def from_array(cls, tenors, forwards, t0=None, interp_mode=InterpMode.PiecewiseConst):
"""Create a Curve object: tenors (floats), fwds (floats), interp_mode"""
if t0 is None:
t0 = tenors[0]
assert len(tenors) == len(forwards)
if interp_mode == cls.InterpMode.PiecewiseConst:
interpfwd = interp1d(tenors, forwards, kind='zero', bounds_error=False, fill_value='extrapolate')
return cls(t0, lambda t: interpfwd(t))
elif interp_mode == cls.InterpMode.Linear:
interpfwd = interp1d(tenors, forwards, kind='linear', bounds_error=False, fill_value='extrapolate')
return cls(t0, lambda t: interpfwd(t))
elif interp_mode == cls.InterpMode.LinearLog:
linzero = interp1d(tenors, np.log(forwards), kind='linear', bounds_error=False, fill_value='extrapolate')
return cls(t0, lambda t: np.exp(linzero(t)))
else:
raise BaseException('invalid curve interpolation mode ...')
评论列表
文章目录