Created
June 28, 2020 11:06
-
-
Save ranaroussi/72d0e92bbe31d1514baccf00175049e4 to your computer and use it in GitHub Desktop.
Daily Risk Free Rate (based on 3-Month US Treasury Bills Rates)
This file contains hidden or 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 | |
# de-annualize yearly interest rates | |
def deannualize(annual_rate, periods=365): | |
return (1 + annual_rate) ** (1/periods) - 1 | |
def get_risk_free_rate(): | |
# download 3-month us treasury bills rates | |
annualized = yf.download("^IRX")["Adj Close"] | |
# de-annualize | |
daily = annualized.apply(deannualize) | |
# create dataframe | |
return pd.DataFrame({"annualized": annualized, "daily": daily}) | |
if __name__ == "__main__": | |
rates = get_risk_free_rate() | |
print(rates.tail()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
divide Adj Close values by 100 before passing through function, no?