Hi,
I've managed to overcome the issue on skipping the US holiday by adding the following - trading_calendar=get_calendar("LSE") -
twice in TradingAlgorithim - see below in bold. Output is now:
2017-01-13 16:30:00+00:00
2017-01-16 16:30:00+00:00
2017-01-17 16:30:00+00:00
But unfortunately I still have the problem when I use pipeline, I get this: ValueError: Mask shape (20, 1) != data shape (21, 1).
if name == 'main':
start = makeTS("2017-01-01"); end = makeTS("2017-1-31")
# load the bundle
bundle_data = load('csv2', os.environ, None)
cal = bundle_data.equity_daily_bar_reader.trading_calendar.all_sessions
pipeline_loader = USEquityPricingLoader(bundle_data.equity_daily_bar_reader, bundle_data.adjustment_reader)
choose_loader = make_choose_loader(pipeline_loader)
env = TradingEnvironment(bm_symbol='^FTSE', exchange_tz='Europe/London',trading_calendar=get_calendar("LSE"),
asset_db_path=parse_sqlite_connstr(bundle_data.asset_finder.engine.url))
data = DataPortal(
env.asset_finder, get_calendar("LSE"),
first_trading_day=bundle_data.equity_minute_bar_reader.first_trading_day,
equity_minute_reader=bundle_data.equity_minute_bar_reader,
equity_daily_reader=bundle_data.equity_daily_bar_reader,
adjustment_reader=bundle_data.adjustment_reader,
)
# the actual running of the backtest happens in the TradingAlgorithm object
bt_start = time()
perf = TradingAlgorithm(
env=env,
get_pipeline_loader=choose_loader,
**trading_calendar=get_calendar("LSE"),**
sim_params=create_simulation_parameters(
start=start,
end=end,
capital_base=CAPITAL_BASE,
**trading_calendar=get_calendar("LSE"),**
data_frequency='daily'
),
**{
'initialize': initialize,
'handle_data': handle_data,
'before_trading_start': None,
'analyze': None,
}
).run(data, overwrite_sim_params=False,)
bt_end = time()
Hi Guys,
I'm trying to run zipline locally on UK stocks but I haven't figured out how to stop it using US holidays. The date I'm testing with is 16th Jan 2017 (Martin Luther King Day)
My steps have been -
1) Downloaded data from yahoo into a csv file
2) Implemented the steps to ingest custom data as per this link http://www.prokopyshen.com/create-custom-zipline-data-bundle
3) Ran the ingest comment using the LSE calendar
from zipline.data.bundles import register
from zipline.data.bundles.viacsv import viacsv
from zipline.utils.calendars import get_calendar
from zipline.utils.calendars import exchange_calendar_lse
eqSym = {
"CPI",
}
register(
'csv2', # name this whatever you like
viacsv(eqSym),
calendar_name='LSE',
)
4) Implemented the following code - and so far - bundle_data.equity_daily_bar_reader.trading_calendar.all_sessions has returned a UK looking calendar
bundle_data = load('csv2', os.environ, None)
cal = bundle_data.equity_daily_bar_reader.trading_calendar.all_sessions
pipeline_loader = USEquityPricingLoader(bundle_data.equity_daily_bar_reader, bundle_data.adjustment_reader)
choose_loader = make_choose_loader(pipeline_loader)
env = TradingEnvironment(bm_symbol='^FTSE',
exchange_tz='Europe/London',asset_db_path=parse_sqlite_connstr(bundle_data.asset_finder.engine.url))
data = DataPortal(
env.asset_finder, get_calendar("LSE"),
first_trading_day=bundle_data.equity_minute_bar_reader.first_trading_day,
equity_minute_reader=bundle_data.equity_minute_bar_reader,
equity_daily_reader=bundle_data.equity_daily_bar_reader,
adjustment_reader=bundle_data.adjustment_reader,
)
5) But when I run it with a very simple test, I can see it skips 16th Jan 2017 which is a US holiday not a UK one by using get_datetime() in handle_data()
2017-01-12 21:00:00+00:00
2017-01-13 21:00:00+00:00
2017-01-17 21:00:00+00:00
6) And if I use pipeline it throws this error
ValueError: Mask shape (20, 1) != data shape (19, 1).
Any help will greatly be appreciated.
Thanks Stuart