mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 15:33:42 +08:00
ENH: Allow user to set the symbol lookup date
Previously symbols were resolved to sids based on the end of simulation date. This commit allows the user to specify the date for which resolution will take place using a new set_symbol_lookup_date() API method. If the user does not use this method the lookup date will default back to the simulation end date.
This commit is contained in:
+19
-1
@@ -225,6 +225,10 @@ class TradingAlgorithm(object):
|
||||
# Set the dt initally to the period start by forcing it to change
|
||||
self.on_dt_changed(self.sim_params.period_start)
|
||||
|
||||
# The symbol lookup date specifies the date to use when resolving
|
||||
# symbols to sids, and can be set using set_symbol_lookup_date()
|
||||
self._symbol_lookup_date = None
|
||||
|
||||
self.portfolio_needs_update = True
|
||||
self.account_needs_update = True
|
||||
self.performance_needs_update = True
|
||||
@@ -693,9 +697,14 @@ class TradingAlgorithm(object):
|
||||
Default symbol lookup for any source that directly maps the
|
||||
symbol to the Asset (e.g. yahoo finance).
|
||||
"""
|
||||
# If the user has not set the symbol lookup date,
|
||||
# use the period_end as the date for sybmol->sid resolution.
|
||||
_lookup_date = self._symbol_lookup_date if self._symbol_lookup_date is not None \
|
||||
else self.sim_params.period_end
|
||||
|
||||
return self.asset_finder.lookup_symbol_resolve_multiple(
|
||||
symbol_str,
|
||||
as_of_date=self.sim_params.period_end
|
||||
as_of_date=_lookup_date
|
||||
)
|
||||
|
||||
@api_method
|
||||
@@ -986,6 +995,15 @@ class TradingAlgorithm(object):
|
||||
raise OverrideCommissionPostInit()
|
||||
self.commission = commission
|
||||
|
||||
@api_method
|
||||
def set_symbol_lookup_date(self, dt):
|
||||
"""
|
||||
Set the date for which symbols will be resolved to their sids
|
||||
(symbols may map to different firms or underlying assets at
|
||||
different times)
|
||||
"""
|
||||
self._symbol_lookup_date = pd.Timestamp(dt, tz='UTC')
|
||||
|
||||
def set_sources(self, sources):
|
||||
assert isinstance(sources, list)
|
||||
self.sources = sources
|
||||
|
||||
Reference in New Issue
Block a user