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: 3712577 • 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

Code

#include <iostream>
#include <math>
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)

{
//Answer of Question 8.2
if(n<1)
return 1;
if(S<=0)
return 1;
if(T<=t0)
return 1;
if(sigma<=0.0)
return 1;
  
//Answer of Question 8.3
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;
}
int main() {
double S, K, r, q, sigma, T, t0, V;
bool call, American;
int n;
//input steps
cout<<"Enter Stock price : ";
cin>>S;
cout<<"Enter Strike Price";
cin>K;
cout<<"Enter risk free interest rate : ";
cin>>r;
cout<<"Enter continue dividend yield : ";
cin>>q;
cout<<"Enter stock volatility : ";
cin>>sigma;
cout<<"Enter expiration time : ";
cin>>T;
cout<<"Enter current time";
cin>>t0;
cout<<"Enter option fair value";
cin>>V;
cout<<"Enter number of time steps : ";
cin>>n;
//four times call with american/europe, call/put
int res_1 = binomial_simple(S, K, r, q, sigma, T, t0, true, true, n, &V);
int res_2 = binomial_simple(S, K, r, q, sigma, T, t0, true, false, n, &V);
int res_3 = binomial_simple(S, K, r, q, sigma, T, t0, false, true, n, &V);
int res_4 = binomial_simple(S, K, r, q, sigma, T, t0, false, false, n, &V);
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