Monte Carlo simulation for look back call option with continuous barrier

I NEED TO APPLY MONTE CARLO SIMULATION MODEL TO LOOK BACK CALL OPTION WITH CONTINUOUS BARRIER ON C++. THERE ARE ALL HEADER AND MAIN CPP FILES BELOW. THIS IS JUST AND EGZAMPLE FOR EUROPEN OPTION. I NEED TO CHANGE IT TO LOOK BACK CALL OPTION WITH CONTINUOUS BARRIER.

I HAVE TO WRITE a C++ program that will run a Monte Carlo simulation to approximate the theoretical price of the
up-and-out lookback call option with a continuous barrier.

These codes should be ready to price the option for any values of its characteristics, but find the theoretical
price for the following values:
ˆ . price of the underyling at the moment of option pricing: S0 = 195,
ˆ . strike price K = 200,
ˆ . annualized volatility rate  = 0.2
ˆ . annualized risk-free rate r = 0.06
ˆ . time to maturity t = 0.5

PLEASE HELP!

HEADER FILES

AsianOption.h

#include<vector>


class AsianOption{
public:

//constructor
AsianOption(
int nInt_,
double strike_,
double spot_,
double vol_,
double r_,
double expiry_
);

//destructor
~AsianOption(){};

//methods
void generatePath();
double getArithmeticMean();
double getGeometricMean();
void printPath();
double arithmeticAsianCall(int nReps);
double arithmeticAsianPut(int nReps);
double geometricAsianCall(int nReps);
double geometricAsianPut(int nReps);

//overloaded operator ()
double operator()(char char1, char char2, int nReps);

//members
std::vector<double> thisPath;
int nInt;
double strike;
double spot;
double vol;
double r;
double expiry;

};

functions.h

//
//
//

//functions prototypes
double mean (std::vector<double> thisVec);
double stdDev (std::vector<double> thisVec);

Random1.h

//
//
// Random1.h
//
//


#ifndef RANDOM1_H
#define RANDOM1_H

//declarations of functions
//(prototypes)
double GetOneGaussianBySummation();
double GetOneGaussianByBoxMuller();

#endif



MAIN FILES

AsianOptions.cpp

#include"AsianOption.h"
#include<cmath>
#include<iostream>
#include"Random1.h"


//definition of constructor
AsianOption::AsianOption(
int nInt_,
double strike_,
double spot_,
double vol_,
double r_,
double expiry_){
nInt = nInt_;
strike = strike_;
spot = spot_;
vol = vol_;
r = r_;
expiry = expiry_;
generatePath();
}

//method definition
void AsianOption::generatePath(){
double thisDrift = (r * expiry - 0.5 * vol * vol * expiry) / double(nInt);
double cumShocks = 0;
thisPath.clear();

for(int i = 0; i < nInt; i++){
cumShocks += (thisDrift + vol * sqrt(expiry / double(nInt)) * GetOneGaussianByBoxMuller());
thisPath.push_back(spot * exp(cumShocks));
}
}

//method definition
double AsianOption::getArithmeticMean(){

double runningSum = 0.0;

for(int i = 0; i < nInt; i++){
runningSum += thisPath[i];
}

return runningSum/double(nInt);
}


//method definition
double AsianOption::getGeometricMean(){

double runningSum = 0.0;

for(int i = 0; i < nInt ; i++){
runningSum += log(thisPath[i]);
}

return exp(runningSum/double(nInt));
}

//method definition
void AsianOption::printPath(){

for(int i = 0; i < nInt; i++){

std::cout << thisPath[i] << "\n";

}

}

//method definition
double AsianOption::arithmeticAsianCall(int nReps){

double rollingSum = 0.0;
double thisMean = 0.0;

for(int i = 0; i < nReps; i++){
generatePath();
thisMean=getArithmeticMean();
rollingSum += (thisMean > strike)? (thisMean-strike) : 0;
}

return rollingSum/double(nReps);

}

//method definition
double AsianOption::arithmeticAsianPut(int nReps){

double rollingSum = 0.0;
double thisMean = 0.0;

for(int i = 0; i < nReps; i++){
generatePath();
thisMean=getArithmeticMean();
rollingSum += (thisMean < strike)? (strike - thisMean) : 0;
}

return rollingSum/double(nReps);

}

//method definition
double AsianOption::geometricAsianCall(int nReps){

double rollingSum = 0.0;
double thisMean = 0.0;

for(int i = 0; i < nReps; i++){
generatePath();
thisMean=getGeometricMean();
rollingSum += (thisMean > strike)? (thisMean-strike) : 0;
}

return rollingSum/double(nReps);

}

