Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

VarianceSwap.cpp

Go to the documentation of this file.
00001 #include "./VarianceSwap.h"
00002 
00003 VarianceSwap::VarianceSwap(OptionStrategy* options, Real maturity, Real forwardprice)
00004         :       _options(options),
00005                 _maturity(maturity),
00006                 _forward(forwardprice)
00007 {
00008 }
00009 
00010 VarianceSwap::~VarianceSwap(void)
00011 {
00012 }
00013 
00014 Real VarianceSwap::getPrice() {
00015         Real result=0;
00016         //Create vectors to store indexes of options to use
00017         valarray<Integer> putsToUse;
00018         valarray<Integer> callsToUse;
00019         putsToUse.resize(_options->returnNbOptions());
00020         callsToUse.resize(_options->returnNbOptions());
00021         for (Natural i=0;i<putsToUse.size();i++) {
00022                 putsToUse[i]=-1;
00023                 callsToUse[i]=-1;
00024         }
00025 
00026         Integer countCalls=0;
00027         Integer countPuts=0;
00028         BlackScholes* bs;
00029         BlackScholes* bs2;
00030         Real Strike1;
00031         Real Strike2;
00032 
00033         //Search _options for options to use
00034         for (Integer i=0;i<(Integer)_options->returnNbOptions();i++) {
00035                 bs=_options->returnOption(i);
00036                 if (bs->isCall() && (bs->getStrike()>=_forward)) {
00037                         callsToUse[countCalls]=i;
00038                         countCalls++;
00039                 }
00040                 if (!(bs->isCall()) && (bs->getStrike()<=_forward)) {
00041                         putsToUse[countPuts]=i;
00042                         countPuts++;
00043                 }
00044         }
00045 
00046         //Compute the formula
00047         for (Integer i=0;i<countPuts-1;i++) {
00048                 bs2=_options->returnOption(putsToUse[i+1]);
00049                 bs=_options->returnOption(putsToUse[i]);
00050                 Strike1=bs->getStrike();
00051                 Strike2=bs2->getStrike();
00052                 result+=(Strike2-Strike1)*1/(Strike1*Strike1)*bs->getPrice();
00053         }
00054         if (countCalls>0 && countPuts>0) {
00055                 bs=_options->returnOption(putsToUse[countPuts-1]);
00056                 bs2=_options->returnOption(callsToUse[0]);
00057                 Strike1=bs->getStrike();
00058                 Strike2=bs2->getStrike();
00059                 result+=(Strike2-Strike1)*1/(Strike1*Strike1)*bs->getPrice();
00060         }
00061         for (Integer i=0;i<countCalls-1;i++) {
00062                 bs2=_options->returnOption(callsToUse[i+1]);
00063                 bs=_options->returnOption(callsToUse[i]);
00064                 Strike1=bs->getStrike();
00065                 Strike2=bs2->getStrike();
00066                 result+=(Strike2-Strike1)*1/(Strike1*Strike1)*bs->getPrice();
00067         }
00068 
00069         return 2./_maturity*result;
00070 }
00071 
00072 Real VarianceSwap::getRho(Real shiftCurve) {
00073         double result=getPrice();
00074         _options->changeRate(shiftCurve);
00075         result=getPrice()-result;
00076         return result;
00077 }
00078 
00079 Real VarianceSwap::getVega(Real shiftVol) {
00080         double result=getPrice();
00081         _options->changeVol(shiftVol);
00082         result=getPrice()-result;
00083         return result;
00084 }
00085 
00086 Real VarianceSwap::getTheta(Real shiftMat) {
00087         double result=getPrice();
00088         _options->changeMaturity(shiftMat);
00089         result=getPrice()-result;
00090         return result;
00091 }

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:37 2005 for terreneuve by doxygen 1.3.6