Quantcast

Variance Swap test

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Variance Swap test

ziegele
This post was updated on .
I was looking at the VarianceSwap example in test-suite. In Visual Studio 2015, I created a class called VarianceSwapTest, and call it from the main() function.

I notice that the testing functions testReplicatingVarianceSwap() and testMCVarianceSwap() are both called by the other function static boost::unit_test_framework::test_suite* suite().



Since the return type is test_suite*, I'm wondering how to fill in the main() function to call it, and what kind of results shall I expect, from Visual Studio 2015?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Variance Swap test

ziegele
This post was updated on .
BTW, if I "directly call" the suite() function in main() this way:



I got 2 errors while compiling:



This is how to link boost library and quantlib for this project:





Could anyone please advise how to fix, perhaps add some modification on the Linker part in Visual Studio?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Variance Swap test

Luigi Ballabio
The main() function using the suite is provided by the Boost unit-test framework; you'll need to provide an init_unit_test_suite function, as done in the quantlibtestsuite.cpp file.

As for the linking errors you were getting: flatRate is defined in test-suite/utilities.cpp, and you need to link it together with your other files.

Luigi


On Tue, Feb 7, 2017 at 5:35 PM ziegele <[hidden email]> wrote:
BTW, if I "directly call" the suite() function in main() this way:

<http://quantlib.10058.n7.nabble.com/file/n18060/main.jpg>

I got 2 errors while compiling:

<http://quantlib.10058.n7.nabble.com/file/n18060/error.jpg>

This is how to link boost library and quantlib for this project:

<http://quantlib.10058.n7.nabble.com/file/n18060/include.jpg>

<http://quantlib.10058.n7.nabble.com/file/n18060/library.jpg>

Could anyone please advise how to fix?





--
View this message in context: http://quantlib.10058.n7.nabble.com/Variance-Swap-test-tp18059p18060.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Variance Swap test

ziegele
Thanks Luigi!

I bypassed the problem by replacing flatRate() as defined in utilities.hpp with the FlatForward class. As shown in the screenshot below, the calculation matches with expected result very well. I also included the cpp codes in attachment (flat.cpp).



Naturally, the next step is to replace flat interest rate and dividend with a term structure. So I tried the InterpolatedZeroCurve class. In order to make sure that I get this class setup correctly, I defined a flat interest rate terms structure, to compare with the FlatForward results. The code is also attached (termStructure.cpp).

Unfortunately, the calculation result didn't match with expectation:



My guess is that, building flat forward curve from a flat interest rate term structure should use some other functions. How should I correctly interpolate the term structure, so that I can:

1) match with the constant div and r at the first step;
2) introduce non-flat interest rate and dividend term structure?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Variance Swap test

Luigi Ballabio
The difference might be that in the flat forward case your curve starts at today's date, while in the interpolated case it starts at February 24th and the discount factors used in the calculation will change accordingly.  You should try using today as the first date in the vector instead.

Luigi


On Wed, Mar 1, 2017 at 4:04 AM ziegele <[hidden email]> wrote:
Thanks Luigi!

I bypassed the problem by replacing flatRate() as defined in utilities.hpp
with the FlatForward class. As shown in the screenshot below, the
calculation matches with expected result very well. I also included the cpp
codes in attachment ( flat.cpp
<http://quantlib.10058.n7.nabble.com/file/n18127/flat.cpp>  ).

<http://quantlib.10058.n7.nabble.com/file/n18127/match.jpg>

Naturally, the next step is to replace flat interest rate and dividend with
a term structure. So I tried the InterpolatedZeroCurve class. In order to
make sure that I get this class setup correctly, I defined a flat interest
rate terms structure, to compare with the FlatForward results. The code is
also attached ( termStructure.cpp
<http://quantlib.10058.n7.nabble.com/file/n18127/termStructure.cpp>  ).

Unfortunately, the calculation result didn't match with expectation:

<http://quantlib.10058.n7.nabble.com/file/n18127/mismatch.jpg>

My guess is that, building flat forward curve from a flat interest rate term
structure should use some other functions. How should I correctly
interpolate the term structure, so that I can:

1) match with the constant div and r at the first step;
2) introduce non-flat interest rate and dividend term structure?

Thanks!



--
View this message in context: http://quantlib.10058.n7.nabble.com/Variance-Swap-test-tp18059p18127.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Loading...