0

环境:Zipline 1.3.0 miniconda3 windows OS

我正在尝试在数据中迭代 S。S.symbol 有 15 个值。

当迭代 1 个符号的数据时,如以下代码所示说“间谍”;我想创建 2keys

(S.symbol + "c") —> spyc 保存当前值

(S.symbol + “s”) —→ spys 保存一个浮点值。

def before_trading_start(context,data):
print("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#")
print("Get DateTime: ",get_datetime())
#context is a dictionary
for S in data:
    if(S.symbol == 'SPY'):
        arr = list(range(1,91))
        hist = data.history(S,"price",90,"1d")
        price_list = np.log(hist.tolist())
        context.spyc = data.current(S,"price")
        context.spys = Slope(arr, price_list)
        print (context.spyc)
        print (S.symbol, context.spys)


    else:
        continue
###############我的动态命名失败版本
def before_trading_start(context,data):
print("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*")
print("Get DateTime: ",get_datetime())
for S in data:
    arr = list(range(1,91))
    hist = data.history(S,"price",90,"1d")
    price_list = np.log(hist.tolist())

    context[S.symbol + "c"] = data.current(S,"price")
    context[S.symbol+"s"] = Slope(arr, price_list)
    print (context[S.symbol + "c"])
    print (S.symbol, context[S.symbol + "s"])

S.symbols = ["Spy","AAPl",'xom','L','T','CSCO','MSFT'..]

4

0 回答 0