-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
import numpy as np
import QuantLib as ql
import polars as pl
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter
read the input data
df_ois = pl.read_csv("data.csv")
today = ql.Date(5, 11, 2025)
ql.Settings.instance().evaluationDate = today
bps = 1e-4
index= ql.Estr()
settlement_days = 2
ois_quotes = {}
ois_helpers = []
for line in range(df_ois.shape[0]):
tenor = df_ois[line, 'Tenor']
quote = df_ois[line, 'Yield_bis']
q = ql.SimpleQuote(quote / 100.0)
ois_quotes[tenor] = q
ois_helpers.append(
ql.OISRateHelper(
settlement_days,
ql.Period(tenor),
ql.QuoteHandle(q),
index,
paymentFrequency=ql.Annual,
)
)
estr_curve = ql.PiecewiseLogLinearDiscount(
0,
ql.TARGET(),
ois_helpers,
ql.Actual360(),
)
ax = plt.figure(figsize=(9, 4)).add_subplot(1, 1, 1)
ax.yaxis.set_major_formatter(FuncFormatter(lambda r, pos: f"{r:.2%}"))
times = np.linspace(0.0, estr_curve.maxTime(), 2500)
rates = [estr_curve.zeroRate(t, ql.Continuous).rate() for t in times]
ax.plot(times, rates);
Tenor | Yield | spread | df | zero
1D | 1.93 | -7 | 0.99995 | 1.95675
1W | 1.9306 | -4.76 | 0.99941 | 1.95702
2W | 1.93 | -2.975 | 0.99904 | 1.95627
3W | 1.9309 | -0.96 | 0.99866 | 1.95667
1M | 1.9317 | 1.671 | 0.99818 | 1.95696
2M | 1.9311 | 10.444 | 0.99642 | 1.95476
3M | 1.9314 | 16.11 | 0.99488 | 1.95356
4M | 1.931 | 19.827 | 0.99339 | 1.95172
5M | 1.926 | 22.284 | 0.99177 | 1.94522
6M | 1.922 | 22.4 | 0.99016 | 1.93967
7M | 1.919 | 19.317 | 0.98861 | 1.93515
8M | 1.914 | 19.21 | 0.98709 | 1.92867
9M | 1.91 | 20.293 | 0.98551 | 1.92313
10M | 1.907 | 21.52 | 0.98394 | 1.91859
11M | 1.905 | 22.473 | 0.98232 | 1.91499
1Y | 1.904 | 22.574 | 0.98085 | 1.91254
15M | 1.898 | 21.172 | 0.97618 | 1.90921
18M | 1.903 | 22.45 | 0.97157 | 1.91439
21M | 1.914 | 22.406 | 0.96672 | 1.92421
2Y | 1.929 | 22.401 | 0.96179 | 1.93726
3Y | 2.006 | 21.697 | 0.94108 | 2.01497
4Y | 2.0892 | 21.137 | 0.91907 | 2.09969
5Y | 2.1694 | 20.358 | 0.89631 | 2.18212
6Y | 2.2453 | 19.588 | 0.87288 | 2.26085
7Y | 2.3156 | 18.988 | 0.84892 | 2.33441
8Y | 2.385 | 18.268 | 0.82446 | 2.40788
9Y | 2.452 | 17.398 | 0.79965 | 2.47965
10Y | 2.5131 | 16.636 | 0.77482 | 2.5457
11Y | 2.5693 | 15.974 | 0.7503 | 2.60718
12Y | 2.6211 | 15.361 | 0.72597 | 2.66444
15Y | 2.7422 | 13.787 | 0.65652 | 2.80027
17Y | 2.79424 | 12.767 | 0.61469 | 2.85888
20Y | 2.8402 | 11.782 | 0.55849 | 2.90897
25Y | 2.8653 | 10.559 | 0.48043 | 2.92908
30Y | 2.8689 | 9.69 | 0.41565 | 2.92346
40Y | 2.8617 | 7.643 | 0.31354 | 2.89677
50Y | 2.8254 | 6.35 | 0.24395 | 2.81897