Problems using SwaptionVolatilityMatrix class

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems using SwaptionVolatilityMatrix class

Giancarlo Pfeifer-2
Hi, I am trying to use the class
SwaptionVolatilityMatrix, but I seem to have problems
with the way tenors are stored and computed.

I am attaching the C code below (let me know if you
want me to send a zipped file with a MS or Unix
project).

What seems to happen is:
1. When volatilities for swaptions are stored, they
are inserted with their correspondent expiry dates and
tenors.
2. When volatilities are retrieved, the bilinear
interpolation uses for swap tenors, the swap tenors of
the first set of swaptions.
The length used by the linear interpolation is
expressed in years and this value can change by +/- 1
day from year to year. So a 1y swap may last 0.99726
or 1 year.
As result, even if I insert data for a swaption as :
(Date(3, August, 2003), Period(12, Months) ),
trying to retrieve it as : volatility( Date(3, August,
2003), Period(12, Months), 0 ) is not guaranteed to
return the exact value, and it will occasionally
generate an error.

Is this a bug? If so was it already reported?
Altenatively, am I not using the class correctly?

I also have a second question.
When I insert the volatility data into the
SwaptionVolatilityMatrix, what dates should I enter
for the exerciseDates? Should them be the effective
dates of the swaps (ie. the first reset period) or the
first fixing date (that might be one or two days
earlier, depending on currency and market
conventions)?
Judging from the implementation of
"SwaptionVolatilityStructure::volatility(const Date&,
const PEriod&, Rate)" I would propend for the
effective date, is it true?

Thanks
gc
(giancarlo pfeifer)





#include <ql/quantlib.hpp>
#include <iostream.h>

using namespace std;
using namespace QuantLib;

