ImportHistoricalTrades to support Fidelity ATP trade data?
Author: KGo
Creation Date: 2/22/2017 5:55 PM
profile picture

KGo

#1
SymTradeFile2 has great promise but falls short of the requirements for simple live use with Fidelity trade data.

Because both buy and sell orders are routinely filled at multiple shares-price fills the below functionality is required to use live order history.

1. (Split Entry) An entry can be split and exited via multiple exit orders.

2. (Split Exit) An exit order can be applied to multiple entries while optionally leaving some entry shares open.

3. Input data should only require pre-sorting by trade date so multiple symbols are listed together on the same date. Entries must be listed before exits.

4. Ideally the user can select if shares are exited using LIFO or FIFO method to match their account settings. This could be an input data field after shares enabling full user control.

These enhancements would make it possible to use the ATP History as input to WLP to model trade results. ATP history is the best source for trade execution prices free from commission and fees so those prices should most likely be valid at the execution bar. Handling splits is a separate issue.

It's likely this can be done in the process of building the trade data for input to the underlying SymTradeFile so no changes to the base method are required.
profile picture

Eugene

#2
I've renamed the misleading title "SymTradeFile2 Upgrade" to a more appropriate one. SimTradeFile2 is legacy name; ImportHistoricalTrades is preferred.

1, 2 - Optional trade size is supported by SimTradeFile/SimTradeFile2.
3 - Not sure why this should matter.

Can you attach a sample file?
profile picture

KGo

#3
This data demonstrates the issues.

3 - Move a sell directly under a buy to see a difference.

I am seeing some sells at the open of the first sell sell date.
profile picture

KGo

#4
The above data should result in a trade list with added trades and open trades as attached here. Multiple similar solutions are possible depending on LIFO, FIFO or ad hoc application of exits.
profile picture

Eugene

#5
SimTradeFile2 seems to do a good job (better than the v.1) at handling discretionary trading. After all, problems arise if both positions do not have a matching order size. i.e. they were exited by you as 650/400 shares vs. 700/350. Nevertheless, ImportHistoricalTrades closed them on the next bar. Let's say this is a limitation. I think that supporting the advanced features like split entries/exits and LIFO/FIFO might require a complete redesign of the simple method which SimTradeFile2 is.
profile picture

KGo

#6
QUOTE:
problems arise if both positions do not have a matching order size. i.e. they were exited by you as 650/400 shares vs. 700/350


Know that this is not simply a discretionary trading issue. Fidelity will often fill a single market order in multiple parts. When both entry and exit orders are for the same number of shares (1000 shares) the entry order fills (400 and 600 shares) will often not match the exit order fills (300 and 700 shares). This alone makes ImportHistoricalTrades unusable.

I'd like to review the code but don't see it in Community components. Could you point me to it or post it here?
profile picture

Cone

#7
Wealth-Lab itself cannot do those trades either because it is position-based. In other words, in Wealth-Lab, you sell Positions not shares The shares in the exit orders must exactly match those in the Position (at entry).

It's a relatively complicated matter to perform your example trade in Wealth-Lab. You'd have to split the 400 share position by 25%, leaving you with 100, 300, and 600 share positions. Then you'd sell the 300 shares and (600 + 100) shares.

Consequently, to make your example work in the sim trade file, you'll need to create positions for 100, 300 and 600 shares.
profile picture

KGo

#8
Yes that's exactly correct and an automated function to do it is needed. As suggested in my post #1:
QUOTE:
this can be done in the process of building the trade data for input to the underlying SymTradeFile so no changes to the base method are required


Specifically, I am suggesting that ImportHistoricalTrades style Format2 be translated to style Format1 before executing any trades in WL. This reduces the problem to matching exits to entries in text list mode. If the shares don't match either add a duplicate entry for the remaining entry shares or add a duplicate exit for the remaining exit shares.

The resulting Format1 trade list will run as normal for Format1. No changes to the trade execution engine for Format1 are required. WL SplitPosition function will never be used.

I'd like to review the code but don't see it in Community components. Could you point me to it or post it here?
profile picture

Eugene

#9
All you have to do to find it is search the code for SimTradeFile. You will find the code under ../ExtensionMethods/PositionEx.cs.
profile picture

asresearch

#10
I do have problems with ImportHistoricalTrades trade lots matching and sizing too.
But I can not find ../ExtensionMethods directory to take a look at the source on my HD.

I could not find how to get ExtensionMethods source tree from the site. Can you please guide me?


I followed http://www2.wealth-lab.com/WL5Wiki/kbFAQMisc.ashx item
I can't see any open source in the Wealth-Lab Wiki?

Open source project code is available to registered customers of Wealth-Lab Developer/Pro, for free, and can be downloaded by clicking on
"Attachments" of a project's home page. WLD/WLP customers who can't see "Attachments" - please enter a new support ticket at wealth-
lab.com. Note: source code is not available to trial users.


But was not able to find anything :(
Thanks
profile picture

Eugene

#11
It's here: Home - Community Components > Download Project Source
profile picture

asresearch

#12
Thank you !!!
Got it

profile picture

Eugene

#13
You're welcome.