[Bug] Error out when backtesting
See original GitHub issueDescribe the bug In Pred, once specifies backtesting date such as lstm -e 2021-03-23, it has KeyError:1980
To Reproduce load AMD pred AMD lstm -e 2021-03-23
Screenshots
(✨) (pred)> help
Daily Stock: AMD
Prediction Techniques:
help show this prediction techniques menu again
q quit this menu, and shows back to main menu
quit quit to abandon program
sma simple moving average
ets exponential smoothing (e.g. Holt-Winters)
knn k-Nearest Neighbors
linear linear regression (polynomial 1)
quadratic quadratic regression (polynomial 2)
cubic cubic regression (polynomial 3)
regression regression (other polynomial)
arima autoregressive integrated moving average
prophet Facebook's prophet prediction
mlp MultiLayer Perceptron
rnn Recurrent Neural Network
lstm Long-Short Term Memory
(✨) (pred)> lstm -e 2021-03-23
1980
Traceback (most recent call last):
File "/home/wyatt/GamestonkTerminal/gamestonk_terminal/prediction_techniques/neural_networks.py", line 872, in lstm
df_stock, df_future = _setup_backtesting(df_stock, ns_parser)
File "/home/wyatt/GamestonkTerminal/gamestonk_terminal/prediction_techniques/neural_networks.py", line 290, in _setup_backtesting
if ns_parser.s_end_date < get_next_stock_market_days(
File "/home/wyatt/GamestonkTerminal/gamestonk_terminal/helper_funcs.py", line 211, in get_next_stock_market_days
holidays = holidays + us_market_holidays(year)
File "/home/wyatt/GamestonkTerminal/gamestonk_terminal/helper_funcs.py", line 119, in us_market_holidays
validHolidays.append(datetime.strptime(goodFridays[year], "%Y-%m-%d").date())
KeyError: 1980
Desktop (please complete the following information):
- OS:Ubuntu 18.04.5 LTS
- Python 3.8.8
Additional context N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Problem with Backtest (maybe a Bug) by Strongs
Runtime Error: Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError...
Read more >Backtesting Error (after update) · Issue #3363 - GitHub
The problem is that your configuration does not contain a stoploss (which is valid) - but is using the stoploss from the strategy...
Read more >[BUG REPORT] Large errors in the backtesting system
I created a simple buy and hold trade to test the robustness of the current backtesting system. From 2017-05-30 to 2017-10-20 with $120761.00...
Read more >The Biggest Backtesting Mistakes You Can Make
Backtesting mistakes are common place for new traders. So how can you backtest strategies for more realistic results?
Read more >Disadvantages Of Backtesting (Why Backtesting Doesn't Work)
Disadvantages of backtesting – conclusion A backtest can't capture that markets change, are random, that you tend to curve fit, and you make...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It seems that the default doesn’t work due to some kind of holiday calendar. The key error seems to indicate the holiday error was in 1980.
We should probably set a default start load date. Also if you are training a model such as lstm, more recent data should be used since market conditions change over time.
Edit: confirmed that the holiday helper function has Good Friday’s only back through 2010 (also needs dates to be updated) so I bet that any stock with data loaded before 2010 would raise this issue
You also will need to set the end date to I believe 5 days previous to today.
@DidierRLopes can confirm that. And also we may need to relook at that PR involving dates (or just default maybe a couple years not all time under load)