Open jjaviergalvez opened 6 years ago
I tried with the following custom calendar:
from datetime import time
from zipline.utils.memoize import lazyval
from pandas.tseries.offsets import CustomBusinessDay
from pytz import timezone
from .trading_calendar import TradingCalendar
class TwentyFourHR(TradingCalendar):
"""
Exchange calendar for 24/7 trading.
Open Time: 12am, UTC
Close Time: 11:59pm, UTC
"""
@property
def name(self):
return "twentyfourhr"
@property
def tz(self):
return timezone("UTC")
@property
def open_time(self):
return time(9, 31)
@property
def close_time(self):
return time(16)
@lazyval
def day(self):
return CustomBusinessDay(
weekmask='Mon Tue Wed Thu Fri',
)
and it seems to work. So I suspect that part of the problem comes from the NYSEExchangeCalendar
. I don't know why if in the class was declared as
@property
def close_time(self):
return time(16)
Why the error at time 16:01?
I modified to return time(16,0)
and even return time(15)
but the same error pops up.
The other issue is that the start
parameter in the run_algorithm(...)
function doesn't recognize the time.
Hi @jjaviergalvez sorry for the delayed response. I haven't yet had the time to look into this more in-depth, but if you already have data in a .csv
file, you can ingest it using the csvdir
bundle, which we have docs for here.
Let me know if any of those docs are unclear.
Dear Zipline Maintainers,
Before I tell you about my issue, let me describe my environment: name: myenv channels:
Environment
pip
bcolz 0.12.1
Bottleneck 1.2.1
certifi 2018.4.16 py35_0
chardet 3.0.4
decorator 4.3.0 py35_0
empyrical 0.4.3
expat 2.2.5 he0dffb1_0
fontconfig 2.12.6 h49f89f6_0
freetype 2.8 hab7d2ae_1
glib 2.56.1 h000015b_0
gmp 6.1.2 h6c8ec71_1
gst-plugins-base 1.14.0 hbbd80ab_1
gstreamer 1.14.0 hb453b48_1
html5lib 1.0.1 py35h2f9c1c0_0
icu 58.2 h9c2bf20_1
idna 2.6
ipython 6.4.0 py35_0
ipython_genutils 0.2.0 py35hc9e07d0_0
ipywidgets 7.2.1 py35_0
jedi 0.12.0 py35_1
jinja2 2.10 py35h480ab6d_0
jpeg 9b h024ee3a_2
jsonschema 2.6.0 py35h4395190_0
jupyter 1.0.0 py35_4
jupyter_client 5.2.3 py35_0
jupyter_console 5.2.0 py35h4044a63_1
jupyter_core 4.4.0 py35ha89e94b_0
libedit 3.1.20170329 h6b74fdf_2
libffi 3.2.1 hd88cf55_4
libgcc-ng 7.2.0 hdf63c60_3
libpng 1.6.34 hb9fc6fc_0
libsodium 1.0.16 h1bed415_0
libstdcxx-ng 7.2.0 hdf63c60_3
libxcb 1.13 h1bed415_1
libxml2 2.9.8 h26e45fe_1
Logbook 1.4.0
mistune 0.8.3 py35h14c3975_1
multipledispatch 0.5.0
nbformat 4.4.0 py35h12e6e07_0
ncurses 6.1 hf484d3e_0
networkx 1.11
numexpr 2.6.5
pandas 0.18.1
pandocfilters 1.4.2 py35h1565a15_1
parso 0.2.1 py35_0
patsy 0.5.0
pexpect 4.6.0 py35_0
pickleshare 0.7.4 py35hd57304d_0
pip 10.0.1 py35_0
prompt_toolkit 1.0.15 py35hc09de7a_0
ptyprocess 0.5.2 py35h38ce0a3_0
pygments 2.2.0 py35h0f41973_0
pyqt 5.9.2 py35h751905a_0
python 3.5.5 hc3d631a_4
python-dateutil 2.7.3 py35_0
python-editor 1.0.3
qt 5.9.5 h7e424d6_0
qtconsole 4.3.1 py35h4626a06_0
readline 7.0 ha6073c6_4
requests 2.18.4
setuptools 39.2.0 py35_0
simplegeneric 0.8.1 py35_2
sip 4.19.8 py35hf484d3e_0
six 1.11.0 py35h423b573_1
sortedcontainers 2.0.3
statsmodels 0.9.0
testpath 0.3.1 py35had42eaf_0
tk 8.6.7 hc745277_3
toolz 0.9.0
traitlets 4.3.2 py35ha522a97_0
urllib3 1.22
webencodings 0.5.1 py35hb6cf162_1
wheel 0.31.1 py35_0
widgetsnbextension 3.2.1 py35_0
xz 5.2.4 h14c3975_4
zeromq 4.2.5 h439df22_0
zipline 1.2.0
Now that you know a little about me, let me tell you about the issue I am having:
Description of Issue
I'm trying to work with local files with ziplines. My local file is minute by minute data. But when I run the algorithm with
zipline.run_algorithm(...)
I get an error regarding that some dates are not my data.start
andend
inzipline.run_algorithm(...)
doesn't differentiate betweendatetime(2018, 1, 3, 9, 33, 0, 0, pytz.utc)
anddatetime(2018, 1, 3, 0, 0, 0, 0, pytz.utc)
. In other words, it seems that it only considers the year/month/day but not the hour. Then, I can not use all my data.Here is how you can reproduce this issue on your machine:
Reproduction Steps
data = OrderedDict() data['SPY'] = pd.read_csv('AAPL.csv', index_col=0, parse_dates=[['Date', 'Timestamp']]) data['SPY'] = data['SPY'][['OpenPrice', 'HighPrice', 'LowPrice', 'ClosePrice', 'TotalVolume']] panel = pd.Panel(data) panel.minor_axis = ['open', 'high', 'low', 'close', 'volume'] panel.major_axis = panel.major_axis.tz_localize(pytz.utc)
from zipline.api import order, record, symbol, set_benchmark import zipline from datetime import datetime
def initialize(context): set_benchmark(symbol("SPY"))
def handle_data(context, data): order(symbol("SPY"), 10) record(SPY=data.current(symbol('SPY'), 'price'))
use start=datetime(2018, 1, 2, 9, 33, 0, 0, pytz.utc) to see that doesn't matter the time
perf = zipline.run_algorithm(start=datetime(2018, 1, 3, 9, 33, 0, 0, pytz.utc), end=datetime(2018, 2, 4, 9, 40, 0, 0, pytz.utc), initialize=initialize, capital_base=100000, handle_data=handle_data, data_frequency ='minute', data=panel)