1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct probabilities {
float uptick_prob;
float notick_prob;
float downtick_prob;
};
float max(float a, float b) {
return (b < a )? a:b;
}
float american_asian_call_option(int k, int i, float current_stock_price, float current_avg_stock_price, float up_factor, float R, probabilities probs, int no_of_divisions, float strike_price) {
if (k == no_of_divisions)
return max(0.0, (((current_avg_stock_price)/(k+1)) - strike_price));
else
return max((((current_avg_stock_price)/(k+1)) - strike_price),
(probs.uptick_prob*american_asian_call_option(k+1,i+1,current_stock_price*up_factor,(((current_avg_stock_price)+(current_stock_price*up_factor))), up_factor, R, probs, no_of_divisions, strike_price) +
probs.notick_prob*american_asian_call_option(k+1,i,current_stock_price,(current_avg_stock_price+(current_stock_price)), up_factor, R, probs, no_of_divisions, strike_price) +
probs.downtick_prob*american_asian_call_option(k+1,i-1,current_stock_price/up_factor,(current_avg_stock_price + (current_stock_price/up_factor)), up_factor, R, probs, no_of_divisions, strike_price))/R);
}
float american_asian_put_option(int k, int i, float current_stock_price, float current_avg_stock_price, float up_factor, float R, probabilities probs, int no_of_divisions, float strike_price) {
if (k == no_of_divisions)
return max(0.0, strike_price - ((current_avg_stock_price)/(k+1)));
else
return max((strike_price - ((current_avg_stock_price)/(k+1))),
(probs.uptick_prob*american_asian_put_option(k+1,i+1,current_stock_price*up_factor,((current_avg_stock_price)+(current_stock_price*up_factor)), up_factor, R, probs, no_of_divisions, strike_price)+
probs.notick_prob*american_asian_put_option(k+1,i,current_stock_price,(current_avg_stock_price+(current_stock_price)), up_factor, R, probs, no_of_divisions, strike_price) +
probs.downtick_prob*american_asian_put_option(k+1,i-1,current_stock_price/up_factor,(current_avg_stock_price + (current_stock_price/up_factor)), up_factor, R, probs, no_of_divisions, strike_price))/R);
}
int main (int argc, char* argv[])
{
int no_of_divisions;
float expiration_time = .5;
float risk_free_rate = .08;
float volatility = .3;
float initial_stock_price= 60;
float strike_price = 50;
probabilities probs;
cin >> no_of_divisions;
float up_factor = exp(volatility*sqrt(2*(expiration_time/((float) no_of_divisions))));
float R = exp(risk_free_rate*expiration_time/((float) no_of_divisions));
probs.uptick_prob = pow(((sqrt(R) - (1/sqrt(up_factor)))/(sqrt(up_factor)-(1/sqrt(up_factor)))),2);
probs.downtick_prob = pow(((sqrt(up_factor)-sqrt(R))/(sqrt(up_factor)-(1/sqrt(up_factor)))),2);
probs.notick_prob = 1-probs.uptick_prob-probs.downtick_prob;
cout << "Recursive Trinomial American Asian Option Pricing" << endl;
cout << "Expiration Time (Years) = " << expiration_time << endl;
cout << "Number of Divisions = " << no_of_divisions << endl;
cout << "Risk Free Interest Rate = " << risk_free_rate << endl;
cout << "Volatility (%age of stock value) = " << volatility*100 << endl;
cout << "Initial Stock Price = " << initial_stock_price << endl;
cout << "Strike Price = " << strike_price << endl;
cout << "--------------------------------------" << endl;
cout << "Up Factor = " << up_factor << endl;
cout << "Uptick Probability = " << probs.uptick_prob << endl;
cout << "Notick Probability = " << probs.notick_prob << endl;
cout << "Downtick Probability = " << probs.downtick_prob << endl;
cout << "--------------------------------------" << endl;
cout<<endl;
double call_price = american_asian_call_option(0,0, initial_stock_price, initial_stock_price, up_factor, R, probs, no_of_divisions, strike_price);
cout << "Trinomial Price of an American Asian Call Option = " << call_price << endl;
double put_price = american_asian_put_option(0, 0, initial_stock_price, initial_stock_price, up_factor, R, probs, no_of_divisions, strike_price);
cout << "Trinomial Price of an American Asian Put Option = " << put_price << endl;
return 0;
}
|