zipline icon indicating copy to clipboard operation
zipline copied to clipboard

No market times defined for LSE

Open warren-oneill opened this issue 11 years ago • 3 comments

According to the commentary for the TradingEnvironment class

# This module maintains a global variable, environment, which is
# subsequently referenced directly by zipline financial
# components. To set the environment, you can set the property on
# the module directly:
#       from zipline.finance import trading
#       trading.environment = TradingEnvironment()
#
# or if you want to switch the environment for a limited context
# you can use a TradingEnvironment in a with clause:
#       lse = TradingEnvironment(bm_index="^FTSE", exchange_tz="Europe/London")
#       with lse:
# the code here will have lse as the global trading.environment
#           algo.run(start, end)

but as outlined here http://stackoverflow.com/q/25165500/4527613 this doesn't work without further tweaking. A possible solution would be to include the same functionality for LSE as for NYSE, e.g. specify get_non_trading_days(), get_open_and_closes() etc... and then define the TradingEnvironment with

TradingEnvironment(bm_index="^FTSE", exchange_tz="Europe/London", env_trading_calendar=tradingcalendar_lse)

That way the times will be specified as well as the days.

warren-oneill avatar Feb 04 '15 11:02 warren-oneill

Implementation of the LSE market times may be harder than I originally thought. The NYSE calendar days are hardcoded in the loader with the following

from zipline.utils.tradingcalendar import (
    trading_day,
    trading_days
)

and the NYSE early closing times are hardcoded in the TradingEnvironment with

self.early_closes = get_early_closes(self.first_trading_day,
                                             self.last_trading_day)

Surely the latter would be better written as

self.early_closes = env_trading_calendar.get_early_closes(self.first_trading_day,
                                             self.last_trading_day)

?

warren-oneill avatar Feb 06 '15 12:02 warren-oneill

Pull Request created #523

warren-oneill avatar Mar 12 '15 10:03 warren-oneill

Going to close this b/c the PR linked above is closed, and there are docs for making custom trading calendars now (on zipline master).

freddiev4 avatar Jan 03 '18 05:01 freddiev4