mhallsmoore / qstrader

QuantStart.com - QSTrader backtesting simulation engine.
https://www.quantstart.com/qstrader/
MIT License
2.79k stars 842 forks source link

Lack of timestamp data from yahoo finance results in testing of qstrader with sixty_forty.py impossible #377

Closed smith6jt-cop closed 5 months ago

smith6jt-cop commented 2 years ago

The directions in the README.md will result in a colossal waste of time for anyone that attempts to follow them. Creating .csv files of SPY or AGG from Yahoo Finance will NOT include the timestamp data necessary to run the script as there will be no time data (even if you open in Notepad), only date data.

Error: (QSTrader) C:\Users\smith\qstrader-master>python sixty_forty.py Loading CSV files into DataFrames... Loading CSV file for symbol 'EQ:SPY'... Loading CSV file for symbol 'EQ:AGG'... Adjusting pricing in CSV files... Adjusting CSV file for symbol 'EQ:SPY'... Adjusting CSV file for symbol 'EQ:AGG'... Initialising simulated broker "Backtest Simulated Broker Account"... (2003-09-30 14:30:00+00:00) - portfolio creation: Portfolio "000001" created at broker "Backtest Simulated Broker Account" (2003-09-30 14:30:00+00:00) - subscription: 1000000.00 subscribed to portfolio "000001" Beginning backtest simulation... (2003-09-30 14:30:00+00:00) - market_open (2003-09-30 21:00:00+00:00) - market_close (2003-09-30 21:00:00+00:00) - trading logic and rebalance (2003-09-30 21:00:00+00:00) - target weights: {'EQ:AGG': 0.4, 'EQ:SPY': 0.6} C:\Users\smith\qstrader-master\qstrader\data\daily_bar_csv.py:243: FutureWarning: Passing method to DatetimeIndex.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. ask = bid_ask_df.iloc[bid_ask_df.index.get_loc(dt, method='pad')]['Ask'] Traceback (most recent call last): File "sixty_forty.py", line 45, in <module> strategy_backtest.run() File "C:\Users\smith\qstrader-master\qstrader\trading\backtest.py", line 415, in run self.qts(dt, stats=stats) File "C:\Users\smith\qstrader-master\qstrader\system\qts.py", line 172, in __call__ rebalance_orders = self.portfolio_construction_model(dt, stats=stats) File "C:\Users\smith\qstrader-master\qstrader\portcon\pcm.py", line 291, in __call__ target_portfolio = self._generate_target_portfolio(dt, full_weights) File "C:\Users\smith\qstrader-master\qstrader\portcon\pcm.py", line 140, in _generate_target_portfolio return self.order_sizer(dt, weights) File "C:\Users\smith\qstrader-master\qstrader\portcon\order_sizer\dollar_weighted.py", line 164, in __call__ raise ValueError( ValueError: Asset price for "EQ:AGG" at timestamp "2003-09-30 21:00:00+00:00" is Not-a-Number (NaN). This can occur if the chosen backtest start date is earlier than the first available price for a particular asset. Try modifying the backtest start date and re-running.

Generating input data with an interval of less than one day using the yfinance module will include a timestamp, but this variable is limited to <60 days.

This is apparently an issue related to a change in how the input data is generated. Unfortunately, this means that the documentation for qstrader should be altered to include information pertaining to accessing usable data or alternatively the code edited to not rely on timestamp data for an initial testing of the backtesting functionality.

It looks like there was an ignored comment asking for an SPY.csv file in https://github.com/mhallsmoore/qstrader/issues/371#issue-983097724 that may relate to this.

There may be some way of altering the .csv input files to reflect timestamp data that works with the program, but honestly why bother if the developers are not going to maintain this.