Comments (2)
I know what the problem is probably is. I'll release a fix tomorrow.
Thanks for catching that :)
On 9 Nov 2016, at 22:17, jkleint [email protected] wrote:
I modified the example strategy to use 1S resolution bars with AAPL, plus
print ticks. It runs for one minute printing ticks, then crashes trying to
handle a bar.
#!/usr/bin/env python
import sys
from qtpylib.algo import Algo
class DumbAlgo(Algo):
def on_start(self):
print('start!')
def on_tick(self, instrument):
print('tick!', instrument.get_tick())
def on_bar(self, instrument):
print('bar!', instrument.get_bar())
if name == "main":
# initialize the algo
strategy = DumbAlgo(
instruments = [ "AAPL" ],
resolution = "1S"
)
# run the algo
strategy.run()
$ python strategy.py
start!
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:12.370000'), 'last': 110.63, 'lastsize': 2, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:12.620000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:13.372000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:14.124000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 6, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:15.374000'), 'last': 110.61, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:16.375000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:16.628000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:16.960000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.62, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:17.126000'), 'last': 110.62, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.64, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:18.380000'), 'last': 110.62, 'lastsize': 2, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:19.379000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 11, 'datetime': Timestamp('2016-11-09
20:01:19.629000'), 'last': 110.63, 'lastsize': 5, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 11, 'datetime': Timestamp('2016-11-09
20:01:19.881000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:21.381000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:22.883000'), 'last': 110.65, 'lastsize': 3, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:23.133000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:23.884000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:01:24.387000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:26.138000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:26.638000'), 'last': 110.63, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.63, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:26.889000'), 'last': 110.65, 'lastsize': 5, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.65, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:29.642000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:29.893000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:31.645000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:32.647000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:32.896000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:33.647000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.64, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:34.648000'), 'last': 110.64, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 4, 'asset_class': 'STK', 'ask':
110.66, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:35.650000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 9, 'datetime': Timestamp('2016-11-09
20:01:36.651000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 9, 'datetime': Timestamp('2016-11-09
20:01:38.653000'), 'last': 110.65, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 5, 'asset_class': 'STK', 'ask':
110.67, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09
20:01:39.404000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09
20:01:39.655000'), 'last': 110.67, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09
20:01:41.157000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 2, 'datetime': Timestamp('2016-11-09
20:01:41.658000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:42.658000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 8, 'asset_class': 'STK', 'ask':
110.67, 'opt_price': nan}
tick! {'bid': 110.65, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:43.909000'), 'last': 110.69, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 8, 'asset_class': 'STK', 'ask':
110.67, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:45.411000'), 'last': 110.68, 'lastsize': 3, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:47.414000'), 'last': 110.68, 'lastsize': 2, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 1, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:48.416000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 12, 'datetime': Timestamp('2016-11-09
20:01:49.167000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.68, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:51.420000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.69, 'opt_price': nan}
tick! {'bid': 110.68, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:52.171000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 10, 'asset_class': 'STK', 'ask':
110.69, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 4, 'datetime': Timestamp('2016-11-09
20:01:54.422000'), 'last': 110.66, 'lastsize': 2, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.69, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 8, 'datetime': Timestamp('2016-11-09
20:01:57.927000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:58.427000'), 'last': 110.66, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 10, 'datetime': Timestamp('2016-11-09
20:01:59.428000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
tick! {'bid': 110.66, 'bidsize': 5, 'datetime': Timestamp('2016-11-09
20:02:02.183000'), 'last': 110.68, 'lastsize': 1, 'symbol': 'AAPL',
'symbol_group': 'AAPL', 'asksize': 2, 'asset_class': 'STK', 'ask':
110.68, 'opt_price': nan}
data asset_class close high low
open symbol
datetime
2016-11-09 20:01:00+00:00 STK 110.68 110.69 110.55 110.62 AAPL
symbol_group volume opt_price opt_underlying \
datetime
2016-11-09 20:01:00+00:00 AAPL 79.0 NaN NaN
opt_dividend opt_volume opt_iv opt_oi \
datetime
2016-11-09 20:01:00+00:00 NaN NaN NaN NaN
opt_delta opt_gamma opt_vega opt_theta
datetime
2016-11-09 20:01:00+00:00 NaN NaN NaN NaN
Traceback (most recent call last):
File "/python/lib/python3.4/site-packages/pandas/indexes/base.py",
line 2134, in get_loc
return self._engine.get_loc(key)
File "pandas/index.pyx", line 139, in
pandas.index.IndexEngine.get_loc (pandas/index.c:4443)
File "pandas/index.pyx", line 161, in
pandas.index.IndexEngine.get_loc (pandas/index.c:4289)
File "pandas/src/hashtable_class_helper.pxi", line 732, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13733)
File "pandas/src/hashtable_class_helper.pxi", line 740, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13687)
KeyError: 'last'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "strategy.py", line 35, in
strategy.run()
File "/python/src/qtpylib/qtpylib/algo.py", line 222, in run
book_handler = self._book_handler
File "/python/src/qtpylib/qtpylib/blotter.py", line 943, in listen
bar_handler(df)
File "/python/src/qtpylib/qtpylib/algo.py", line 556, in _bar_handler
self.bars = self._update_window(self.bars, bar,
window=self.bar_window, resolution=self.resolution)
File "/python/src/qtpylib/qtpylib/algo.py", line 583, in _update_window
df = tools.resample(df, resolution=resolution, tz=tz)
File "/python/src/qtpylib/qtpylib/tools.py", line 305, in resample
ohlc = data[data['symbol']==sym]['last'].resample(resolution).ohlc()
File "/python/lib/python3.4/site-packages/pandas/core/frame.py",
line 2059, in getitem
return self._getitem_column(key)
File "/python/lib/python3.4/site-packages/pandas/core/frame.py",
line 2066, in _getitem_column
return self._get_item_cache(key)
File "/python/lib/python3.4/site-packages/pandas/core/generic.py",
line 1386, in _get_item_cache
values = self._data.get(item)
File "/python/lib/python3.4/site-packages/pandas/core/internals.py",
line 3541, in get
loc = self.items.get_loc(item)
File "/python/lib/python3.4/site-packages/pandas/indexes/base.py",
line 2136, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/index.pyx", line 139, in
pandas.index.IndexEngine.get_loc (pandas/index.c:4443)
File "pandas/index.pyx", line 161, in
pandas.index.IndexEngine.get_loc (pandas/index.c:4289)
File "pandas/src/hashtable_class_helper.pxi", line 732, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13733)
File "pandas/src/hashtable_class_helper.pxi", line 740, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13687)
KeyError: 'last'
2016-11-09 12:02:02,546 [INFO]: Algo stopped...
2016-11-09 12:02:02,546 [INFO]: Disconnecting...
2016-11-09 12:02:02,546 [INFO]: Disconnecting from MySQL...
The crash seems to be in qtpylib/tools.py, trying to use a non-existent
'last' column of a dataframe.
ohlc = data[data['symbol']==sym]['last'].resample(resolution).ohlc()
(I modified tools.py to print data[data['symbol']==sym] before the crash)
Not sure about the missing minute of data.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#18, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABIWspuO53StM2KXozVOa7XhmlsSkikTks5q8ipOgaJpZM4Kt8Te
.
from qtpylib.
Fixed in 1.5.24
from qtpylib.
Related Issues (20)
- [BUG] TypeError: unsupported operand type(s) for -: 'float' and 'str'
- [BUG] Find available cash and account value inside strategy. HOT 1
- Ujhj
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- [BUG] pip install error (different than issue #141) HOT 1
- How can I add an FX broker using MT4/5 platform?
- ATR differences with TradingView
- How to backtest options strategy? How to add options data to MySQL database from csv?
- How to "first cross"
- Documentation down HOT 1
- Cannot install from PYPI server HOT 3
- [BUG] HOT 1
- http://www.qtpylib.io/ not accessible - documentation offline ? [BUG] HOT 1
- Order book logging and back testing
- Increase the usage of augmented assignment statements
- Arguments Helps
- Fatal Errors during installation (after preparing isolated conda environment for pip installation) [BUG] HOT 2
- [BUG] No module named 'Queue' in ibpy2 dependency HOT 2
- [BUG] error: invalid path 'Icon?'
- [BUG] module 'pandas' has no attribute 'ewma'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtpylib.