mhallsmoore / qstrader

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

An integer is required error when accessing dictionary #270

Closed douggie closed 8 months ago

douggie commented 5 years ago

Hi,

After following the installation instructions and running on max OSX with Python 3.6.3 I wondered if you might have any pointers on what could be causing the following error when running the example buy_and_hold_backtest.py?

$ python buy_and_hold_backtest.py No tradelog files to clean. Running Backtest...

Backtest complete. Sharpe Ratio: 0.25 Max Drawdown: 79.59% Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1945, in get_loc return self._engine.get_loc(key) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1431, in get_loc return Index.get_loc(self, key, method, tolerance) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1947, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

ValueError: Error parsing datetime string "next" at position 0

The above exception was the direct cause of the following exception:

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 58, in run results = backtest.start_trading(testing=testing) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/trading_session.py", line 167, in start_trading self.statistics.plot_results() File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 632, in plot_results self._plot_txt_curve(stats, ax=ax_txt_curve) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 356, in _plot_txt_curve sortino = perf.create_sortino_ratio(returns, self.periods) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/performance.py", line 66, in create_sortino_ratio return np.sqrt(periods) * (np.mean(returns)) / np.std(returns[returns < 0]) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/series.py", line 618, in getitem if com.is_iterator(key): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/common.py", line 1449, in is_iterator return hasattr(obj, 'next') or hasattr(obj, 'next') File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/generic.py", line 2670, in getattr if name in self._info_axis: File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/base.py", line 184, in contains res = self.get_loc(key) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1439, in get_loc stamp = Timestamp(key, tz=self.tz) File "pandas/tslib.pyx", line 295, in pandas.tslib.Timestamp.new (pandas/tslib.c:9203) File "pandas/tslib.pyx", line 1269, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:24653) File "pandas/tslib.pyx", line 1381, in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26273) File "pandas/src/datetime.pxd", line 141, in datetime._string_to_dts (pandas/tslib.c:85631) SystemError: <class 'str'> returned a result with an error set

JamesKBowler commented 5 years ago

Hi mate, Are you using the default data set?

Cheers

James

On Mon, 10 Dec 2018, 09:03 douggie <notifications@github.com wrote:

Hi,

After following the installation instructions and running on max OSX with Python 3.6.3 I wondered if you might know what is causing the following error when running the example buy_and_hold_backtest.py? $ python buy_and_hold_backtest.py No tradelog files to clean. Running Backtest...

Backtest complete. Sharpe Ratio: 0.25 Max Drawdown: 79.59% Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1945, in get_loc return self._engine.get_loc(key) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1431, in get_loc return Index.get_loc(self, key, method, tolerance) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1947, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

ValueError: Error parsing datetime string "next" at position 0

The above exception was the direct cause of the following exception:

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 58, in run results = backtest.start_trading(testing=testing) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/trading_session.py", line 167, in start_trading self.statistics.plot_results() File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 632, in plot_results self._plot_txt_curve(stats, ax=ax_txt_curve) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 356, in _plot_txt_curve sortino = perf.create_sortino_ratio(returns, self.periods) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/performance.py", line 66, in create_sortino_ratio return np.sqrt(periods) (np.mean(returns)) / np.std(returns[returns < 0]) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/series.py", line 618, in getitem if com.is_iterator(key): File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/common.py", line 1449, in is_iterator return hasattr(obj, 'next') or hasattr(obj, 'next') File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/generic.py", line 2670, in getattr if name in self._info_axis: File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/base.py", line 184, in contains res = self.get_loc(key) File "/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1439, in get_loc stamp = Timestamp(key, tz=self.tz) File "pandas/tslib.pyx", line 295, in pandas.tslib.Timestamp.new* (pandas/tslib.c:9203) File "pandas/tslib.pyx", line 1269, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:24653) File "pandas/tslib.pyx", line 1381, in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26273) File "pandas/src/datetime.pxd", line 141, in datetime._string_to_dts (pandas/tslib.c:85631) SystemError: <class 'str'> returned a result with an error set

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mhallsmoore/qstrader/issues/270, or mute the thread https://github.com/notifications/unsubscribe-auth/AXGWkD55ydT8JmL_wATBLb38iKFVYXHvks5u3iNJgaJpZM4ZK7KI .

