To be honestly I have no idea. However, the teacher told me I have to do something in the function I have mentioned. I assume that when it generate numbers it stores them in a vector this.path. So maybe I could write small syntax that will get the largest number in that vector and if there is a number that is over 250 then it could stop and return zero,meaning that the option costs nothing (zero). I hope that somehow helps, I am not very good ad advanced c++.
I think your friend might have been suggesting to iterate through the vector and search until you find the number 250. So something like:
1 2 3 4
typedef vector<double>::iterator dviter;
for (dviter iter = thisPath.begin(); iter != thisPath.end(); ++iter)
{ /* Search for the number 250 */ }
The above method is all well and good, but since this is a monte carlo simulation you don't want to be incurring extra overhead just because you need to search for one number. So what I would suggest it to make the generatePath method return a boolean. It will return true if 250 was not appended to the path and it will return false if 250 is appended to the path.
So this means before you add each value to the vector, you check if it is 250. If it is you return false. The default return value of the function should be true
Then in your function: double BarrierOption::arithmeticBarrierPut(int)
Smac89:
Thank you very much for reply.So if I did use boolean syntax, how exactly would my function look like. I mean how would my Arithmetic BarrierPut function would look like exactly? Again thank you very much.
That function will look exactly the same as before, but instead of just having the line: generatePath();, you will replace this with the if statement I wrote out in my last comment