Course Name: Mean Reversion Strategies In Python, Section No: 14, Unit No: 4, Unit type: Notebook
why is the daily_stock_return calculated as follow
daily_stock_returns = (spx-spx.shift(1))/spx.shift(1)
and not on AMZN as in the next line? thx.
Daily stock returns are calculated by subtracting stock's close price of yesterday to stock's close price of today and divided by the close price of yesterday.
daily_stock_returns = (spx-spx.shift(1))/spx.shift(1)
daily_stock_returns['AMZN'].plot(figsize=(10, 5))
The first line of code calculates the daily returns of all stocks stored in the 'spx' dataframe. This is further used to calculate market returns. The second line of code plots the daily returns of stock Amazon. This is done to demonstrate the daily returns of Amazon.
You can change the code to plot the stock Apple daily returns.
daily_stock_returns['AAPL'].plot(figsize=(10, 5))
Or, you can plot all stocks returns stored in the 'spx' at once by using the below code.
daily_stock_returns.plot(figsize=(10, 5))
Hope that helps.