Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8 Homework: Binomial model 8.1 Function signature Let us write a simple (but wor

ID: 3712579 • Letter: 8

Question

8 Homework: Binomial model 8.1 Function signature Let us write a simple (but working) C++ function to implement the binomial model. . The input arguments are 1. The stock price S 2. The strike price K 3. The risk-free interest rate r. (We shall use decimal, not percent) 4. The continuous dividend yield q. (We shall use decimal, not percent.) 5. The stock volatility ?. (We shall use decimal, not percent.) 6. The expiration time T. (Measured in years.) 7. The current time to. (Measured in years.) 8. boolean "call" (true for a call, false for a put) 9. boolean "American" (true for an American option, false for European) 10. int n, the number of timesteps (n >= 1) 11. reference to double, output the option fair value V The function signature is int binomial_simple (double S, double K, double r, double q, double sigma, double T, double t0, bool call, bool American, int n, double & V); . The return type is int because we shall perform validation checks

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

int binomial_simple(double,double,double,double,double,double,double,bool,bool,int,double *);

int main()
{
double S,K,r,q,sigma,T,t0,V;
bool call=true,American=true,put=false,European=false;
int n;
  
cout << "Enter Stoke price:S" << endl;
cin >> S;
cout << "Enter Strike price:K" << endl;
cin >> K;
cout << "enter risk-free interest rate:r" << endl;
cin >> r;
cout << "Enter continuous divident yield:q" << endl;
cin >> q;
cout << "Enter Stock volatility: sigma:" << endl;
cin >> sigma;
cout << "Enter expiration time: T" << endl;
cin >> T;
cout << "Enter current time:t0 " << endl;
cin >> t0;
cout << "Enter number of timestamps. Please enter greater than equal to 1" << endl;
cin >> n;
cout << "Enter option fair value:V " << endl;
cin >> t0;

int output= binomial_simple(S,K,r,q,sigma,T,t0,call,American,n,&V);
cout << output <<endl;
if(output==1)
cout << "Fail";

return 0;
}

int binomial_simple(double S,double K,double r,double q,double sigma,double T,double t0,bool call,bool American,int n,double *V)
{

if(n < 1)
return 1;
if(S <= 0)
return 1;
if(T <= t0)
return 1;
if(sigma <= 0.0)
return 1;
  
double dt = (T-t0)/double(n);
double df = exp(-r*dt);
double growth = exp((r-q)*dt);
double u = exp(sigma*sqrt(dt));
double d = 1.0/u;

double p_prob = (growth-d)/(u-d);
double q_prob = 1.0-p_prob;

if(p_prob<0.0)
return 1;
if(p_prob>1.0)   
return 1;
  
return 0;   
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote