prices = self.data.History(self.data.var["stocks"], 10, Resolution.Minute)
prices = prices['close']
ret_mean = prices.pct_change().mean()
msg = np.array2string(ret_mean,separator=',')
msg2 = prices.pct_change().to_string()
self.data.Log("ret pct_change " + msg2)
self.data.Log("ret_mean " + msg)
Running this should give me an output like this:
prices.pct_change().mean()
Output:
prices.pct_change().mean(): Series
Equity(8554 [SPY]): 0.000360162256317
Equity(19920 [QQQ]): -0.000349071472794
Equity(23921 [TLT]): -0.00105604535262
Equity(25801 [TIP]): -0.000195614219234
Equity(25485 [AGG]): -0.000227679365955
but it's giving me a total mean for all the stocks put together like this:
2017-01-03 09:32:00 ret pct_change symbol time
AGG 2016-12-30 15:52:00 NaN
2016-12-30 15:53:00 -0.000093
2016-12-30 15:54:00 0.000000
2016-12-30 15:55:00 0.000185
2016-12-30 15:56:00 0.000000
2016-12-30 15:57:00 0.000046
2016-12-30 15:58:00 0.000046
2016-12-30 15:59:00 0.000000
2017-01-03 09:30:00 -0.003054
2017-01-03 09:31:00 0.000000
QQQ 2016-12-30 15:52:00 0.107993
2016-12-30 15:53:00 0.000085
2016-12-30 15:54:00 0.000085
2016-12-30 15:55:00 0.001100
2016-12-30 15:56:00 -0.000169
2016-12-30 15:57:00 0.000845
2016-12-30 15:58:00 0.000169
2016-12-30 15:59:00 0.000676
2017-01-03 09:30:00 0.005738
2017-01-03 09:31:00 -0.000252
SPY 2016-12-30 15:52:00 0.862178
2016-12-30 15:53:00 0.000090
2016-12-30 15:54:00 0.000135
2016-12-30 15:55:00 0.000718
2016-12-30 15:56:00 0.000045
2016-12-30 15:57:00 0.000941
2016-12-30 15:58:00 0.000313
2016-12-30 15:59:00 0.000761
2017-01-03 09:30:00 0.006263
2017-01-03 09:31:00 -0.000489
TIP 2016-12-30 15:52:00 -0.497447
2016-12-30 15:53:00 0.000000
2016-12-30 15:54:00 0.000000
2016-12-30 15:55:00 0.000000
2016-12-30 15:56:00 -0.000044
2016-12-30 15:57:00 0.000044
2016-12-30 15:58:00 -0.000044
2016-12-30 15:59:00 0.000133
2017-01-03 09:30:00 -0.001856
2017-01-03 09:31:00 0.000177
TLT 2016-12-30 15:52:00 0.051175
2016-12-30 15:53:00 -0.000168
2016-12-30 15:54:00 -0.000084
2016-12-30 15:55:00 -0.000461
2016-12-30 15:56:00 -0.000126
2016-12-30 15:57:00 0.000420
2016-12-30 15:58:00 -0.000084
2016-12-30 15:59:00 -0.000252
2017-01-03 09:30:00 -0.006127
2017-01-03 09:31:00 0.000338
2017-01-03 09:32:00 ret_mean 0.010815266655526064
Any ideas where I went wrong?
Alexandre Catarino
Please checkout this thread where we explain the structure of the pandas.DataFrame from QC History method:
Essentially we have to redefine the data frame columns:
df = self.History(self.tickers, 10, Resolution.Daily).close prices = pd.concat([df.loc[x] for x in self.tickers], axis = 1) prices.columns = self.tickers
LukeI
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!