2021年4月11日星期日

How to Bootstrapping with SciPy properly?

I'm trying to bootstrapping in Python each Term of a Mexican Swap, I calculated it before on Excel Goal Seek and got this results:

Results on Goal Seek

Basically I have all the fixed rates for the 3 periods but I just have the floating rate for period 1, I need to find floating rate for period 2 and 3, but in this case we can assume that floating rate on period 2 = floating rate on period 3

The other assumption to solve this equation is that the SWAP NPV = 0, so for this case Fixed NPV = Floating NPV The Fixed NPV its calculated and is 1.0001, the Floating NPV is calculated based on Floating Rate

Basically Floating NPV = ∑((NotionalFloating Rate28/360)/(1+Fixed Rate*28/360)^Period

But for period 1 using floating_rate 0.04288 and x for period 2 and 3

I can't solve that using SciPy, its giving error, solver doesn't keep floating rating for period 1 and I don't know how to attribute floating rate of period 2 and 3 be the same, Can someone help me?

notional = 100  convention = 28/360  df3 = [[]]  df3 = pd.DataFrame({'period': [1, 2, 3],                       'fixed_rate': [0.04315, 0.04315, 0.04315],                       'floating_rate': [0.04288, 0, 0]})  df3['fixed_cashflow'] = notional * df3['fixed_rate'] * convention  df3['fixed_npv'] = df3['fixed_cashflow'] / (1 + df3['fixed_rate'] * convention) ** df3['period']  x = df3['floating_rate']  fixed_npv = np.array(df3['fixed_npv'])  fixed_rate = np.array(df3['fixed_rate'])  period = np.array(df3['period'])    res = opt.minimize(fun=calculo,                     x0=np.array(x),                     args=(fixed_npv, fixed_rate, period, notional, convention),                     method="BFGS")  return res    def calculo(x0, fixed_npv, fixed_rate, period, notional, convention):   return sum((notional * x0 * convention) / (1 + fixed_rate * convention) ** period) - sum(fixed_npv)  
https://stackoverflow.com/questions/67052546/how-to-bootstrapping-with-scipy-properly April 12, 2021 at 12:07PM

没有评论:

发表评论