qstrader icon indicating copy to clipboard operation
qstrader copied to clipboard

python buy_and_hold_backtest.py does not run

Open stjordanis opened this issue 8 years ago • 4 comments

I followed the instructions from: https://www.quantstart.com/qstrader or https://github.com/mhallsmoore/qstrader

python buy_and_hold_backtest.py emits:

Could not subscribe ticker SP500TR as no data CSV found for pricing. Traceback (most recent call last): File "buy_and_hold_backtest.py", line 81, in main() File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/click/core.py", line 722, in call return self.main(*args, **kwargs) File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "buy_and_hold_backtest.py", line 77, in main run(config, testing, tickers, filename) File "buy_and_hold_backtest.py", line 27, in run csv_dir, events_queue, tickers File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/qstrader/price_handler/yahoo_daily_csv_bar.py", line 38, in init self.bar_stream = self._merge_sort_ticker_data() File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/qstrader/price_handler/yahoo_daily_csv_bar.py", line 68, in _merge_sort_ticker_data df = pd.concat(self.tickers_data.values()).sort_index() File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/pandas/tools/merge.py", line 845, in concat copy=copy) File "/home/steliox/anaconda2/envs/conda-35/lib/python3.5/site-packages/pandas/tools/merge.py", line 878, in init raise ValueError('No objects to concatenate') ValueError: No objects to concatenate

stjordanis avatar Feb 07 '17 05:02 stjordanis

@stjordanis The error is nasty, but I think it might be because you're not passing in the configuration file ? i.e. "--config=~qstrader.yml" -- or if that file exists and is being passed in by default (might be, can't remember), the SP500TR.csv file doesn't exist where the config file suggests ("~/data" from memory)

ryankennedyio avatar Feb 08 '17 02:02 ryankennedyio

@ryankennedyio thanks that's it! i ran: python buy_and_hold_backtest.py --config=~qstrader.yml after I moved the input file in ~/data like you said Thanks for the quick reply.

stjordanis avatar Feb 08 '17 03:02 stjordanis

Might be worth keeping this open @stjordanis because it should probably return a more helpful error than what you saw the first time :)

ryankennedyio avatar Feb 08 '17 04:02 ryankennedyio

I got a similar error, but the command "python buy_and_hold_backtest.py --config=~qstrader.yml" didn´t work as expected:

_C:\Users\Eduardo\Anaconda3\pkgs\qstrader\data>dir Volume in drive C has no label. Volume Serial Number is C0C3-6C1A

Directory of C:\Users\Eduardo\Anaconda3\pkgs\qstrader\data

22-Jan-18 03:20 AM <DIR> . 22-Jan-18 03:20 AM <DIR> .. 22-Jan-18 03:07 AM 279.879 AAPL.csv 22-Jan-18 03:07 AM 178.152 AGG.csv 22-Jan-18 03:07 AM 519 AMZN.csv 22-Jan-18 03:07 AM 2.151 buy_and_hold_backtest.py 22-Jan-18 03:07 AM 519 GOOG.csv 22-Jan-18 03:07 AM 3.640 monthly_liquidate_rebalance_backtest.py 22-Jan-18 03:07 AM 3.758 moving_average_cross_backtest.py 22-Jan-18 03:07 AM 499 MSFT.csv 22-Jan-18 03:07 AM 295.971 SPY.csv 22-Jan-18 03:07 AM 2.470 test_examples.py 22-Jan-18 03:07 AM 0 init.py 11 File(s) 767.558 bytes 2 Dir(s) 818.988.580.864 bytes free

C:\Users\Eduardo\Anaconda3\pkgs\qstrader\data>python buy_and_hold_backtest.py --config=~qstrader.yml Could not subscribe ticker SPY as no data CSV found for pricing. Traceback (most recent call last): File "buy_and_hold_backtest.py", line 70, in run(config, testing, tickers, filename) File "buy_and_hold_backtest.py", line 56, in run events_queue, title=title File "C:\Users\Eduardo\Anaconda3\lib\site-packages\qstrader\trading_session.py", line 52, in init self._config_session() File "C:\Users\Eduardo\Anaconda3\lib\site-packages\qstrader\trading_session.py", line 68, in _config_session end_date=self.end_date File "C:\Users\Eduardo\Anaconda3\lib\site-packages\qstrader\price_handler\yahoo_daily_csv_bar.py", line 38, in init self.bar_stream = self._merge_sort_ticker_data() File "C:\Users\Eduardo\Anaconda3\lib\site-packages\qstrader\price_handler\yahoo_daily_csv_bar.py", line 68, in merge_sort_ticker_data df = pd.concat(self.tickers_data.values()).sort_index() File "C:\Users\Eduardo\Anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 206, in concat copy=copy) File "C:\Users\Eduardo\Anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 239, in init raise ValueError('No objects to concatenate') ValueError: No objects to concatenate

Can anyone help plz?

Edulongo7 avatar Jan 22 '18 05:01 Edulongo7