-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathzcb_prices.py
More file actions
30 lines (21 loc) · 838 Bytes
/
zcb_prices.py
File metadata and controls
30 lines (21 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
"""
Generate Zero Coupon Bond Prices
Helper Fuction
"""
import sys
import os
import math
import pandas as pd
import numpy as np
spot_rates = pd.read_csv("https://raw.githubusercontent.com/wrcarpenter/Interest-Rate-Models/main/Data/spots-monthly.csv", header=0)
cols = list(spot_rates.columns.values)
zcbs = pd.DataFrame(np.zeros((spot_rates.shape[0], spot_rates.shape[1]), dtype=float), columns=cols)
zcbs['Date'] = spot_rates['Date']
spot_rates.to_clipboard()
for row in range(0, zcbs.shape[0]):
for col in range(1, zcbs.shape[1]):
# continuous compounding
zcbs.iloc[row, col] = np.exp(-1*spot_rates.iloc[row, col]/100*col/12)
# Saving down
zcbs.to_csv('C:/Users/wcarp/OneDrive/Desktop/Interest Rate Model/Data/zcbs.csv', index=False)