cmq_cashflow.py 文件源码

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

项目:pyktrader2 作者: harveywwu 项目源码 文件源码
def value(self, proj, disc, spread=0.0):
            """
            the coupons of the leg must be unpaid yet as of today (assuming today is the valuation date):                    
            |-----|-----------------------|---|
            F0   A0s                     A0e  P0  
                                    |-----|-----------------------|---|
                                    F1   A1s                     A1e  P1   
                                                            |-----|-----------------------|---|
                                                            F2   A2s                     A2e  P2         
            It can be that F1 < today < P0, there would be 2 unpaid but fixed coupons, however this is very rare.
            """
            if isinstance(proj, (float, int)): # proj is a single float, e.g. a single fixed rate
                rates = proj             
            elif np.iterable(proj): # proj is a vector of floats, e.g. predefined fixed rates           
                assert len(proj) == len(self.cp)
                rates = proj                      
            elif callable(proj): # proj is a curve or a function, a floating leg
                rates = np.array([p.index.forward(proj) for p in self.cp])
            else: 
                raise BaseException('invalid rate/projection ...') 

            rates = rates * self.factory.rate_leverage + self.factory.rate_spread
            return self.np_effnotl.dot((rates + spread) * disc(self.np_paydates))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号