Skip to content

Instantly share code, notes, and snippets.

@fyyying
Last active May 23, 2020 13:35
Show Gist options
  • Save fyyying/ad1e9b6a6afd6b4bec90d094ae59214e to your computer and use it in GitHub Desktop.
Save fyyying/ad1e9b6a6afd6b4bec90d094ae59214e to your computer and use it in GitHub Desktop.
Calculate forward rate with koalas
# Implementation with Koalas
import databricks.koalas as ks
# Read in the data from csv
data = ks.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