# A Simple C++ Program for Computing Binomial Option Prices

I have been advised that C++ and VBA are commonly requested languages for actuaries. So, while I am studying for exam MFE, I have been writing simple programs.  My native language is LISP.  I like its beauty, and its adaptability.  I am sure that C++ has its promoters, but I think that it is a shame that such an ugly programming language has become one of the most used.

Of course, I am still a novice to the language, so my code is still extra ugly.

Computes call price using binomial model:

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>

//Calculates price of call option, and portfolio required to duplicate option, using binomial tree

int main() {
using namespace std;
float S0, r,div, K, h, sigma, u, d, uS,dS,Cu,Cd,delta, bondValue, callPrice;
//get data
cout<<“Calculate the price of a call, using a one period binary tree”<<endl;
cout<<“Current Stock Price?”;
cin>>S0;
cout<<“Continuously Compounded Risk Free Rate?”;
cin>>r;
cout<<“Continuous Dividend Rate?”;
cin>>div;
cout<<“Strike Price?”;
cin>>K;
cout<<“Time to Expiration?”;
cin>>h;
cout<<“Volatility?”;
cin>>sigma;
//calculate likely upward and downward motions
u=exp((r-div)*h+sigma*sqrt(h));
d=exp((r-div)*h-sigma*sqrt(h));
uS=u*S0;
dS=d*S0;
cout<<“Upward Move “<<uS<<endl;
cout<<“Downward Move “<<dS<<endl;
//calculate payoff of call, given motions above
if (uS > K)
Cu = uS-K;
else Cu = 0;
if (dS > K)
Cd = dS-K;
else Cd = 0;
//calculate Delta, Beta, and call option price
delta=exp(-div * h)*(Cu-Cd)/(S0*(u-d));
bondValue=exp(-r * h)*((u*Cd)-(d*Cu))/(u-d);
callPrice=delta*S0+bondValue;
cout<<“To duplicate the call, buy “<<delta<<” shares=”” of=”” the=”” stock=”” for=”” “<<delta*s0<<“=”” dollars=”” and=”” borrow=”” “<<-1=”” *=”” bondvalue<<“=”” at=”” rate=”” “<<r<<“=”” a=”” total=”” price=”” “<<callprice<<<span=”” class=”hiddenSpellError” pre=”” data-mce-bogus=”1″>endl;
cout<<“Price of Call “<<callPrice<<endl;

//find the price of some other related calls
cout<<“Some other Call prices: “<<endl;
float step;
step = 0.05*K;
K= K-5*step;
for (int z=0;z<11;z++){
if (uS > K)
Cu = uS-K;
else Cu = 0;
if (dS > K)
Cd = dS-K;
else Cd = 0;

delta=exp(-div * h)*(Cu-Cd)/(S0*(u-d));
bondValue=exp(-r * h)*((u*Cd)-(d*Cu))/(u-d);
callPrice=delta*S0+bondValue;

cout<<setw(8)<<k<<” “<<callprice<<<span=”” class=”hiddenSpellError” pre=”” data-mce-bogus=”1″>endl;
K=K+step;
}
return 0;
}
//Wow what an ugly program

Here is a sample run: