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))
评论列表
文章目录