Почему я не могу добавить значение в список на Quantopian?
def before_trading_start(context, data):
"""
Called every day before market open.
"""
#context.output = pipeline_output('my_pipeline')
# These are the securities that we are interested in trading each day.
#context.security_list = context.output.index
#get the historical price of silver and gold. the return format is a dataframe with gold and silver as column
Price_history = data.history(context.symbols, fields = "close", bar_count = 20, frequency = "1d")
lookback = 20
#slice to get price of gold and silver
gold_price1yr = Price_history.iloc[:,[0]]
#print gold_price1yr
silver_price1yr = Price_history.iloc[:,[1]]
#print silver_price1yr
constant_all = []
for i in range(len(silver_price1yr)):
gold_lookback = gold_price1yr[i: i + lookback]
if len(gold_lookback) == lookback:
silver_lookback = silver_price1yr[i: i + lookback]
silver_lookback = sm.add_constant(silver_lookback)
result = sm.OLS(gold_lookback, silver_lookback ).fit()
constant = result.params[0]
constant_all.append(constant)
print constant
#print gold_lookback
pd_constant_all = pd.DataFrame(constant_all)
print constant_all
#print Price_history
#print pd_constant_all
На выходе должен быть список. Тем не менее, я получаю только отдельные значения. Как следующее
2011-01-04 21:45 ПЕЧАТЬ 87.779121674 2011-01-04 21:45 ПЕЧАТЬ [87.7791216739692] 2011-01-05 21:45 ПЕЧАТЬ 93.2090812207 2011-01-05 21:45 ПЕЧАТЬ [93.209081220694856] 2011-01-06 21: 45 PRINT 88.4401372606 2011-01-06 21:45 PRINT [88.440137260626358] 2011-01-07 21:45 PRINT 82.7608582584 2011-01-07 21:45 PRINT [82.760858258436173] 2011-01-10 21:45 PRINT 76.95961595 2011- 01-10 21:45 ПЕЧАТЬ [76.959615949999503] 2011-01-11 21:45 ПЕЧАТЬ 70.6742891837 2011-01-11 21:45 ПЕЧАТЬ [70.674289183739688] 2011-01-12 21:45 ПЕЧАТЬ 70.6463954346 2011-01-12 21:45 ПЕЧАТЬ [70.646395434648355] 2011-01-13 21:45 ПЕЧАТЬ 70.4309108453 2011-01-13 21:45 ПЕЧАТЬ [70.430910845346773] 2011-01-14 21:45 ПЕЧАТЬ 69.0955253173 2011-01-14 21:45 ПЕЧАТЬ [69.095525317271182] 2011- 01-18 21:45 ПЕЧАТЬ 69.0679169919 2011-01-18 21:45 ПЕЧАТЬ [69.067916991920754] 2011-01-19 21:45 ПЕЧАТЬ 68.8110099435 2011-01-19 21:45 ПЕЧАТЬ [68.811009943546651] 2011-01-20 21:45 ПЕЧАТЬ 69.3882796904 2011-01-20 21:45 ПЕЧАТЬ [69.388279690360491] 2011-01-21 21:45 ПЕЧАТЬ 70.9655104 476 2011-01-21 21:45 ПЕЧАТЬ [70.965510447643481] 2011-01-24 21:45 ПЕЧАТЬ 71.7269364979 2011-01-24 21:45 ПЕЧАТЬ [71.726936497866348] 2011-01-25 21:45 ПЕЧАТЬ 73.5244489903 2011-01-25 21:45 PRINT [73.524448990312294] 2011-01-26 21:45 PRINT 74.5914691354 2011-01-26 21:45 PRINT [74.591469135412751] 2011-01-27 21:45 PRINT 75.2568473548 2011-01-27 21:45 PRINT [75.256847354849157 ] 2011-01-28 21:45 ПЕЧАТЬ 72.3128344168
Но когда попробуешь в блокноте, код выдаст мне список.