Last active
January 23, 2021 07:20
-
-
Save HumanRupert/ebdf16b1211e3f8c9f378b173af87dd3 to your computer and use it in GitHub Desktop.
AMZN excess monthly returns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yfinance as yf | |
import pandas as pd | |
amzn = yf.Ticker("AMZN") | |
hist = amzn.history(period="max", auto_adjust=True, rounding=False) | |
price = hist[["Close"]] | |
monthly_price = price.resample('BM').last() | |
# calculate monthly returns | |
monthly_returns = monthly_price.pct_change().dropna() | |
# calculate excess monthly returns | |
excess_returns = (monthly_returns['Close'] - factors['RF']).dropna() | |
# calculate cumulative sum of monthly returns | |
excess_returns_cum = excess_returns.cumsum() | |
excess_returns_cum.plot.line() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment