Last active
July 13, 2020 08:26
-
-
Save fyyying/9b03ab5b65fee193e33aa4a771dc68d9 to your computer and use it in GitHub Desktop.
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 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