Trade history to chart along with historical prices
Author: sigfried
Creation Date: 4/3/2019 1:41 PM
profile picture

sigfried

#1
I would like to load my Fidelity trade history so I can look at my historical trades against charts of historical prices. Is that possible? I see positions from all my accounts, but don't see a way to fetch trading history.

My goal is to understand and evaluate my trading behavior in retrospect. I follow a fairly mindless trading strategy of buying things (mostly things already in my portfolio) when they dip as long as I don't have too much of it already, and selling when they're up. Given that I mostly just use Fidelity's web app, I'm most aware of current-day spikes and dips. And I tend to be all-but-completely ignorant of fundamentals and most of the other information that real traders would use.

So far it's felt like I've done ok with this strategy, but that's most likely because it's been mostly bull markets over the past couple years I've been doing it. It would be nice to see: have I been buying before bigger declines or selling before bigger ascents? Should I follow the advice that every professional gives to would-be traders as naive as myself: "Don't try to time the market"? Right now there's no chart or set of charts I know how to find (and interpret) that can give me more than a tiny fragment of an answer.

Thanks in advance for your help!
profile picture

Eugene

#2
Evaluating a history of trading behavior has actually been requested quite frequently. Using the Community Components library makes it possible to perform the analysis of trade executions with this solution: Import real (historical) trades. Several "trade file" formats are supported. You need to have the data for all the traded symbols in WLP and the trade data should be split adjusted (so to match your chart data).

Also there's a downloadable strategy called Historical Trades: splits, cash flow, multiple files, shared equity (see "Instructions for Script Download") that does all that and much more.
profile picture

KGo

#3
@sigfried If you use the downloadable program you can simply save the trade history csv downloaded from the Fidelity site. Remove the legal disclamer at the bottom. However, Fidelity Active Trader Pro is better as it allows multi-year download of trade history. Either way sort the history with oldest first and entries before exits on each day. Save the downloaded Historical Trades to a new strategy name and replace the Execute at the bottom with below. Adjust the Multifile statement to use the options you desire and use WealthScript Overide in position sizing to trade shares. The second MultiFile statement has some options you may want.
CODE:
Please log in to see this code.


You can model the entire actual Fidelity account history with dividends and other cash flows but must add an extension to WL. From Historical Trades Documentation:
QUOTE:
1. To use the Cash Flow Dividend transfer capability install MS123 Extra Fundamental/News Providers found at https://www.wealth-lab.com/Extensions/Details/34 . Transfers require Position Options>>Tag>>%Equity PosSizer or WealthScript Override (SetShareSize) and dividends must be set to Transfer. No other provider setup is required.


When the file is working execute it on any symbol to see the trades graphed for that symbol.
profile picture

sigfried

#4
Thank you. It sounds like I could save myself a lot of work and get a lot more functionality by using the Historical Trades strategy and other community resources -- assuming I'm not too dumb to get it working in some reasonable amount of time.

I haven't looked at .NET programming since the 90's when I did some VB and ASP. It looks sort of like Java, so maybe it's C#.

I couldn't find the Community Components that Eugene mentioned. Maybe I don't have access to the wiki yet.

I tried to follow KGo's instructions and got lost pretty quickly. I saw where to specify my MultiFile

CODE:
Please log in to see this code.


But I'm not sure where or how to set the folder path. And when I tried to compile or run the strategy (Historical Trades...), I got a bunch of errors that I can't figure out how to copy and paste. The first was:
QUOTE:
error CS1061 @ (31,15) : 'WealthLab.Strategies.MyStrategy' does not contain a definition for 'EnterAtPrice' and no extension method 'EnterAtPrice' accepting a first argument...
profile picture

sigfried

#5
Also, the default exports from the fidelity web app and active trader pro are different, and from active trader pro I'm getting dollar amounts exported with dollar signs and commas. It's not clear to me if I'll need to munge these files into a specified format for the Historical Trades strategy. I haven't checked out "Import real (historical) trades" that Eugene mentioned yet.
profile picture

Eugene

#6
QUOTE:
I couldn't find the Community Components that Eugene mentioned. Maybe I don't have access to the wiki yet.

Like I told you in the support ticket, Extensions are installed from this website (www). Here's it:

Community Components library

The Wiki (www2) hosts the source code of some demo and open source extensions. Please sign up there again and verify your new account. After your Wiki account is verified I'll manually assign the privileges required for source code download.
profile picture

KGo

#7
The EnterAtPrice error will be gone when you install Community Components as Eugene referenced.

QUOTE:
not clear to me if I'll need to munge these files into a specified format for the Historical Trades strategy

Historical Trades accepts both formats including different data titles, dollar signs and embedded commas in dollar values.

Be aware that Fidelity may use 4 decimal precision for entry or exit price (ie $70.8996). Ensure that if you edit the file, full precision remains. Excel for example will round values with dollar signs to 2 places.

The file directory (fd) is set to find the Documents folder. Specify any folder you want. The file name input will also take the full path if desired. Use @"full path" for that.

Note the Strategy summary tab has quite a lot of documentation. Follow the Overview section which contains.a Preparing Wealth-Lab subsection. (TIP) I select all and paste the document into Excel after widening the first 2 columns to look like the strategy summary tab. Then references to any topic can be found using Excel Find.
profile picture

sigfried

#8
Thanks so much for the help!

I did get it working.

I had a bunch of trades where the symbol was a long number, maybe ETNs and stuff. Those didn't work, but after deleting them from the trades csv file, I am able to see my trades in the context of a historical price chart -- one symbol at a time. I haven't really read the documentation yet, so I'll do that before bugging you anymore.

Thanks!
profile picture

Eugene

#9
Congrats on having unleashed the power and extensibility of the platform ;-)
profile picture

sigfried

#10
I'm not sure unleashed is quite the right term. Maybe I cracked the window so the platform can get a whiff of power and extensibility floating outside in the breeze. :)

profile picture

KGo

#11
@sigfried Congratulations on getting Historical Trades working.

QUOTE:
I had a bunch of trades where the symbol was a long number, maybe ETNs and stuff.

Those are CUSIP numbers, a unique identifier for the instrument. No need to delete them. You can google to identify the instrument. Here are some ProShares CUSIP changes.
https://www.proshares.com/news/proshares_announces_etf_share_splits_and_reverse_splits_01102014.html

There are 3 ways to fix them:
1. Replace the number with the symbol in the csv.
2. Substitute the symbol for the number in the MultiFile statement ~Symbol:Sub:74347X237=QID:74348A202=TWM
3. Hard code each substitution into Historical Trades LoadSymbolLookupDic procedure with
CODE:
Please log in to see this code.


Know that if you are modeling with Same Day Price (SDP) any trade before a split will not be on the chart because the prices are not there. The trade is made against an adjusted price series.

When the Fidelity trade data is run with shares Historical Trades matches entry and exit quantities to create the entry/exit pairs. It will automatically split the trades as is actually done using LIFO or FIFO methods. Then WLP Trades tab can be saved as a csv and run in Historical Trades as SDP or SameDayOpen (SDO) or SameDayClose (SDC). Use percent equity sizing with SDO or SDC and all trades will appear on the current chart. This may help with an visual review of the entire history.

Lastly, if you save a symbol with pre-split prices all trades would appear on that chart.
profile picture

sigfried

#12
Thanks so much @KGo!
profile picture

KGo

#13
Your very welcome.
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).