本文整理汇总了Python中zipline.assets.AssetFinder.clear_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python AssetFinder.clear_metadata方法的具体用法?Python AssetFinder.clear_metadata怎么用?Python AssetFinder.clear_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipline.assets.AssetFinder
的用法示例。
在下文中一共展示了AssetFinder.clear_metadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TradingEnvironment
# 需要导入模块: from zipline.assets import AssetFinder [as 别名]
# 或者: from zipline.assets.AssetFinder import clear_metadata [as 别名]
class TradingEnvironment(object):
@classmethod
def instance(cls):
global environment
if not environment:
environment = TradingEnvironment()
return environment
def __init__(
self,
load=None,
bm_symbol='^GSPC',
exchange_tz="US/Eastern",
max_date=None,
env_trading_calendar=tradingcalendar
):
"""
@load is function that returns benchmark_returns and treasury_curves
The treasury_curves are expected to be a DataFrame with an index of
dates and columns of the curve names, e.g. '10year', '1month', etc.
"""
self.trading_day = env_trading_calendar.trading_day.copy()
# `tc_td` is short for "trading calendar trading days"
tc_td = env_trading_calendar.trading_days
if max_date:
self.trading_days = tc_td[tc_td <= max_date].copy()
else:
self.trading_days = tc_td.copy()
self.first_trading_day = self.trading_days[0]
self.last_trading_day = self.trading_days[-1]
self.early_closes = env_trading_calendar.get_early_closes(
self.first_trading_day, self.last_trading_day)
self.open_and_closes = env_trading_calendar.open_and_closes.loc[
self.trading_days]
self.prev_environment = self
self.bm_symbol = bm_symbol
if not load:
load = load_market_data
self.benchmark_returns, self.treasury_curves = \
load(self.trading_day, self.trading_days, self.bm_symbol)
if max_date:
tr_c = self.treasury_curves
# Mask the treasury curves down to the current date.
# In the case of live trading, the last date in the treasury
# curves would be the day before the date considered to be
# 'today'.
self.treasury_curves = tr_c[tr_c.index <= max_date]
self.exchange_tz = exchange_tz
self.asset_finder = AssetFinder()
def __enter__(self, *args, **kwargs):
global environment
self.prev_environment = environment
environment = self
# return value here is associated with "as such_and_such" on the
# with clause.
return self
def __exit__(self, exc_type, exc_val, exc_tb):
global environment
environment = self.prev_environment
# signal that any exceptions need to be propagated up the
# stack.
return False
def update_asset_finder(self,
clear_metadata=False,
asset_finder=None,
asset_metadata=None,
identifiers=None):
"""
Updates the AssetFinder using the provided asset metadata and
identifiers.
If clear_metadata is True, all metadata and assets held in the
asset_finder will be erased before new metadata is provided.
If asset_finder is provided, the existing asset_finder will be replaced
outright with the new asset_finder.
If asset_metadata is provided, the existing metadata will be cleared
and replaced with the provided metadata.
All identifiers will be inserted in the asset metadata if they are not
already present.
:param clear_metadata: A boolean
:param asset_finder: An AssetFinder object to replace the environment's
existing asset_finder
:param asset_metadata: A dict, DataFrame, or readable object
:param identifiers: A list of identifiers to be inserted
:return:
#.........这里部分代码省略.........