I cannot reproduce your problem. This is my output
Last price of underlying = 164.25
Price of arithmetic Asian Put = 0
Price of geometric Asian Put = 0
calling functions via operator()
Price of arithmetic Asian Put = 0
Price of geometric Asian Put = 0
mean of myVec is 201.218
stddev of myVec is 28.1681
Ok I have made a little addition,and now it works. except that I am struggling
with one thing. When my barrier is hit, for example if I set it to 250, then it returns 0 and if it doesnt hit then it return option price(so far so good). So I am setting my maturity to .5 (half a year) which is 126 days in finance roughly. So what I need for my code to do, is to get this barrier up only in the last 64 days.So from day 0 to 64 it should not have the barrier, but from day 64 to 126 my barrier should start working. Basically, I should not have the barrier in the first half and have it up in the second. I was thinking something like max.element.path (beging()+64, end ()), But I am not sure. I will provide the codes below, but I think the BarrierOption::arithmeticBarrierPut(int nReps) is where the changes have to be made. This is the input for your info:
126,200,195,0.2,0.06.0.5,300. (The last number 300, is the most important as it could be adjust to 350 or 250 and you will see the result)
using std::vector;
using std::cout;
using std::cin;
int main(){
// set the seed
srand( time(NULL) );
int nInt_;
double strike_,spot_,vol_,r_,expiry_,barrier_;
cout << "Enter the number of iterations: ";
cin >> nInt_;
cout << "Enter the stike price: ";
cin >> strike_;
cout << "Enter the spot price: ";
cin >> spot_;
cout << "Enter the volatility rate: ";
cin >> vol_;
cout << "Enter the interest rate: ";
cin >> r_;
cout << "Enter the expiration time: ";
cin >> expiry_;
cout << "Enter the barrier level: ";
cin >> barrier_;
//create a new instance of class
BarrierOption myBarrier(nInt_,strike_,spot_,vol_,r_,expiry_,barrier_);
/*(126, 200, 195, 0.2, 0.06, 0.5,300)*/
//get last price of underlying
cout << "Last price of underlying = " << myBarrier.thisPath.back() << "\n";
//run Monte Carlo to obtain theoretical price of arithmetic asian call
cout << "Price of arithmetic Asian Put = " << myBarrier.arithmeticBarrierPut(10000) << "\n";
cout << "Price of geometric Asian Put = " << myBarrier.geometricBarrierPut(10000) << "\n";
//call Monte Carlo via overloaded () operator
cout << "calling functions via operator() \n";
cout << "Price of arithmetic Asian Put = " << myBarrier('A', 'P', 10000) << "\n";
cout << "Price of geometric Asian Put = " << myBarrier('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++){
myBarrier.generatePath();
myVec2.push_back(myBarrier.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();
system ("Pause");
return 0;
}
In Barrier.option.cpp in //method definition
double BarrierOption::arithmeticBarrierPut(int nReps)
it should return:
return rollingSum / double(nReps); I missed the "double"