#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
Integer seed[6], state[70];
Integer A, K, N, subid = 0, lseed = 6, lstate = 70;
double T, r, q, mu, var;
A = 5;
N = 50000;
K = 80;
T = 1.5;
r = 0.03;
q = 0.015;
mu = 0;
var = 1.00;
double *Z = new double[N*A];
Integer S[] = {100,90,80,70,60};
double sigma[]= {0.04,0.06,0.07,0.10,0.15};
double cor[] = {1.0,0.3,0.4,-0.7,0.0,
0.3,1.0,0.5,-0.3,0.1,
0.4,0.5,1.0,-0.2,-0.5,
-0.7,-0.3,-0.2,1.0,0.4,
0.0,0.1,-0.5,0.4,1.0
};
for (int i=0; i<6; i++) {
seed[i] = i+1;
}
nag_rand_init_repeatable(Nag_MRG32k3a,subid,seed,lseed,state,&lstate,NULL);
nag_rand_normal(N*A,mu,var,state,Z,NULL);
nag_dpotrf(Nag_ColMajor,Nag_Lower,A,cor,A,NULL);
nag_dtrmm(Nag_ColMajor,Nag_LeftSide,Nag_Lower,Nag_NoTrans,Nag_NonUnitDiag,A,N,1.0,cor,A,Z,A,NULL);
double sum = 0.0;
for (int i=0; i K) {
sum += Xi - K;
}
}
double price = exp(-r*T)*sum/N;
cout.precision(14);
cout << endl << "NAG C++ Question 4" << endl;
cout << "===================================" << endl;
cout << "Price " << price << endl;
cout << "===================================" << endl << endl;
delete[] Z;
}