Pls help debug

#include<cmath>
#include<iostream>
#include<iomanip>
const float t = 0;
const float K = 25 ;
const float S0 = 25 ;
const float T = 1 ;
const float d = 0.05 ;
const float r = 0.035 ;
const float Pi = 3.1415926 ;
using namespace std ;
double D1(double) ;
double D2(double) ;
double f(double) ;
double F(double) ;
double Vc(double, double, double);
double Vp(double, double, double);
int main () {
double sigma [10];// arrays of sigma//
int i ;// define i//
cout << setw(8) << "sigma " << setw(15) <<"Vc" << setw(15) << "Vp" << "\n";
for (i=0; i<10; i++)
{ sigma [i] = (i+1)*0.1;
cout << setprecision(2);// set to 2 decimal point//
cout <<setw(8) << std :: setiosflags(ios:: fixed) << sigma[i] ;
cout << setprecision(6) ;
cout << setw(16) << Vc(S0, 0, sigma[i]);
cout << setw(16) << Vp(S0, 0, sigma[i]) << "\n";
}
return 0;
}
double D1(double sigma){
return ((log(S0/K)) + ( r - d + ((sigma*sigma)/2))*(T-t))/sigma * sqrt(T-t) ;
}

double D2(double sigma){
return D1(sigma) - sigma * (sqrt(T-t)) ;

}
double f(double x){
return (1/sqrt(2*Pi)*exp((-1)*x*x/2)) ;

}
double F(double x){
double z, a1, a2, a3, a4, a5 ;
z = 1/(1+0.2316419*x);
a1=0.319381530;
a2=0.356563782*(-1);
a3=1.781477937;
a4=1.821255978*(-1);
a5=1.330274429;

if (x>=0)
{
return 1-f(x)*z*((((a5*z+a4)*z+a3)*z+a2)*z+a1);

}
else
{
return 1-F(x*(-1));/*time t*/

}}

double Vc(double St,double t,double sigma) {
return St*exp((-1)*d*(T-t))*F(D1(sigma))-K*exp((-1)*r*(T-t))*F(D2(sigma)); /*time t*/
}
/*time t for put option*/
double Vp (double St, double t,double sigma) {
return (-1)*St*exp((-1)*d*(T-t))*F((-1)*D1(sigma))+K*exp((-1)*r*(T-t))*F(D2(sigma));

}
}
Last edited on
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 #include<cmath>
#include<iostream>
#include<iomanip>
const float t = 0;
const float K = 25 ;
const float S0 = 25 ;
const float T = 1 ;
const float d = 0.05 ;
const float r = 0.035 ;
const float Pi = 3.1415926 ;
using namespace std ;
double D1(double) ;
double D2(double) ;
double f(double) ;
double F(double) ;
double Vc(double, double, double);
double Vp(double, double, double);
int main () {
double sigma [10];// arrays of sigma//
int i ;// define i//
cout << setw(8) << "sigma " << setw(15) <<"Vc" << setw(15) << "Vp" << "\n";
for (i=0; i<10; i++)
{ sigma [i] = (i+1)*0.1;
cout << setprecision(2);// set to 2 decimal point//
cout <<setw(8) << std :: setiosflags(ios:: fixed) << sigma[i] ;
cout << setprecision(6) ;
cout << setw(16) << Vc(S0, 0, sigma[i]);
cout << setw(16) << Vp(S0, 0, sigma[i]) << "\n";
}
return 0;
}
double D1(double sigma){
return ((log(S0/K)) + ( r - d + ((sigma*sigma)/2))*(T-t))/sigma * sqrt(T-t) ;
}

double D2(double sigma){
return D1(sigma) - sigma * (sqrt(T-t)) ;

}
double f(double x){
return (1/sqrt(2*Pi)*exp((-1)*x*x/2)) ;

}
double F(double x){
double z, a1, a2, a3, a4, a5 ;
z = 1/(1+0.2316419*x);
a1=0.319381530;
a2=0.356563782*(-1);
a3=1.781477937;
a4=1.821255978*(-1);
a5=1.330274429;

if (x>=0)
{
return 1-f(x)*z*((((a5*z+a4)*z+a3)*z+a2)*z+a1);

}
else
{
return 1-F(x*(-1));/*time t*/

}}

double Vc(double St,double t,double sigma) {
return St*exp((-1)*d*(T-t))*F(D1(sigma))-K*exp((-1)*r*(T-t))*F(D2(sigma)); /*time t*/
}
/*time t for put option*/
double Vp (double St, double t,double sigma) {
return (-1)*St*exp((-1)*d*(T-t))*F((-1)*D1(sigma))+K*exp((-1)*r*(T-t))*F(D2(sigma));

}
}//<<<<<<<<<<<<<<delete this 
Topic archived. No new replies allowed.