Hello QC Support,
I have a question regarding how to convert the rolling window to a dataframe. In the documentation on rolling window here it is stated that:
RollingWindow is an array of data that allows for reverse list access semantics, where the object with index [0] refers to the most recent item in the window, and index [Length-1] refers to the last item in the window, where Length is the number of elements in the window.
Does that mean when the rolling window is moved into a dataframe, e.g.:
df = pd.DataFrame(symbolData.Close_rolling, columns=["Close"]).reset_index(drop=True)
that the most recent closing price is df["Close][0] and not df["Close][-1]? Can you confirm pls.
And if I wanted to calculate forward returns, which one below should it be:
df['FwdReturn'] = np.log(df["Close"].shift(-1)/df["Close"])
OR
df['FwdReturn'] = np.log(df["Close"] / df["Close"].shift(1))
And if I wanted to check “if current_price > previous_price”, which should it be:
if df["Close"][0] > df["Close"][1]
OR
if df["Close"][-1] > df["Close"][-2]
Thanks again.
Louis Szeto
Hi Sheikh
Yes the most recent input would be df['close'].iloc[0]. That means the forward return should be df['fwdReturn'] = np.log(df.close/df.close.shift(-1)) (you need to shift 1 unit backward as previous day input). And the comparison is “if df['fwdReturn'].iloc[0] > df['fwdReturn'].iloc[1]:”. However, we suggest you reverse the order of the dataframe by the following code to use it like order of History:
Note that you should be using .iloc for pandas mapping. Please check the attached notebook for technical details.
Best
Louis Szeto
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.
Sheikh Pancham
Thanks Louis, got it, greatly appreciated!
Sheikh Pancham
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!