Created
June 13, 2020 12:38
-
-
Save fyyying/9fc33e0972020bb0a1e7cf20ac3cba97 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 Koalas | |
import databricks.koalas as ks | |
# Read in the cash flows data and rate data as csv | |
cashflow_df = ks.read_csv(path_cashflow) | |
rate_df = ks.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"] | |
# Groupby product and check the profitability | |
cf_with_rate_df = cf_with_rate_df.groupby("Product")[["Present value"]].sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment