cmq_curve.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyktrader2 作者: harveywwu 项目源码 文件源码
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 ...')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号