-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (45 loc) · 1.57 KB
/
main.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from numbers import Number
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set_style("whitegrid")
from finstruct.core.unit import DateUnit, TermUnit, RateUnit
from finstruct.core.driver import Driver, IRCurveDriver, VOLSurfaceDriver
from finstruct.structures.core import Structure, StructArray, Manifold
from finstruct.structures.curve import IRCurve
driver = IRCurveDriver(
Index=[DateUnit("30/360")],
Basis=[TermUnit("Y", "30/360")],
Projection=[RateUnit("SPOT", "LINEAR", "Y")])
curve = Manifold.read_csv("data/treasury_rates.csv", driver, name="Test Manifold")
dates = [np.datetime64(datetime.date(2024,6,18)), np.datetime64(datetime.date(2024,6,14))]
terms = np.arange(1, 31)
#idx = curve._idx(Date=dates[0], Term=1) # error here
#idx2 = curve._idx_new(Date=dates[0], Term=10)
#print(all(idx == idx2))
index, coords, values = curve._interpolate(Date=dates, Term=terms)
# print(idx)
df = pd.DataFrame({"Date": index.flatten(),
"Term": coords.flatten(),
"Rate": values.flatten()})
print(df)
sns.lineplot(df,
x="Term",
y="Rate",
hue="Date")
plt.show()
testdict = {
"a": 1,
"b": 2
}
from finstruct.utils.data import StructArray
dictdata = {"a": [1, 2, 3],
"b": ["a", "b", "c"]}
dicttypes = {"a": int,
"b": str}
test = StructArray(dictdata, dicttypes)
test2 = test.filter(a=[1,2],b="a")
#print(test2._data)
#print(idx)
#print(curve.data)