# Load CSV
import pandas as pddata['btc_usdt'] = pd.DataFrame.from_csv('data/kraken-usd.csv')
# Run it
from datetime import datetimefrom zipline.api import order, record, symbolfrom zipline.algorithm import TradingAlgorithmfrom zipline import run_algorithmimport strategies.true_koala as strategy
start = datetime(2015, 1, 1, 0, 0, 0, 0, pytz.utc)end = datetime(2016, 1, 1, 0, 0, 0, 0, pytz.utc)
#algo_obj = TradingAlgorithm(initialize=strategy.initialize, handle_data=strategy.handle_data, start=start, end=end, capital_base = 100000.0)algo = run_algorithm( start=start, end=end, initialize=initialize, handle_data=strategy.handle_data, # analyze = analyze, data=data, #data_frequency = 'minute', capital_base = 1e6 )perf_manual = algo_obj.run(panel)
def initialize(context): context.i = 0 context.asset = symbol('btc_usdt')
def handle_data(context, data): # Skip first 21 days to get full windows context.i += 1 if context.i < 21: return
# Compute averages # data.history() has to be called with the same params # from above and returns a pandas dataframe. short_mavg = data.history(context.asset, 'price', bar_count=7, frequency="1d").mean() long_mavg = data.history(context.asset, 'price', bar_count=21, frequency="1d").mean()
# Trading logic if short_mavg > long_mavg: # order_target orders as many shares as needed to # achieve the desired number of shares. order_target(context.asset, 100) elif short_mavg < long_mavg: order_target(context.asset, 0)
# Save values for later inspection record(btc=data.current(context.asset, 'price'), short_mavg=short_mavg, long_mavg=long_mavg)
Date,Open,High,Low,Close,Volume (BTC),Volume (Currency),Weighted Price2017-11-13,5840.0,5879.8,5800.0,5848.2,13.04438313,75825.9992298,5812.923345942017-11-12,6330.0,6500.0,5464.0,5880.0,14495.1237039,86294051.5049,5953.315974942017-11-11,6567.1,6800.0,6200.0,6330.0,6931.899168,44788043.9663,6461.15052756...
2014-01-09,825.56345,870.0,807.42084,841.86934,8.1583345,6784.24998189,831.572912572014-01-08,810.0,899.84281,788.0,824.98287,19.18275555,16097.3295835,839.1562693662014-01-07,874.6704,892.06753,810.0,810.0,15.62237812,13151.4728443,841.835522304
SymbolNotFound: Symbol 'BTC_USDT' was not found.
Could you please help me out?
Thanks a lot.
from zipline.data.bundles import registerfrom zipline.data.bundles.csvdir import csvdir_equities
register('csvdir', csvdir_equities(['daily', 'minute']))
%%zipline -b csvdir --start 2016-1-1 --end 2017-1-1 --data-frequency daily
def initialize(context): context.i = 0
context.asset = symbol('BTC_USD')
ValueError: SQLite file u'/home/av/.zipline/data/csvdir/2017-11-14T17;00;29.202350/assets-6.sqlite' doesn't exist.
I feel like I am a step closer, but I don't know what to do next.
Could anyone help me out please? Thanks!
(.env) > $ CSVDIR=./csvdir/ zipline ingest -b csvdir [±feature/demo ●●] /home/av/.zipline/extension.py:4: UserWarning: Overwriting bundle with name 'csvdir'
register('csvdir', csvdir_equities(['daily', 'minute']))
Loading custom pricing data: [####################################] 100% | BTC_USD: sid 0 Merging daily equity files: [------------------------------------] 0 Traceback (most recent call last): File "/home/av/repos/ziplinetest/.env/bin/zipline", line 11, in <module> load_entry_point('zipline==1.1.1+152.g18e4186f', 'console_scripts', 'zipline')() File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/__main__.py", line 327, in ingest show_progress, File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/data/bundles/core.py", line 451, in ingest pth.data_path([name, timestr], environ=environ), File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/data/bundles/csvdir.py", line 94, in ingest self.csvdir) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/data/bundles/csvdir.py", line 156, in csvdir_bundle show_progress=show_progress) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/data/us_equity_pricing.py", line 257, in write return self._write_internal(it, assets) File "/home/av/repos/ziplinetest/.env/lib/python2.7/site-packages/zipline/data/us_equity_pricing.py", line 378, in _write_internal ).difference(asset_sessions).tolist(), AssertionError: Got 1407 rows for daily bars table with first day=2014-01-07, last day=2017-11-13, expected 972 rows. Missing sessions: []
class POLONIEXExchangeCalendar(TradingCalendar): """ Exchange calendar for Poloniex US.
Open Time: 12am, US/Eastern Close Time: 11:59pm, US/Eastern
""" @property def name(self): return "POLONIEX"
@property def tz(self): return timezone("UTC")
@property def open_time(self): return time(0, 0)
@property def close_time(self): return time(23,59)
@lazyval def day(self): return CustomBusinessDay( weekmask='Mon Tue Wed Thu Fri Sat Sun', )
register_calendar('POLONIEX', POLONIEXExchangeCalendar( start=Timestamp('2014-01-07', tz='UTC'), end=Timestamp('2017-11-12', tz='UTC') ))register('custom-csvdir-bundle', csvdir_equities(["daily", "minute"], '/home/av/repos/ziplinetest/csvdir'), calendar_name='POLONIEX')
Date,open,high,low,close,volume,Volume (Currency),Weighted Price
2017-11-13,5840.0,5879.8,5800.0,5848.2,13.04438313,75825.9992298,5812.92334594
...
2014-01-07,874.6704,892.06753,810.0,810.0,15.62237812,13151.4728443,841.835522304
CSVDIR=./csvdir/ zipline ingest -b custom-csvdir-bundle
IndexError: index 1406 is out of bounds for axis 0 with size 1406
Error: Invalid value for "--trading-calendar": invalid choice: POLONIEX. (choose from BMF, CFE, CME, ICE, LSE, NYSE, TSX, us_futures)
register_calendar(
'TWENTYFOURSEVEN',
TwentyFourSevenCalendar(
start=start_session,
end=end_session
)
)
def register_calendar_alias(self, alias, real_name, force=False):
Hello!Same problem here.I'm trying to ingest some btc data using csvdir bundle and I keep getting this error:AssertionError: Got 2330 rows for daily bars table with first day=2011-09-13, last day=2018-01-29, expected 1605 rows.It looks like a calendar issue, so I registered POLONIEX calendar I found on this group but it didn't help.Any ideas how to solve this? Ed Bartosh? Thanks!
--
You received this message because you are subscribed to the Google Groups "Zipline Python Opensource Backtester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
register(
'crypto-bundle',
csvdir_equities(
['daily'],
'/Users/tadukas/dev/Zipline/csvdir',
),
calendar_name='POLONIEX'
)
--
You received this message because you are subscribed to the Google Groups "Zipline Python Opensource Backtester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+u...@googlegroups.com.
--BR,
Ed
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.
register_calendar(
'POLONIEX',
POLONIEXExchangeCalendar(
start=Timestamp('2011-01-01', tz='UTC'),
end=Timestamp('2018-01-29', tz='UTC')
)
)
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.