int main(int argc, char* argv[])
{
        Date todaysDate(30, July, 2003 );
        vector<Date> exerciseDates;
        vector<Period> swapTenors;
        QuantLib::Math::Matrix volMatrix( 2, 2 );
        DayCounters::ActualActual
dayCounter(DayCounters::ActualActual::ISDA);


        // Set up swaption volatility matrix with 1y and 2y
expiry and 1y and 2y tenors
        exerciseDates.push_back( Date( 3, August, 2004) );
// The 1y1y swap effective date
        exerciseDates.push_back( Date( 2, August, 2005) );
// The 2y1y swap effective date

        swapTenors.push_back( Period(12, Months) );
        swapTenors.push_back( Period(24, Months) );
       
        volMatrix[0][0] = 0.29;
        volMatrix[0][1] = 0.25;
        volMatrix[1][0] = 0.27;
        volMatrix[1][1] = 0.22;

        Handle<Volatilities::SwaptionVolatilityMatrix>
swaptionVolatilityMatrix(
                new Volatilities::SwaptionVolatilityMatrix(
                                                                todaysDate,
                                                                exerciseDates,
                                                                swapTenors,
                                                                volMatrix,
                                                                dayCounter ) );


        // Compute time to expiry of options
        Time expiryOf1ySwapInYears = dayCounter.yearFraction(
todaysDate, exerciseDates[0],
                                                                                                                todaysDate, exerciseDates[0] );
        Time expiryOf2ySwapInYears = dayCounter.yearFraction(
todaysDate, exerciseDates[1],
                                                                                                                todaysDate, exerciseDates[1] );

        // Compute the swap tenors. Since they start at
different dates, they are slightly different
        // (by +/- 1 day)

        Date expiryDateOf1y1ySwap = exerciseDates[0].plus(
swapTenors[0] );
        Time tenorOf1y1ySwap = dayCounter.yearFraction(
exerciseDates[0], expiryDateOf1y1ySwap,
                                                                                                        exerciseDates[0], expiryDateOf1y1ySwap);

        Date expiryDateOf1y2ySwap = exerciseDates[0].plus(
swapTenors[1] );
        Time tenorOf1y2ySwap = dayCounter.yearFraction(
exerciseDates[0], expiryDateOf1y2ySwap,
                                                                                                        exerciseDates[0], expiryDateOf1y2ySwap);

        Date expiryDateOf2y1ySwap = exerciseDates[1].plus(
swapTenors[0] );
        Time tenorOf2y1ySwap = dayCounter.yearFraction(
exerciseDates[0], expiryDateOf2y1ySwap,
                                                                                                        exerciseDates[0], expiryDateOf2y1ySwap);

        Date expiryDateOf2y2ySwap = exerciseDates[1].plus(
swapTenors[1] );
        Time tenorOf2y2ySwap = dayCounter.yearFraction(
exerciseDates[1], expiryDateOf2y2ySwap,
                                                                                                        exerciseDates[1], expiryDateOf2y2ySwap);

        // Display the matrix. To make sure I retrieve some
values, I have to use lengths in years
        // as QuantLib recons they are
        std::cout << "Swaption Volatility Matrix initialised"
<< endl;
        std::cout << "\t\tTenors" << endl;
        std::cout << "\t\t" <<
swaptionVolatilityMatrix->lengths()[0].length() <<
"\t\t" <<
swaptionVolatilityMatrix->lengths()[1].length() <<
endl;
        std::cout <<
swaptionVolatilityMatrix->exerciseDates()[0] << "\t";
                // display volatility for 1y1y
                std::cout << swaptionVolatilityMatrix->volatility(
expiryOf1ySwapInYears ,
                                                                                                                   tenorOf1y1ySwap,
                                                                                                                   0 ) << "\t\t";
                // display volatility for 1y2y
                std::cout << swaptionVolatilityMatrix->volatility(
expiryOf1ySwapInYears ,
                                                                                                                   tenorOf1y2ySwap,
                                                                                                                   0 ) << endl;


        std::cout <<
swaptionVolatilityMatrix->exerciseDates()[1] << "\t" ;
                // display volatility for 2y1y
                std::cout << swaptionVolatilityMatrix->volatility(
expiryOf2ySwapInYears ,
                                                                                                                   tenorOf1y1ySwap,
                                                                                                                   0 ) << "\t\t";

                // display volatility for 2y2y
                std::cout << swaptionVolatilityMatrix->volatility(
expiryOf2ySwapInYears ,
                                                                                                                   tenorOf1y2ySwap,
                                                                                                                   0 ) << endl;

        // Good: the volatilities have been extracted from
the matrix, but I had to fake the
        // tenor of the 2y1y and 2y2y to get the exact
figures

        // Now let's use the other method to extract
volatilities, and the program will
        // throw an exception because a tenor of 24 months is
greater than what QuantLib thought
        // is the length of the swap.

                std::cout << endl;
        std::cout << "\t\tTenors" << endl;
        std::cout << "\t\t" <<
swaptionVolatilityMatrix->lengths()[0].length() <<
"\t\t" <<
swaptionVolatilityMatrix->lengths()[1].length() <<
endl;
        std::cout <<
swaptionVolatilityMatrix->exerciseDates()[0] << "\t";
                // display volatility for 1y1y
                std::cout << swaptionVolatilityMatrix->volatility(
Date( 3, August, 2004),
                                                                                                                   Period( 12, Months ),
                                                                                                                   0 ) << "\t\t";
                // display volatility for 1y2y
                std::cout << swaptionVolatilityMatrix->volatility(
Date( 3, August, 2004),
                                                                                                                   Period( 24, Months),
                                                                                                                   0 ) << endl;


        std::cout <<
swaptionVolatilityMatrix->exerciseDates()[1] << "\t" ;
                // display volatility for 2y1y
                std::cout << swaptionVolatilityMatrix->volatility(
Date( 2, August, 2005),
                                                                                                                   Period( 12, Months),
                                                                                                                   0 ) << "\t\t";
                // display volatility for 2y2y
                std::cout << swaptionVolatilityMatrix->volatility(
Date( 2, August, 2005),
                                                                                                                   Period( 24 , Months),
                                                                                                                   0 ) << endl;


        return 0;
}







__________________________________________________
Yahoo! Plus
For a better Internet experience
http://www.yahoo.co.uk/btoffer


Reply | Threaded
Open this post in threaded view
|

Re: Problems using SwaptionVolatilityMatrix class

Luigi Ballabio-2
At 10:53 AM 7/30/03 +0100, Giancarlo Pfeifer wrote:
>Hi, I am trying to use the class
>SwaptionVolatilityMatrix, but I seem to have problems
>with the way tenors are stored and computed.

Giancarlo,
         thanks for reporting the problem---I fixed it in cvs, and now the
matrix will report the correct volatilities when input dates and periods
are passed. Look out for next release in September.

Bye,
         Luigi