//method definition
double AsianOption::geometricAsianPut(int nReps){

double rollingSum = 0.0;
double thisMean = 0.0;

for(int i = 0; i < nReps; i++){
generatePath();
thisMean=getGeometricMean();
rollingSum += (thisMean < strike)? (strike - thisMean) : 0;
}

return rollingSum/double(nReps);

}

//overloaded operator ();
double AsianOption::operator()(char char1, char char2, int nReps){
if ((char1 == 'A') & (char2 =='C')) return arithmeticAsianCall(nReps);
else if ((char1 == 'A') & (char2 =='P')) return arithmeticAsianPut(nReps);
else if ((char1 == 'G') & (char2 =='C')) return geometricAsianCall(nReps);
else if ((char1 == 'G') & (char2 =='P')) return geometricAsianPut(nReps);
else return -99;
}


functions.cpp

#include<cmath>
#include<iostream>
#include<vector>

// general function for mean
double mean (std::vector<double> thisVec) {

double runningSum = 0.0;
int thisSize = thisVec.size();

for(int i = 0; i < thisSize; i++){
runningSum += thisVec[i];
}

return runningSum/double(thisSize);
}


// general function for standard deviation
double stdDev (std::vector<double> thisVec) {

double runningSum = 0.0;
int thisSize = thisVec.size();

for ( int i = 0; i < thisSize; i++ ){
runningSum += pow((thisVec[i]- mean(thisVec) ), 2);
}

return sqrt(runningSum/(thisSize - 1));
}


Random1.cpp

//
//
//
// Random1.cpp
//
//

#include "Random1.h"
#include <cstdlib>
#include <cmath>

// the basic math functions should be in namespace std but aren't in VCPP6
#if !defined(_MSC_VER)
using namespace std;
#endif


//definitions of functions
double GetOneGaussianBySummation()
{
double result=0;

for (unsigned long j=0; j < 12; j++)
result += rand()/static_cast<double>(RAND_MAX);

result -= 6.0;

return result;

}


double GetOneGaussianByBoxMuller()
{
double result;

double x;
double y;

double sizeSquared;
do
{
x = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
y = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
sizeSquared = x*x + y*y;
}
while
( sizeSquared >= 1.0);

result = x*sqrt(-2*log(sizeSquared)/sizeSquared);

return result;

}

Problem01.cpp

#include<iostream>
#include<vector>
#include"asianOption.h"
#include<ctime>
#include<cstdlib>
#include"functions.h"

using std::vector;
using std::cout;
using std::cin;

int main(){

// set the seed
srand( time(NULL) );

//create a new instance of class
AsianOption myAsian(252, 96, 95, 0.2, 0.0, 1);

// Iterate over all the elements.
// myAsian.printPath();

//get arithmetic means
cout << "Arithmetic mean price = " << myAsian.getArithmeticMean() <<"\n";
cout << "Geometric mean price = " << myAsian.getGeometricMean() <<"\n";

//get last price of underlying
cout << "Last price of underlying = " << myAsian.thisPath.back() << "\n";

//run Monte Carlo to obtain theoretical price of arithmetic asian call
cout << "Price of arithmetic Asian Call = " << myAsian.arithmeticAsianCall(10000) << "\n";
cout << "Price of arithmetic Asian Put = " << myAsian.arithmeticAsianPut(10000) << "\n";
cout << "Price of geometric Asian Call = " << myAsian.geometricAsianCall(10000) << "\n";
cout << "Price of geometric Asian Put = " << myAsian.geometricAsianPut(10000) << "\n";


//call Monte Carlo via overloaded () operator
cout << "calling functions via operator() \n";
cout << "Price of arithmetic Asian Call = " << myAsian('A', 'C', 10000) << "\n";
cout << "Price of arithmetic Asian Put = " << myAsian('A', 'P', 10000) << "\n";
cout << "Price of geometric Asian Call = " << myAsian('G', 'C', 10000) << "\n";
cout << "Price of geometric Asian Put = " << myAsian('G', 'P', 10000) << "\n";

//check whether data generating process runs correctly
//(is the expected price and volatility of underlying close to option parameters?)
vector<double> myVec2;
for(int i = 0; i < 1000; i++){
myAsian.generatePath();
myVec2.push_back(myAsian.thisPath.back());
}

cout << "mean of myVec is " << mean(myVec2) << "\n";
cout << "stddev of myVec is " << stdDev(myVec2) << "\n";



//cout << "\nPress Enter to continue...";
//cin.get();
return 0;
}

Topic archived. No new replies allowed.