Skip to content

Instantly share code, notes, and snippets.

@HumanRupert
Last active January 24, 2021 07:11
Show Gist options
  • Save HumanRupert/f6d101794ccee0247bac8090fe67c63b to your computer and use it in GitHub Desktop.
Save HumanRupert/f6d101794ccee0247bac8090fe67c63b to your computer and use it in GitHub Desktop.
import yfinance as yf
import pandas as pd
etsy = yf.Ticker("ETSY")
hist = etsy.history(period="max", auto_adjust=True, rounding=False)
price = hist[["Close"]]
# resample by latest monthly price
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()
# convert to dataframe
excess_returns = pd.DataFrame(data=excess_returns.values,
index=excess_returns.index,
columns=["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