Skip to content

Instantly share code, notes, and snippets.

@HumanRupert
Last active January 23, 2021 07:20
Show Gist options
  • Save HumanRupert/ebdf16b1211e3f8c9f378b173af87dd3 to your computer and use it in GitHub Desktop.
Save HumanRupert/ebdf16b1211e3f8c9f378b173af87dd3 to your computer and use it in GitHub Desktop.
AMZN excess monthly returns
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