zipline icon indicating copy to clipboard operation
zipline copied to clipboard

TypeError: a float is required

Open chrisspen opened this issue 9 years ago • 3 comments

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: Linux 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Python Version: Python 2.7.12
  • Python Bitness: 64
  • How did you install Zipline: pip
  • Python packages:

alembic==0.8.9 bcolz==0.12.1 beautifulsoup4==4.5.1 Bottleneck==1.2.0 cachetools==2.0.0 click==6.6 contextlib2==0.5.4 cyordereddict==1.0.0 Cython==0.25.2 decorator==4.0.10 empyrical==0.2.2 funcsigs==1.0.2 intervaltree==2.1.0 Logbook==1.0.0 Mako==1.0.6 MarkupSafe==0.23 mock==2.0.0 multipledispatch==0.4.9 networkx==1.11 numexpr==2.6.1 numpy==1.11.3 pandas==0.16.1 pandas-datareader==0.2.1 patsy==0.4.1 pbr==1.10.0 python-dateutil==2.6.0 python-editor==1.0.3 pytz==2016.10 requests==2.12.4 requests-file==1.4.1 scipy==0.18.1 six==1.10.0 sortedcontainers==1.5.7 SQLAlchemy==1.1.4 statsmodels==0.6.1 stockbot==0.2.0 TA-Lib==0.4.10 toolz==0.8.2 zipline==1.0.2

Now that you know a little about me, let me tell you about the issue I am having:

I ran the demo example in Stockbot's README, which is:

#!/usr/bin/env python

from logbook import Logger
from stockbot.algo.core import (
    adx_init,
    trade_di,
    trade_so,
)
from stockbot.core import get_sp500_list

def initialize(context):
    return adx_init(
        context,
        name='adx_di_so',
        top_rank=5,
        bot_rank=5,
        di_window=14,
        symbols=get_sp500_list(),
        log=Logger('Stockbot'),
    )

def handle_data(context, data):
    # increment counter and log datetime
    context.i += 1
    context.adx['log'].info('processing %s' % context.get_datetime())

    # trade trending S&P500 stocks using the DI system
    trade_di(
        context,
        data,
        window=context.adx['di_window'],
        portfolio=[i for (i, adx) in context.adx['top']],
        capital_ppi=1.0/(len(context.adx['top'])+len(context.adx['bot'])),
        log=context.adx['log'],
    )

    # trade oscillating S&P500 stocks using the SO system
    trade_so(
        context,
        data,
        window=context.adx['di_window'],
        portfolio=[i for (i, adx) in context.adx['bot']],
        capital_ppi=1.0/(len(context.adx['top'])+len(context.adx['bot'])),
        log=context.adx['log'],
    )

and that I launched through Zipline with:

zipline run -f stockbot_example.py --start 2010-01-01 --end 2016-12-12

However, Zipline dies midway through the download with the following traceback:

Traceback (most recent call last):
  File "/myproject/.env/bin/zipline", line 11, in <module>
    load_entry_point('zipline==1.0.2', 'console_scripts', 'zipline')()
  File "/myproject/.env/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/myproject/.env/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/myproject/.env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/myproject/.env/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/myproject/.env/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/__main__.py", line 97, in _
    return f(*args, **kwargs)
  File "/myproject/.env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/__main__.py", line 240, in run
    environ=os.environ,
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/utils/run_algo.py", line 180, in _run
    overwrite_sim_params=False,
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/algorithm.py", line 688, in run
    for perf in self.get_generator():
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 220, in transform
    for capital_change_packet in every_bar(dt):
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/gens/tradesimulation.py", line 133, in every_bar
    handle_data(algo, current_data, dt_to_use)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/utils/events.py", line 184, in handle_data
    dt,
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/utils/events.py", line 203, in handle_data
    self.callback(context, data)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/algorithm.py", line 459, in handle_data
    self._handle_data(self, data)
  File "test_stockbot.py", line 50, in handle_data
    log=context.adx['log'],
  File "/myproject/.env/local/lib/python2.7/site-packages/stockbot-0.2.0-py2.7.egg/stockbot/algo/core.py", line 192, in trade_so
    'high': data.history(i, 'high', window + 4, '1d'),
  File "zipline/_protocol.pyx", line 124, in zipline._protocol.check_parameters.__call__.assert_keywords_and_call (zipline/_protocol.c:3193)
  File "zipline/_protocol.pyx", line 626, in zipline._protocol.BarData.history (zipline/_protocol.c:8338)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/data_portal.py", line 777, in get_history_window
    field)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/data_portal.py", line 646, in _get_history_daily_window
    assets, days_for_window, end_dt, field_to_use
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/data_portal.py", line 667, in _get_history_daily_window_data
    extra_slot=False
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/data_portal.py", line 909, in _get_daily_window_for_sids
    extra_slot)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/history_loader.py", line 377, in history
    is_perspective_after)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/history_loader.py", line 280, in _ensure_sliding_windows
    asset, prefetch_dts, field, is_perspective_after)
  File "/myproject/.env/local/lib/python2.7/site-packages/zipline/data/history_loader.py", line 211, in _get_adjustments_in_range
    ratio)
  File "zipline/lib/adjustment.pyx", line 263, in zipline.lib.adjustment.Float64Adjustment.__init__ (zipline/lib/adjustment.c:5414)
TypeError: a float is required

chrisspen avatar Jan 02 '17 00:01 chrisspen

I'm having the same issue. date, 2006-12-20 and many others in 2006 quantopian-quandl data

quocgfy avatar Mar 10 '17 03:03 quocgfy

It looks like there's data issues in 2012. >= 2012 to present, this error doesn't show up.

quocble avatar Mar 13 '17 22:03 quocble

I have had this problem both with the quantopian-quandl bundle, and my own personal bundles. After some digging on my personal bundles, I traced the problem down to writing a NaN into the dividend values. There is a check in the OHLCV section which will not allow NaNs to be written but for some reason the behavior is different with the adjustments writer. The differences cause this bug to show up only when you are trying to get data from the bundle.

pbharrin avatar Feb 13 '19 14:02 pbharrin