Skip to content

Instantly share code, notes, and snippets.

@veridelisi
Created December 12, 2023 12:06
Show Gist options
  • Save veridelisi/44ac084db1ed51d227dd45e8e9145209 to your computer and use it in GitHub Desktop.
Save veridelisi/44ac084db1ed51d227dd45e8e9145209 to your computer and use it in GitHub Desktop.
import pandas as pd
# Set up the variables
spot_rates = {
1: 0.055,
2: 0.06,
3: 0.0625,
4: 0.065,
5: 0.07,
}
# Calculate discount factors using the correct formula
discount_factors = [(1 / (1 + spot_rates[i]) ** i) for i in range(1, 6)]
# Create a DataFrame to display the correct discount factors
discount_factors_table = pd.DataFrame(index=range(1, 6))
discount_factors_table.index.name = 'Year'
discount_factors_table['Spot Rate'] = [spot_rates[i] for i in range(1, 6)]
discount_factors_table['Discount Factor'] = discount_factors
# Display the results
print(discount_factors_table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment