Skip to content

Orders are not executed and no errors are reported #2546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mstaniak opened this issue Sep 19, 2019 · 1 comment
Closed

Orders are not executed and no errors are reported #2546

mstaniak opened this issue Sep 19, 2019 · 1 comment

Comments

@mstaniak
Copy link

Dear Zipline Maintainers,

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

Environment

  • Operating System:
    Linux janusz 5.0.0-27-generic Fills in missing slots in transform data panels. #28-Ubuntu SMP Tue Aug 20 19:53:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Python Version: $ python --version
    3.5.4
  • Python Bitness:
    64
  • How did you install Zipline: pip
  • Python packages:
    alembic==1.1.0
    bcolz==0.12.1
    Bottleneck==1.2.1
    certifi==2019.6.16
    chardet==3.0.4
    Click==7.0
    contextlib2==0.5.5
    cycler==0.10.0
    cyordereddict==1.0.0
    Cython==0.29.13
    decorator==4.4.0
    docutils==0.15.2
    empyrical==0.5.3
    idna==2.8
    intervaltree==3.0.2
    kiwisolver==1.1.0
    Logbook==1.5.2
    lru-dict==1.1.6
    lxml==4.4.1
    Mako==1.1.0
    MarkupSafe==1.1.1
    matplotlib==3.0.3
    mock==3.0.5
    multipledispatch==0.6.0
    networkx==1.11
    numexpr==2.7.0
    numpy==1.17.2
    pandas==0.22.0
    pandas-datareader==0.7.4
    patsy==0.5.1
    pymongo==3.9.0
    pyparsing==2.4.2
    PyQt5==5.13.1
    PyQt5-sip==4.19.19
    python-dateutil==2.8.0
    python-editor==1.0.4
    pytz==2019.2
    requests==2.22.0
    requests-file==1.4.3
    scipy==1.3.1
    seaborn==0.9.0
    six==1.12.0
    sortedcontainers==2.1.0
    SQLAlchemy==1.3.8
    statsmodels==0.10.1
    tables==3.5.2
    toolz==0.10.0
    trading-calendars==1.8.1
    urllib3==1.25.3
    wrapt==1.11.2
    zipline==1.3.0

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

Description of Issue

  • I expected to run a successful simulation with a custom bundle or to see an error.
  • What happened instead? The backtest runs without errors, but no transactions happen.

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. Set up a virtual environment with the same package versions as above.
  2. Run the following code:
import pandas as pd
from zipline import run_algorithm
from zipline.api import (symbol, order, record)
from trading_calendars import get_calendar
from zipline.data.bundles import register, bundles, ingest
from zipline.data.bundles.csvdir import csvdir_equities

crypto_calendar = get_calendar('24/7')
csv_directory = '.' 
# change to your working directory. Folder called 'daily' is 
# inside this folder and contains simply the Bitcoin.csv file attached
csv_ingest = csvdir_equities(('daily', ), csv_directory)
register('crypto_bitcoin', csv_ingest, calendar_name = '24/7', create_writers=True)
ingest('crypto_bitcoin', show_progress=True)

def initialize(context):
    context.has_ordered = False 

def handle_data(context, data):
    record(bitcoin_price = data.current(symbol('Bitcoin'), 'price'),
           bitcoin_close = data.current(symbol('Bitcoin'), 'close'),
           has_ordered = context.has_ordered,
           is_stale = data.is_stale(symbol('Bitcoin')),
           can_trade = data.can_trade(symbol('Bitcoin')))
    if not context.has_ordered:
        order(symbol('Bitcoin'), 1)
        context.has_ordered = True
    else:
        pass

perf = run_algorithm(pd.Timestamp('2016-01-01', tz='UTC'),
                     pd.Timestamp('2016-06-30', tz='UTC'),
                     initialize=initialize,
                     handle_data=handle_data,
                     capital_base=10000,
                     data_frequency='daily',
                     bundle='crypto_bitcoin',
                     trading_calendar=crypto_calendar,
                     default_extension=False
    )
perf.bitcoin_price[0]
perf.bitcoin_close[0]
perf.transactions[0]
perf.orders[0]
perf.portfolio_value.unique()
perf.has_ordered.head(10)
perf.is_stale.unique()
perf.can_trade.unique()

From my perspective, this is the minimal working example.
The file that is used to get csv bundle is attached to this issue.

  1. The result in my setup is a backtest result where all transactions are empty lists and the only order looks like this:
limit : None
stop : None
id : 822b7532856343c8b09cc40e07bcec12
commission : 0
stop_reached : False
status : 0
sid : Equity(0 [BITCOIN])
limit_reached : False
created : 2016-01-01 23:59:00+00:00
reason : None
amount : 1
filled : 0
dt : 2016-01-01 23:59:00+00:00

What steps have you taken to resolve this already?

...

Anything else?

I'm using a slightly modified version of zipline, as per #2540 + I changed the default benchmark code to make it work.
My csv file:

date,open,high,low,close,volume,dividend,split
2016-01-01,430.72,436.25,427.52,434.33,36278900,0,0
2016-01-02,434.62,436.06,431.87,433.44,30096600,0,0
2016-01-03,433.58,433.74,424.71,430.01,39633800,0,0
2016-01-04,430.06,434.52,429.08,433.09,38477500,0,0
2016-01-05,433.07,434.18,429.68,431.96,34522600,0,0
2016-01-06,431.86,431.86,426.34,429.11,34042500,0,0
2016-01-07,430.01,458.77,429.08,458.05,87562200,0,0
2016-01-08,457.54,462.93,447.94,453.23,56993000,0,0
2016-01-09,453.38,454.64,446.89,447.61,32278000,0,0
2016-01-10,448.24,448.31,440.35,447.99,35995900,0,0
2016-01-11,448.7,450.66,443.86,448.43,40450000,0,0
2016-01-12,448.18,448.18,435.69,435.69,115607000,0,0
2016-01-13,434.67,435.19,424.44,432.37,173888000,0,0
2016-01-14,432.29,433.32,427.85,430.31,43945500,0,0
2016-01-15,430.26,430.26,364.33,364.33,153351008,0,0
2016-01-16,365.07,390.56,354.91,387.54,120352000,0,0
2016-01-17,387.15,390.96,380.09,382.3,45319600,0,0
2016-01-18,381.73,388.1,376.67,387.17,54403900,0,0
2016-01-19,387.03,387.73,378.97,380.15,46819800,0,0
2016-01-20,379.74,425.27,376.6,420.23,121720000,0,0
2016-01-21,419.63,422.88,406.3,410.26,68338000,0,0
2016-01-22,409.75,410.41,375.28,382.49,91546600,0,0
2016-01-23,382.43,394.54,381.98,387.49,56247400,0,0
2016-01-24,388.1,405.48,387.51,402.97,54824800,0,0
2016-01-25,402.32,402.32,388.55,391.73,59062400,0,0
2016-01-26,392.0,397.77,390.58,392.15,58147000,0,0
2016-01-27,392.44,396.84,391.78,394.97,47424400,0,0
2016-01-28,395.15,395.5,379.73,380.29,59247900,0,0
2016-01-29,380.11,384.38,365.45,379.47,86125296,0,0
2016-01-30,378.86,380.92,376.49,378.26,30284400,0,0
2016-01-31,378.29,380.35,367.83,368.77,37894300,0,0
2016-02-01,369.35,378.07,367.96,373.06,51656700,0,0
2016-02-02,372.92,375.88,372.92,374.45,40378700,0,0
2016-02-03,374.65,374.95,368.05,369.95,45933400,0,0
2016-02-04,370.17,391.61,369.99,389.59,69285504,0,0
2016-02-05,388.9,391.09,385.57,386.55,43825000,0,0
2016-02-06,386.59,386.63,372.39,376.52,49249300,0,0
2016-02-07,376.51,380.87,374.9,376.62,37076300,0,0
2016-02-08,376.76,379.88,373.33,373.45,47671100,0,0
2016-02-09,373.42,377.25,372.9,376.03,55318500,0,0
2016-02-10,376.15,385.48,375.78,381.65,85130896,0,0
2016-02-11,382.11,383.13,376.4,379.65,74375600,0,0
2016-02-12,379.69,384.95,379.6,384.26,67042800,0,0
2016-02-13,384.64,391.86,384.64,391.86,61911700,0,0
2016-02-14,392.93,407.23,392.93,407.23,74469800,0,0
2016-02-15,407.57,410.38,397.75,400.18,74070496,0,0
2016-02-16,401.43,408.95,401.43,407.49,73093104,0,0
2016-02-17,407.66,421.17,406.78,416.32,83193600,0,0
2016-02-18,416.57,426.0,415.64,422.37,76752600,0,0
2016-02-19,422.73,423.1,417.6,420.79,55711300,0,0
2016-02-20,421.6,441.98,421.6,437.16,93992096,0,0
2016-02-21,437.77,448.05,429.08,438.8,89820704,0,0
2016-02-22,438.99,439.05,432.92,437.75,85385200,0,0
2016-02-23,438.26,439.86,417.82,420.74,85244896,0,0
2016-02-24,420.96,425.55,413.91,424.95,67743696,0,0
2016-02-25,425.04,427.72,420.42,424.54,70798000,0,0
2016-02-26,424.63,432.15,421.62,432.15,61486000,0,0
2016-02-27,432.84,434.23,428.1,432.52,41893600,0,0
2016-02-28,432.57,435.68,423.82,433.5,53033400,0,0
2016-02-29,433.44,441.51,431.69,437.7,60694700,0,0
2016-03-01,437.92,439.65,432.32,435.12,74895800,0,0
2016-03-02,435.13,435.92,423.99,423.99,74955296,0,0
2016-03-03,423.91,425.37,419.41,421.65,100484000,0,0
2016-03-04,421.84,425.18,410.94,410.94,90856096,0,0
2016-03-05,410.78,411.26,394.04,400.57,135384992,0,0
2016-03-06,400.52,411.91,395.78,407.71,91212496,0,0
2016-03-07,407.76,415.92,406.31,414.32,85762400,0,0
2016-03-08,414.46,416.24,411.09,413.97,70311696,0,0
2016-03-09,413.89,416.03,411.61,414.86,70012304,0,0
2016-03-10,414.74,417.51,413.25,417.13,81022896,0,0
2016-03-11,417.24,423.93,417.01,421.69,73969696,0,0
2016-03-12,421.61,421.8,410.09,411.62,92712896,0,0
2016-03-13,411.65,416.6,411.64,414.07,74322800,0,0
2016-03-14,414.2,416.68,414.2,416.44,95259400,0,0
2016-03-15,416.39,418.13,414.98,416.83,66781700,0,0
2016-03-16,416.89,417.69,415.91,417.01,65185800,0,0
2016-03-17,417.89,421.0,417.89,420.62,83528600,0,0
2016-03-18,420.55,420.55,406.14,409.55,104940000,0,0
2016-03-19,409.27,410.98,407.23,410.44,58423000,0,0
2016-03-20,410.4,414.63,410.4,413.76,45947900,0,0
2016-03-21,413.42,413.42,410.38,413.31,61655400,0,0
2016-03-22,413.13,418.38,412.53,418.09,66813300,0,0
2016-03-23,418.16,419.27,417.36,418.04,61444200,0,0
2016-03-24,418.42,418.68,415.49,416.39,68346704,0,0
2016-03-25,416.51,418.08,415.56,417.18,52560000,0,0
2016-03-26,417.36,418.99,416.26,417.95,44650400,0,0
2016-03-27,418.14,428.8,417.71,426.77,71229400,0,0
2016-03-28,426.55,426.86,423.29,424.23,68522800,0,0
2016-03-29,424.3,426.2,412.68,416.52,75411504,0,0
2016-03-30,416.83,416.83,412.5,414.82,66034100,0,0
2016-03-31,415.26,418.37,415.26,416.73,60215200,0,0
2016-04-01,416.76,418.17,415.83,417.96,51235700,0,0
2016-04-02,418.42,422.08,418.42,420.87,45681200,0,0
2016-04-03,421.17,421.58,419.7,420.9,38053700,0,0
2016-04-04,421.3,422.34,419.6,421.44,50634300,0,0
2016-04-05,421.02,424.26,420.61,424.03,60718000,0,0
2016-04-06,424.28,424.53,422.73,423.41,59091000,0,0
2016-04-07,423.62,423.66,420.52,422.74,57858600,0,0
2016-04-08,422.91,425.36,419.64,420.35,63454700,0,0
2016-04-09,420.81,420.89,416.52,419.41,49792700,0,0
2016-04-10,419.59,422.43,419.26,421.56,73478600,0,0
2016-04-11,421.87,422.74,420.53,422.48,50747500,0,0
2016-04-12,422.84,427.28,422.84,425.19,70728800,0,0
2016-04-13,425.63,426.66,422.92,423.73,69060400,0,0
2016-04-14,423.93,425.37,423.01,424.28,45281000,0,0
2016-04-15,424.43,429.93,424.43,429.71,54801500,0,0
2016-04-16,429.58,432.63,428.98,430.57,39392800,0,0
2016-04-17,430.64,431.37,426.08,427.4,52125900,0,0
2016-04-18,427.61,429.27,427.09,428.59,55670900,0,0
2016-04-19,428.7,436.02,428.1,435.51,52810500,0,0
2016-04-20,435.32,443.05,434.41,441.39,72890096,0,0
2016-04-21,441.42,450.55,440.95,449.42,68204704,0,0
2016-04-22,449.69,449.81,444.15,445.74,58804400,0,0
2016-04-23,445.86,450.28,444.33,450.28,50485400,0,0
2016-04-24,450.56,460.15,448.93,458.55,68198400,0,0
2016-04-25,459.12,466.62,453.59,461.43,87091800,0,0
2016-04-26,461.65,467.96,461.62,466.09,78971904,0,0
2016-04-27,466.26,467.08,444.13,444.69,93564896,0,0
2016-04-28,445.04,449.55,436.65,449.01,74064704,0,0
2016-04-29,449.41,455.38,446.02,455.1,49258500,0,0
2016-04-30,455.18,455.59,447.7,448.32,69322600,0,0
2016-05-01,448.48,452.48,447.93,451.88,40660100,0,0
2016-05-02,451.93,452.45,441.78,444.67,92127000,0,0
2016-05-03,444.73,451.1,442.62,450.3,59366400,0,0
2016-05-04,450.18,450.38,445.63,446.72,50407300,0,0
2016-05-05,446.71,448.51,445.88,447.98,50440800,0,0
2016-05-06,447.94,461.38,447.07,459.6,72796800,0,0
2016-05-07,459.64,460.67,457.32,458.54,38364500,0,0
2016-05-08,458.43,459.42,455.98,458.55,40315000,0,0
2016-05-09,458.21,462.48,456.53,460.48,55493100,0,0
2016-05-10,460.52,461.93,448.95,450.89,58956100,0,0
2016-05-11,450.86,454.58,450.86,452.73,50605200,0,0
2016-05-12,452.45,454.95,449.25,454.77,59849300,0,0
2016-05-13,454.85,457.05,453.45,455.67,60845000,0,0
2016-05-14,455.82,456.84,454.79,455.67,37209000,0,0
2016-05-15,455.76,458.69,455.46,457.57,28514000,0,0
2016-05-16,457.59,458.2,452.95,454.16,59171500,0,0
2016-05-17,454.01,455.07,453.61,453.78,64100300,0,0
2016-05-18,453.69,456.0,453.3,454.62,86850096,0,0
2016-05-19,454.52,454.63,438.71,438.71,96027400,0,0
2016-05-20,437.79,444.05,437.39,442.68,81987904,0,0
2016-05-21,442.97,443.78,441.71,443.19,42762300,0,0
2016-05-22,443.22,443.43,439.04,439.32,39657600,0,0
2016-05-23,439.35,444.35,438.82,444.15,50582500,0,0
2016-05-24,444.29,447.1,443.93,445.98,65783100,0,0
2016-05-25,446.06,450.3,446.06,449.6,65231000,0,0
2016-05-26,449.67,453.64,447.9,453.38,65203800,0,0
2016-05-27,453.52,478.15,453.52,473.46,164780992,0,0
2016-05-28,473.03,533.47,472.7,530.04,181199008,0,0
2016-05-29,527.48,553.96,512.18,526.23,148736992,0,0
2016-05-30,528.47,544.35,522.96,533.86,87958704,0,0
2016-05-31,534.19,546.62,520.66,531.39,138450000,0,0
2016-06-01,531.11,543.08,525.64,536.92,86061800,0,0
2016-06-02,536.52,540.35,533.08,537.97,60378200,0,0
2016-06-03,537.68,574.64,536.92,569.19,122020000,0,0
2016-06-04,569.71,590.13,564.24,572.73,94925296,0,0
2016-06-05,573.31,582.81,569.18,574.98,68874096,0,0
2016-06-06,574.6,586.47,574.6,585.54,72138896,0,0
2016-06-07,585.45,590.26,567.51,576.6,107770000,0,0
2016-06-08,577.17,582.84,573.13,581.65,80265800,0,0
2016-06-09,582.2,582.2,570.95,574.63,71301000,0,0
2016-06-10,575.84,579.13,573.33,577.47,66991900,0,0
2016-06-11,578.67,607.12,578.67,606.73,82357000,0,0
2016-06-12,609.68,684.84,607.04,672.78,277084992,0,0
2016-06-13,671.65,716.0,664.49,704.38,243295008,0,0
2016-06-14,704.5,704.5,662.8,685.56,186694000,0,0
2016-06-15,685.68,696.3,672.56,694.47,99223800,0,0
2016-06-16,696.52,773.72,696.52,766.31,271633984,0,0
2016-06-17,768.49,775.36,716.56,748.91,363320992,0,0
2016-06-18,748.76,777.99,733.93,756.23,252718000,0,0
2016-06-19,756.69,766.62,745.63,763.78,136184992,0,0
2016-06-20,763.93,764.08,732.73,737.23,174511008,0,0
2016-06-21,735.88,735.88,639.07,666.65,309944000,0,0
2016-06-22,665.91,678.67,587.48,596.12,266392992,0,0
2016-06-23,597.44,629.33,558.14,623.98,253462000,0,0
2016-06-24,625.58,681.73,625.27,665.3,224316992,0,0
2016-06-25,665.28,691.73,646.56,665.12,126656000,0,0
2016-06-26,665.93,665.98,616.93,629.37,109225000,0,0
2016-06-27,629.35,655.28,620.52,655.28,122134000,0,0
2016-06-28,658.1,659.25,637.77,647.0,138384992,0,0
2016-06-29,644.12,644.68,628.28,639.89,142456000,0,0
2016-06-30,640.59,675.4,636.61,673.34,138980000,0,0

Sincerely,
mstaniak

@mstaniak
Copy link
Author

Removing split and dividend columns from the data fixed the issue.
Thus, I would like to suggest removing this part of the documentation:

Zipline provides a bundle called csvdir, which allows users to ingest data from .csv files. The format of the files should be in OHLCV format, with dates, dividends, and splits. A sample is provided below. There are other samples for testing purposes in zipline/tests/resources/csvdir_samples.

https://www.zipline.io/bundles.html#ingesting-data-from-csv-files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant