Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Created June 28, 2020 11:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ranaroussi/72d0e92bbe31d1514baccf00175049e4 to your computer and use it in GitHub Desktop.
Save ranaroussi/72d0e92bbe31d1514baccf00175049e4 to your computer and use it in GitHub Desktop.
Daily Risk Free Rate (based on 3-Month US Treasury Bills Rates)
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())
@mreous714
Copy link

divide Adj Close values by 100 before passing through function, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment