Last active
May 23, 2020 17:21
-
-
Save fyyying/e50a0719aef68402ec7035bf584fa62f to your computer and use it in GitHub Desktop.
Calculate forward rate with Pandas #forward_rate
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
# Implementation with Pandas | |
import pandas as pd | |
# Read in the data from csv | |
data = pd.read_csv(rate_path) | |
# Shift the spot rate down along the maturity axis and calculate forward rate | |
data["Spot_Rate_Shift"] = data["Spot_Rate"].shift(1, fill_value=0) | |
data["Forward_Rate"] = (((1 + data["Spot_Rate"]) ** data["Maturity"]) / | |
((1 + data["Spot_Rate_Shift"]) ** (data["Maturity"] - 1)) - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment