Last active
January 24, 2021 07:11
-
-
Save HumanRupert/f6d101794ccee0247bac8090fe67c63b to your computer and use it in GitHub Desktop.
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 | |
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