float american_asian_call_option(int k, int i, float current_stock_price) {
if (k == no_of_divisions)
return max(0.0, (current_stock_price - strike_price));
elsereturn max((current_stock_price - strike_price),
(uptick_prob*american_call_option(k+1, i+1, current_stock_price*up_factor) +
notick_prob*american_call_option(k+1, i, current_stock_price) +
downtick_prob*american_call_option(k+1, i-1, current_stock_price/up_factor))/R);
}
I need to change it so that the current_stock_price is instead an average of the stock prices. I am not sure how to implement this though. I have tried a few ways but nothing seems to be working. The average is simple in concept, just keep adding up the current stock prices as you run through the recursion and divide by K+1 to get the average. I am not sure how to get it so that the I have the sum of the current prices adding while the recursion runs.
the current_average_stock_price is dynamically calculated though. Depending on the inputs it could be when k=3 or when k = 7 or when k =no_of_division. It is calculated by adding up the current_stock_price after each iteration and dividing by however many iterations have come before so I can't remove the current_stock_price and I don't think I can be calculating the current_average_price in that way...
Let me know if I am thinking about this backwards or completely missing what is actually happening in your code above.
I am pretty sure it should look something along the lines of the following:
1 2 3 4 5 6 7 8
float american_asian_call_option(int k, int i, float ¤t_stock_price, float ¤t_avgerage_stock_price) {
if (k == no_of_divisions)
return max(0.0, (current_average_stock_price - strike_price));
elsereturn max((current_average_stock_price - strike_price),
(uptick_prob*american_asian_call_option(k+1, i+1, current_stock_price*up_factor, [not sure what to put here]) +
notick_prob*american_asian_call_option(k+1, i, current_stock_price, [not sure what to put here]) +
downtick_prob*american_asian_call_option(k+1, i-1, current_stock_price/up_factor, [not sure what to put here]))/R);
I have indicated where I am still confused in the code. I need to be summing the current stock price and dividing by k+1 but I don't know how to implement that.
Seems like your problem is a logic one, in the math itself. The issue is that this is mostly just functions and since I have no clue what each function does, I can't tell if they all work properly or not to determine where your math problem lies.
I understand that you are trying to sum the current stock price by dividing by k+1, but what do you need to divide by k+1 to get that? We will need to know everything to see the math issue, probably even the functions unless you want to test them out yourself by running a quick main and seeing how they change when you put in different numbers to see if the output is what you expect.
Sorry, wish I could help you out more but without more info, I really can't.
The reason it is mostly functions is because it is using recursion. The functions that you are seeing is all there is too it. k, i, current_stock_price, current_avg_stock_price, strike price, uptick_prob, notick_prob, downtick_prob are just numbers that are defined in main. The only function in the code I've presented is the american_asian_call_option and that is all there for you. The math isn't incorrect as I have tested the function without using the average stock price part and it works fine.