Skip to content

Instantly share code, notes, and snippets.

@fyyying
Last active July 13, 2020 08:26
Show Gist options
  • Save fyyying/9b03ab5b65fee193e33aa4a771dc68d9 to your computer and use it in GitHub Desktop.
Save fyyying/9b03ab5b65fee193e33aa4a771dc68d9 to your computer and use it in GitHub Desktop.
# Implementation with Pandas
import pandas as pd
# Read in the cash flows data and rate data as csv
cashflow_df = pd.read_csv(path_cashflow)
rate_df = pd.read_csv(path_rate)
# Calculate discount factor from the rates
rate_df["Discount factor"] = 1 / (1 + rate_df["Interest rate"])**rate_df["Year"]
# Join cash flows with rates
cf_with_rate_df = cashflow_df.merge(rate_df, on=["Currency", "Year"], how="left")
# Calculate present values
cf_with_rate_df["Present value"] = cf_with_rate_df["Cash flows"] * cf_with_rate_df["Discount factor"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment