-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMJDclosed.cpp
More file actions
50 lines (44 loc) · 1.37 KB
/
MJDclosed.cpp
File metadata and controls
50 lines (44 loc) · 1.37 KB
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
#include "StdAfx.h"
#include "MJDclosed.h"
#include "BS_HEADER.h"
// Closed form solution for the Merton (1976) jump diffusion model
/
CMertonJDclosed::CMertonJDclosed(void) { }
CMertonJDclosed::~CMertonJDclosed(void) { }
// PutCall = 'P'ut or 'C'all
// S0 = spot
// K = strike
// r = risk free rate
// q = dividend yield
// sigma = stock return volatility
// T = maturity
// lambdaJ = jump frequency
// muJ = jump mean
// sigmaJ = jump volatility
// N = number of terms in the sum
// Closed form Merton (1976) jump diffusion price
double CMertonJDclosed::JDclosed(char PutCall,double S0,double K,double r,double q,double sigma,double T,double lambdaJ,double muJ,double sigmaJ,int N)
{
CBlackScholes BS;
// Expected jump value
double kappa = exp(muJ + 0.5*sigmaJ*sigmaJ) - 1.0;
// Initialize the price
double Price = 0.0;
double sigman,rn,BSPrice,lambda,Probability;
for (int n=0; n<N; n++) {
sigman = sqrt(sigma*sigma + n*sigmaJ*sigmaJ/T);
rn = r - lambdaJ*kappa + n*log(1.0+kappa)/T;
BSPrice = BS.BSPrice(S0,K,rn,q,sigman,T,PutCall);
lambda = lambdaJ*(1.0+kappa);
Probability = exp(-lambda*T)*pow(lambda*T,double(n))/factorial(n);
Price = Price + Probability*BSPrice;
}
return Price;
}
// Factorial function
double CMertonJDclosed::factorial(int n) {
if (n==0)
return 1.0;
else
return n*factorial(n-1);
}