My algorithm was working fine for periods of up to 6 months, but when I expanded the timeframe to 2 years it started getting erroneous stock values. (I would paste an image to illustrate, but apparently this isn't supported.)
Here's google drive share of the image showing the problem:
https://drive.google.com/open?id=1XWGHne-HB2Oc2Yhs90iCWjOLviGfF8U7
For reference, this is what the real stock values are on Yahoo.
Stock values for 6/20/2019 are ~63.64
Stock values for 8/20/2017 are ~34.82
Relevant bits of code:
context.stocks = [sid(39214)]
price_history = data.history(context.stocks, fields="price", bar_count=7, frequency="1d")
for s in context.stocks:
current_price = price_history[s][-1]
#for testing stock values
log.info("CURRENT STOCK PRICE %s: %.2f HIST_HIGH: %.2f" % (s.symbol, current_price, prev_high_point))
Log output:
NEWER:
1969-12-31 16:00 initialize:48 INFO Original investment capital: 20000.0
2019-06-20 06:31 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 64.41 HIST_HIGH: 72.64
2019-06-20 06:32 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 64.28 HIST_HIGH: 72.64
OLDER: (incorrect values)
1969-12-31 16:00 initialize:48 INFO Original investment capital: 20000.0
2017-08-21 06:31 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 104.73 HIST_HIGH: 116.35
2017-08-21 06:32 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 104.70 HIST_HIGH: 116.35
Why would the older stock data be so different? The code is exactly the same, only the date range in the Build Algorithm panel is different. The ETF was operating at that time. Could it possible have doubled at some point?