Save backtest trade data to a spreadsheet (CSV)
Author: pestocat2
Creation Date: 6/25/2018 3:29 AM
profile picture

pestocat2

#1
Is there a way to transfer the back test trade data to a *.CSV file.
Thank you
profile picture

Eugene

#2
Sure there is: this question has been asked a lot of times before and could be found by searching. But let's start with why do you want to do it. If you tell us your objective and what is the "trade data", maybe we could find a more straightforward way.
profile picture

pestocat2

#3
I work with a group working to develop optimum trading 3X ETFs. I have presented to the group my terrific results using WLP and some wanted the trade data. I sent out the screen shots, but one wanted it in spreadsheet form, thus *.CSV. Sorry if I didn't do a proper search.
Gary
profile picture

Eugene

#4
Thanks for the clarification. Please give this a try and let me know if further assistance is required:

How to run the strategy and save result into a file?
How to save past trades into a file?
Save open trades in CSV file
profile picture

pestocat2

#5
I got my strategy to store the .csv files, but I'm not sure what I got. I had 25 trades, but the file has about 3500 lines of data.
Gary


profile picture

KGo

#6
Right click, copy, paste to Excel, save as CSV.
https://www.wealth-lab.com/Forum/Posts/Is-there-a-way-to-print-copy-the-backtesting-result-to-Excel-file-31074

BTW, That CSV can be run unchanged thru Historical Trades to reproduce complete results.
profile picture

Eugene

#7
QUOTE:
I got my strategy to store the .csv files, but I'm not sure what I got. I had 25 trades, but the file has about 3500 lines of data.

This usually happens when you run some example code intended to be run in Single Symbol mode, on a DataSet of 140 symbols in Multi-Symbol mode.
profile picture

pestocat2

#8
Eugene,
I used my strategy code and added the required code to write the .csv file. The strategy was for a single stock.
profile picture

pestocat2

#9
KGo,
Could explain further "BTW, That CSV can be run unchanged thru Historical Trades to reproduce complete results."
Gary


profile picture

KGo

#10
Sometimes you may want to be able top reproduce a result.

There is a public strategy called "Historical Trades: splits, cash flow, multiple files, shared equity" which is in the Utilities folder after downloading strategies. (Open a Strategy >>Download>>Download Public Strategies >> Download)

Save the entire pasted trade list which includes trade performance data to a csv to the documents folder - no editing is required. Go to the bottom of Historical Trades at about line 3478 and replace "CSV Trade Test 01.csv" in below code line with your csv file name. Pick SetShareSize or PosSizer Position Options %Equity and execute.
CODE:
Please log in to see this code.


If you use recommended preferences and other settings like starting equity are the same, you will get the same results as the original. Check the Debug window for messages including preference settings.

Further discussion of Historical Trades usage should be moved to:https://www.wealth-lab.com/Forum/Posts/Historical-Trades-splits-cash-flow-multiple-files-shared-equity-39101
profile picture

Eugene

#11
QUOTE:
I used my strategy code and added the required code to write the .csv file. The strategy was for a single stock.

Perhaps I was a bit unclear. The code you added seems to loop over DataSetSymbols and this makes it output the unnecessary data. If you could be more detailed about how exactly you added the "required" code, what "for single stock" means in your opinion, and how exactly the strategy was executed, I'll tell you what went wrong. Sorry I cannot guess how it's done on your end exactly.
profile picture

pestocat2

#12
Eugene,
I have a strategy that back tests one ETF at a time with a time period of a little over a year time span. I use Daily scale. It generates about 25 trades over that time period. I modified my code to use this code, except in the for loop which was mine.

CODE:
Please log in to see this code.
profile picture

Eugene

#13
The tried and true Wiki code appends trades on each symbol to the same file as you run your strategy over and over. Like 140 symbols * 25 trades = 3500 lines. Problem solved?
profile picture

pestocat2

#14
Eugene,
Where does the 140 symbols come from. Is there something the "u" that I don't know about. What am I missing.
profile picture

Eugene

#15
Keeping an air of mystery and quoting the entire Wiki sample code with its dummy trade system is a suboptimal support strategy. Questions in #14 are either insignificant in the support context or have been answered (see #7). If you wish to get further with this please attach the CSV file (rename to TXT) and answer questions asked by the technician:

how exactly you added the code (implementation is missing in your replies),
and how exactly the strategy was executed (on which DataSet/symbols, in Multi-Symbol mode or Single-Symbol mode - look up the Wealth-Lab User Guide if unsure what this means)
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).