Historical Trades: splits, cash flow, multiple files, shared equity
Author: KGo
Creation Date: 12/19/2017 3:54 AM
profile picture

KGo

#1
A new utility program has been uploaded. It's named "Historical Trades: splits, cash flow, multiple files, shared equity". It will come with your next strategies download. Here is the overview from the strategy description:

Historical Trades reads multiple trade list and cash flow files of varying format including actual brokerage history into a single Wealth Lab model.

For broker history with actual shares and prices it will automatically split entries to match multiple exits and split exits to match multiple entries. It will create LIFO and/or FIFO trades at actual prices even when prices have split after the sale. If desired, it will use actual commission, fees and all cash flow transactions including actual dividends, interest, deposits, withdrawals and any other category cash flow to create a complete, accurate account model. Multiple accounts can be processed simultaneously to create a consolidated view with all the Wealth-Lab metrics.

Historical Trades creates a model from trade list files based on shares or %Equity. It accepts trades from Wealth Lab strategies, Active Trader Pro history, Fidelity.com history or third party datasets. It is effortless to combine multiple files into a single backtest. Some symbol substitution, trade selection, percent equity adjustment and other changes can be made on the fly without changing the file(s). Trade timing is flexible with same day or next day executions at open, close or price as needed for each trade in each file. Every trade has all data visible and can be reconciled to its input so there is never a question of accuracy. Historical Trades can save a file documenting all transactions and their source setup to precisely reproduce any execution.

The program has statements to run WL trades and ATP or Fidelity.com history. Just put in your file names. I'll post other sample files and code to run them tomorrow.

Kevin
profile picture

Eugene

#2
Kevin, thank you for sharing your work with the community.

I'll not pretend that I understand how the code works. :)

Approved! Now it can be downloaded.
profile picture

KGo

#3
Eugene, Thanks for the approval.

Here are some sample files and code.

This is for %Equity sizing. Use PosSizer>>Position Options>>Tag>>%Equity. It's a WL trade list, intraday 5 min scale and will execute on bars from 5 min up to daily scale on shares or %Equity. Symbol is XIV. It uses defaults stored in the file including system assumed defaults like minimized print but has added a cash flow file.
CODE:
Please log in to see this code.


This example is of shares sizing. Use Data Pane SetShareSize. Fidelity type data with one trade fixed for a split during the trade. All defaults are stored in the file.
CODE:
Please log in to see this code.


If you trade with Fidelity save your ATP or Fidelity.com history and use the Fidelity line in the downloaded program. It will be much like the above example.

Other files attached are for reference.
profile picture

gbullr

#4
KGO:

here is some of the data: Data is in a csv format
The data is 6500 hundred lines long and represents a specific volume imbalance for the underlying symbol on each day.

EntryDate Symbol
9/13/2016 MPLX
9/13/2016 RDUS
9/13/2016 SQQQ
9/13/2016 SWKS
9/13/2016 WTW
9/13/2016 UCO
9/13/2016 ECA
9/13/2016 JBLU
9/13/2016 FE
9/13/2016 HUN
9/13/2016 ISIL
9/13/2016 AGI
9/13/2016 JCI
9/13/2016 SPXS
9/14/2016 PXD
9/14/2016 FNSR
9/14/2016 YY
9/14/2016 XLK
9/14/2016 SWKS
9/14/2016 SIG
9/14/2016 AZN

here is the Multifile line:
MultiFile(fd,@"C:\Users\Gaston\Box Sync\Nanodegree 1\Independent Projects\Options\historical_sizzle_long_trades.csv","~EnterAt:SDC ~ExitAt:NDC ",ref mfn, ref mfs);

this generates this as a result; which goes on for thousands of lines.



How do I get Historical trades to:

1) Exit as the Multifile line says and
2) Not generate multiple trades.


profile picture

KGo

#5
1. The exit instruction is relative to a given exit date. Give the exit date since you know it.

2. One trade for each entry date is executed. You may have the same trade repeated in the file or the MultiFile instruction is executing in a loop. Do not put it in a loop.

The easiest way to do what you requested is to use the attached file format. It just repeats the entry date as the exit date so ~ExitAt:NDC will execute. When giving exits use the Action column as shown.
profile picture

KGo

#6
Forgot csv cannot upload so instead of sipping it, here is tab separated text file which also can be run directly in the system.
profile picture

gbullr

#7
The reality is that I want the exit date open so that I can easily change it and see the results.

The same trades are not repeated in the file.

I don't understand how to run a test without executing in a loop .. How is that done on Wealth-Lab?

Thank you.
profile picture

KGo

#8
Lastly if you want to do your own exit when exit date is not given, here is the execute code:
CODE:
Please log in to see this code.

Normal operation does not have the position loop to exit open positions. Normal operation just needs:
CODE:
Please log in to see this code.
profile picture

gbullr

#9
I got it to WORK!!! Thank you. I will have additional questions regarding entry and exit. I hope you don't mind.

profile picture

KGo

#10
Excellent! Ask anytime, happy to help.
profile picture

KGo

#11
This post describes how to enable Historical Trades access to Wealth-Lab's TradeHistory.xml data. Live account and paper account history are kept in the xml file. To access it copy the debug output and paste to a txt or csv file and run that through Historical Trades.

Replace the Historical Trades Execute with this simplified version or just add the MultiFile line below to the original code:
CODE:
Please log in to see this code.


Modeling part of the data: The Multifile line can take ~Include and ~Exclude with multiple : separated text modifiers in place of the " " above. So ~Include:nt1:nt2 would include both PaperAccount1 and PaperAccount2 but not an actual account number. To limit the analysis to a scale use somehiing like " ~Include:nt1:ly0 ~Exclude:nt2 " to include only daily0 trades for PaperAccount1. Daily0 trades for PaperAccount2 would be excluded. This is very flexible and enables analysis of one file by an extract of account, scale and strategy. There's typically no need to manually sort and save sets of trades.


Here's the program to create the data. Save debug via Notepad in documents folder as "TradeHistory 01.csv" or .txt file to match Multifile above.
CODE:
Please log in to see this code.


The last PrintDebug prints a format compatible with InputHistoricalTrades (SimTradeFile2). Here shares are included and the date format is flexible. Account, scale and strategyID are not acccepted so sorts must be done manually and separate files created.
profile picture

gbullr

#12
Smore questions.

Please tell me how to add commission costs to the trades please.. Is that possible? There is also something that does not make too much sense which is that the sum of the LONG and SHORT margin interest paid does not sum to the ALL trades total.




Thank you.
profile picture

KGo

#13
Use any commission setting in Tools>>Preferences as usual. Or uncheck Tools >>Preferences >>Commission >> Apply Commission to simulated trades. Then:
You can add Commission and Fees (CF) to the Multifile statement to apply to all trades.
CODE:
Please log in to see this code.

Or you can add Column headers EntryCF and ExitCF with amounts on each trade row.
Or you can just specify ~Commission:4.95 in the Multifile statement to apply 4.95 to both entry and exit.
Or you can add column headers called Commission and/or Fees with a value assigned to each trade.

Historical Trades does not touch margin interest. You're seeing native WL. However Long interest plus short interest do not add to total interest when the long, short and total systems have very different market exposures and therefore different margin requirements.
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).