douggie commented 5 years ago

indeed i am just the insructions as per read me.

On Thu, 13 Dec 2018, 06:15 James Bowler, notifications@github.com wrote:

Hi mate, Are you using the default data set?

Cheers

James

On Mon, 10 Dec 2018, 09:03 douggie <notifications@github.com wrote:

Hi,

After following the installation instructions and running on max OSX with Python 3.6.3 I wondered if you might know what is causing the following error when running the example buy_and_hold_backtest.py? $ python buy_and_hold_backtest.py No tradelog files to clean. Running Backtest...

Backtest complete. Sharpe Ratio: 0.25 Max Drawdown: 79.59% Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1945, in get_loc return self._engine.get_loc(key) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pandas/index.pyx", line 575, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:10990) File "pandas/hashtable.pyx", line 303, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6589) TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1431, in get_loc return Index.get_loc(self, key, method, tolerance) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/indexes/base.py", line 1947, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas/index.pyx", line 538, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11140) File "pandas/index.pyx", line 577, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11046) File "pandas/index.pyx", line 583, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11210) KeyError: 'next'

During handling of the above exception, another exception occurred:

ValueError: Error parsing datetime string "next" at position 0

The above exception was the direct cause of the following exception:

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 58, in run results = backtest.start_trading(testing=testing) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/trading_session.py", line 167, in start_trading self.statistics.plot_results() File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 632, in plot_results self._plot_txt_curve(stats, ax=ax_txt_curve) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/tearsheet.py", line 356, in _plot_txt_curve sortino = perf.create_sortino_ratio(returns, self.periods) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/qstrader/statistics/performance.py", line 66, in create_sortino_ratio return np.sqrt(periods) * (np.mean(returns)) / np.std(returns[returns < 0]) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/series.py", line 618, in getitem if com.is_iterator(key): File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/common.py", line 1449, in is_iterator return hasattr(obj, 'next') or hasattr(obj, 'next') File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/core/generic.py", line 2670, in getattr if name in self._info_axis: File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/base.py", line 184, in contains res = self.get_loc(key) File

"/Users/douggieclarke/Development/python/venv/qstraderp3/lib/python3.6/site-packages/pandas/tseries/index.py", line 1439, in get_loc stamp = Timestamp(key, tz=self.tz) File "pandas/tslib.pyx", line 295, in pandas.tslib.Timestamp.new (pandas/tslib.c:9203) File "pandas/tslib.pyx", line 1269, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:24653) File "pandas/tslib.pyx", line 1381, in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26273) File "pandas/src/datetime.pxd", line 141, in datetime._string_to_dts (pandas/tslib.c:85631) SystemError: <class 'str'> returned a result with an error set

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mhallsmoore/qstrader/issues/270, or mute the thread < https://github.com/notifications/unsubscribe-auth/AXGWkD55ydT8JmL_wATBLb38iKFVYXHvks5u3iNJgaJpZM4ZK7KI

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mhallsmoore/qstrader/issues/270#issuecomment-446854640, or mute the thread https://github.com/notifications/unsubscribe-auth/AENHagw_g2DUDdvbhDp27oc3-DWQj6JSks5u4fBpgaJpZM4ZK7KI .

douggie commented 5 years ago

ls python/venv/qstraderp3/data SPY.csv head -5 SPY.csv Date,Open,High,Low,Close,Volume,Adj Close 2016-01-04,200.490005,201.029999,198.589996,201.020004,222353500,196.794026 2015-12-31,205.130005,205.889999,203.869995,203.869995,102929500,199.584102 2015-12-30,207.110001,207.210007,205.759995,205.929993,63317700,201.600793 2015-12-29,206.509995,207.789993,206.470001,207.399994,92640700,203.039891