Skip to content

Instantly share code, notes, and snippets.

@fyyying
Last active May 23, 2020 17:21
Show Gist options
  • Save fyyying/e50a0719aef68402ec7035bf584fa62f to your computer and use it in GitHub Desktop.
Save fyyying/e50a0719aef68402ec7035bf584fa62f to your computer and use it in GitHub Desktop.
Calculate forward rate with Pandas #forward_rate
# 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