python ZIPLINE BUNDLES战略

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python ZIPLINE BUNDLES战略相关的知识,希望对你有一定的参考价值。

# checked against Portfoliovisualizer (same) and Quantopian IDE (slightly different)
# https://www.quantopian.com/algorithms/581b0739ca188f3011000203

from datetime import datetime
from zipline.api import get_datetime

def initialize(context):
    context.SPY = symbols('SPY')[0]
    schedule_function(
        get_monthly_returns,
        date_rules.month_end(),
        time_rules.market_close()
    )
 
def get_monthly_returns(context, data):
    
    h = data.history(context.SPY, ['open', 'high', 'low', 'close', 'volume', 'price'], 252, '1d')
    h_m = h.resample('M', how='last').price
    m_returns = h_m.pct_change() * 100
    print ('\n\n{} MONTHLY RETURNS\n\n{}'.format(get_datetime(), m_returns))
    
capital_base = 10000
start = datetime(2010, 12, 30, 0, 0, 0, 0, pytz.utc)
end = datetime(2011, 6, 4, 0, 0, 0, 0, pytz.utc)

result = run_algorithm(start = start, end = end, initialize=initialize,\
#                 before_trading_start = before_trading_start, \
                capital_base=capital_base, \
                bundle = 'etfs_bundle')

以上是关于python ZIPLINE BUNDLES战略的主要内容,如果未能解决你的问题,请参考以下文章

python ZIPLINE PIPELINE战略,没有大的因素

python ZIPLINE RUN SIMPLE PIPELINE

python ZIPLINE RUN PIPELINE

python ZIPLINE简单策略与管道因素

python 运行ZIPLINE PIPELINE(包括模拟输入)

python 什么ZIPLINE数据看起来像