|
From: Michael (D. portal) <mi...@da...> - 2023-09-15 17:50:11
|
On Fri, Sep 15, 2023, 12:57 PM Michael (DataDriven portal) < mi...@da...> wrote: > Hi Ben: > > Thanks a lot. I will use that. I am also wondering if WAL (weighted > average life) for a bond is calculated by QuantLib (I could not find it in > the documentation) which is defined here: > https://www.investopedia.com/terms/w/weightedaveragelife.asp. > > Thanks, > > Michael > > On Thu, Sep 14, 2023 at 4:32 PM Ben Watson <ben...@ma...> > wrote: > >> >> >> This is from the python documentation >> >> >> import QuantLib as ql >> import numpy as np >> import matplotlib.pyplot as plt >> >> X = [1., 2., 3., 4., 5.] >> Y = [0.5, 0.6, 0.7, 0.8, 0.9] >> >> methods = { >> 'Linear Interpolation': ql.LinearInterpolation(X, Y), >> 'LogLinearInterpolation': ql.LogLinearInterpolation(X, Y), >> 'CubicNaturalSpline': ql.CubicNaturalSpline(X, Y), >> 'LogCubicNaturalSpline': ql.LogCubicNaturalSpline(X, Y), >> 'ForwardFlatInterpolation': ql.ForwardFlatInterpolation(X, Y), >> 'BackwardFlatInterpolation': ql.BackwardFlatInterpolation(X, Y), >> 'LogParabolic': ql.LogParabolic(X, Y) >> } >> >> xx = np.linspace(1, 10) >> fig = plt.figure(figsize=(15,4)) >> plt.scatter(X, Y, label='Original Data') >> for name, i in methods.items(): >> yy = [i(x, allowExtrapolation=True) for x in xx] >> plt.plot(xx, yy, label=name); >> plt.legend(); >> >> On Fri, 15 Sept 2023, 4:34 am Michael (DataDriven portal), < >> mi...@da...> wrote: >> >>> Hi All, >>> >>> I am looking for some QuantLib examples on how to calculate bond's I >>> spread that match Bloomberg calculations (as described below). >>> >>> Any help is greatly appreciated! >>> >>> Bloomberg's I-spread is calculated like this: find the 2 swap rate >>> quotes nearest the bond maturity. Linearly interpolate to get the swap rate >>> at the bond's maturity. (Unless you happen to have a swap rate quote >>> exactly at the bond's maturity.) I-spread = interpolated swap rate - the >>> bond's conventional yield >>> >>> Thanks, >>> >>> Michael >>> _______________________________________________ >>> QuantLib-users mailing list >>> Qua...@li... >>> https://lists.sourceforge.net/lists/listinfo/quantlib-users >>> >> |