# Rebonatos's formula in C++

I'm trying to code in C++ Rebonato's formula for swaption volatilities

$$v_{\alpha,\beta}^2=\frac{1}{T_\alpha} \sum_{i,j=\alpha+1}^{\beta} \frac{w_i(0)w_j(0)F_i(0)F_j(0)}{S_{\alpha\beta}^2(0)}\rho_{i,j}\int_{0}^{T_\alpha}\sigma_i(t)\sigma_j(t)dt$$

where the forward rate volatility is a piecewise-constant function $$\sigma_i(t)=\sigma_{i,\beta(t)}=\phi_i\psi_{i-(\beta(t)-1)}$$. This means that the integral term "reduces to a summation of products of volatility parameters", Brigo&Mercurio pag 316.

Assume the swap's floating leg is a 1-Year Libor rate, resetting every 360 days,while the fixed leg is set to make the IRS fair, i.e. $$S_{\alpha\beta}$$(t), also resetting every 360 days.

I've come up with the following code, where vol_m[i][h+1] represents the quantity $$\sigma_{i,h+1}$$ and corr_m[i][j] is the correlation matrix $$\rho_{ij}$$.

    Real sum=0;
Real sum1=0;
Real time_unit = 360;
for (int i=0;i<=beta-1;i++){
for (int j=0;j<=beta-1;j++){
for (int h=0;h<=alpha;h++){
sum1=sum1+time_unit*vol_m[i][h+1]*vol_m[j][h+1];
}
sum=sum+weight[i]*weight[j]*r[i]*r[j]*(corr_m[i][j]))/pow(swaprate,2)*sum1;
}
}


However, this code is not working properly. Can anyone help me improve it, please?

EDIT: The Real keyword you see in the code is just a QuantLib typedef for double

EDIT: In this article Brigo&Morini present how Rebonato's formula reads using the same piecewise-constant volality $$\sigma_i(t)=\sigma_{i,\beta(t)}$$ as above,

$$\int_{0}^{T_{\alpha}} \sigma_i(t)\sigma_j(t) dt = \sum_{h=0}^{\alpha}(T_h-T_{h-1})\sigma_{i,h+1}\sigma_{j,h+1}$$

• Can you explain more? I've hard time aligning your code with the formula. Mar 19, 2021 at 13:19
• @BobJansen sure, I wanna code a function that given weights, forward rate, swap rate, correlation and volatility computes the ATM swaption volatility, via Rebonato's formula above. The point is I really don't understand how to translate such formula in C++ terms and what I've written so far doesn't seem to be working. Mar 19, 2021 at 15:00
• Shouldn't you divide time_unit (which seems to be number of days) by 365?
– ir7
Mar 19, 2021 at 16:34
• @ir7 I think it depends on your day couting assumption. This code is actually part of a bigger program written using QuantLib, throught which I've always used the convetion Actual360. For this reason I felt it was natural to use 360 as time_unit Mar 20, 2021 at 20:35