Last active
May 23, 2020 13:35
-
-
Save fyyying/ad1e9b6a6afd6b4bec90d094ae59214e to your computer and use it in GitHub Desktop.
Calculate forward rate with koalas
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 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