• 2687閱讀
  • 30回復

PROGRAMMING 難題 (厚酬: 50000x2=100000好友元)(URGENT!!)(最主要都係睇NESTED FOR-LOOP!!) [復制鏈接]

上一主題 下一主題
離線雲佬~~SY
 
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看樓主 倒序閱讀 使用道具 樓主   發表于: 2011-04-15
是咁的,小弟有2個c++ programming遇到d阻滯, run 唔到D正常OUTPUT,望各位好友嘗面留條毛幫幫手睇下邊度有問題..如果成功的話(厚酬: 50000x2=100000好友元)
PS.有C++ SOFTWARE / VISUAL BASIC / VISUAL STUDIO 就最好不過~


其實依2個program 都係用d式去計option call/put price..
一個係CONSTANT ELASTICITY OF VARIANCE MODEl(cev),
另一個係JUMP DIFFUSION MODEL;



(最主要都係睇NESTED FOR-LOOP!!)同埋係咪LOGIC 有問題?
[ 本文被雲佬~~SY在2011-04-16 20:34重新編輯 ]
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 1  發表于: 2011-04-15
第一個program: (PROGRAM1 GESOURCE CODE)

  1. // CEV4_14.cpp : Defines the entry point for the console application.
  2. #include "stdafx.h"
  3. #include <fstream>
  4. #include <iostream>
  5. #include <math.h>
  6. #include <string>
  7. using namespace std;
  8. class price
  9. {
  10. public:
  11.       double strike;
  12.       double ca;
  13.       double pa;
  14.       double b;
  15.       double cc;
  16.       double pc;
  17.       double cv;
  18.       double pv;
  19.       double ctz;
  20.       double ctk;
  21.       double ctv;
  22.       double ctz1;
  23.       double ctk1;
  24.       double ctv1;
  25.       double ptz;
  26.       double ptk;
  27.       double ptv;
  28.       double ptz1;
  29.       double ptk1;
  30.       double ptv1;
  31.       double cchisq;
  32.       double cchisq1;
  33.       double pchisq;
  34.       double pchisq1;
  35.       double cp;
  36.       double pp;
  37.       double cmp;
  38.       double pmp;
  39. };
  40. double chisquare(double a,double b,double c,double d)
  41. {
  42.       double x=0;
  43.       double t[1500],w[1500],u[1500];
  44.       t[0]=((1/d))*(pow(a/2,b/2))*exp(-a/2);
  45.       u[0]=exp(-c/2);
  46.       w[0]=exp(-c/2);
  47.       x=w[0]*t[0];
  48.       for(int y=1;y<1500;y++)
  49.           {
  50.             t[y]=t[y-1]*(a/(b+2*y));
  51.             u[y]=u[y-1]*c/(2*y);
  52.             w[y]=w[y-1]+u[y];
  53.             x=x+w[y]*t[y];
  54.             }
  55.       return x;
  56. }
  57. int main(int argc, char** argv)
  58. {
  59. double S;
  60. double r,q,T;
  61. int alpha;
  62. int vol;
  63. double command;
  64. int i, VALUE=0;
  65. double p0=1, p1=76.18009173 , p2=-86.50532033 , p3=24.01409824;
  66. double p4=-1.231739572, p5=0.001208651, p6=-0.00000539524;
  67. double gamma_x, gamma, temp ;
  68. double tmp;
  69. double xx=0 , min=10000 , minalpha , minvol ;
  70. double zz=0 , min1=10000;
  71. cout << "Enter spot price:" << endl;
  72. cin >> command;
  73. S = command;
  74. cout << "Enter risk-free rate:" << endl;
  75. cin >> command;
  76. r = command;
  77. cout << "Enter dividend yield:" << endl;
  78. cin >> command;
  79. q = command;
  80. cout << "Enter period of maturity:" << endl;
  81. cin >> command;
  82. T = command;
  83. price K[30];
  84. i = 0;
  85. while (i==0)
  86. {
  87.   cout << "Enter strike price: (enter 9999 if there is no more strike price) " << endl;
  88.   cin >> command;
  89. if (command<9999)
  90.   {
  91.     K[VALUE].strike = command;
  92.     cout << "Enter put options' market price" << endl;
  93.     cin >> command;
  94.     K[VALUE].pmp = command;
  95.     cout << "Enter call options' market price" << endl;
  96.     cin >> command;
  97.     K[VALUE].cmp = command;
  98.     VALUE++;
  99.   }
  100. else            
  101. {i=1;}
  102. }
  103. for(vol=1;vol<500;vol++)
  104. {
  105.   for(alpha=1;alpha<300;alpha++)
  106.   {
  107.       for (i=0;i<VALUE;i++)
  108.       {
  109.       K[i].cv=((vol*vol/10000)/(2*(r-q)*(alpha/100-1)))*(exp(2*(r-q)*(alpha/100-1)*T)-1);
  110.       K[i].pv=((vol*vol/10000)/(2*(r-q)*(alpha/100-1)))*(exp(2*(r-q)*(alpha/100-1)*T)-1);
  111.       K[i].ca=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha/100)))/(((1-alpha)*(1-alpha))*K[i].cv);
  112.       K[i].pa=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha/100)))/(((1-alpha)*(1-alpha))*K[i].pv);
  113.       K[i].b=1/(1-alpha/100);
  114.       K[i].cc=pow(S,2*(1-alpha/100))/(((1-alpha)*(1-alpha))*K[i].cv);
  115.       K[i].pc=pow(S,2*(1-alpha/100))/(((1-alpha)*(1-alpha))*K[i].pv);
  116.       };
  117.       for(int i=0;i<VALUE;i++)
  118.       { if(alpha/100<1)
  119.         {
  120.         K[i].ctz=K[i].ca ;
  121.         K[i].ctk=K[i].b + 2 ;
  122.         K[i].ctv=K[i].cc ;
  123.         K[i].ctz1=K[i].cc ;
  124.         K[i].ctk1=K[i].b ;
  125.         K[i].ctv1=K[i].ca ;
  126.         K[i].ptz=K[i].pc ;
  127.         K[i].ptk=K[i].b ;
  128.         K[i].ptv=K[i].pa ;
  129.         K[i].ptz1=K[i].pa ;
  130.         K[i].ptk1=K[i].b+2 ;
  131.         K[i].ptv1=K[i].pc ;
  132.         }
  133.         else {
  134.         K[i].ctz=K[i].cc ;
  135.         K[i].ctk=-K[i].b ;
  136.         K[i].ctv=K[i].ca ;
  137.         K[i].ctz1=K[i].ca ;
  138.         K[i].ctk1=2-K[i].b ;
  139.         K[i].ctv1=K[i].cc ;
  140.         K[i].ptz=K[i].pa ;
  141.         K[i].ptk=2-K[i].b ;
  142.         K[i].ptv=K[i].pc ;
  143.         K[i].ptz1=K[i].pc ;
  144.         K[i].ptk1=K[i].b ;
  145.         K[i].ptv1=K[i].pa ;}
  146.         gamma_x=K[i].ctk/2+1;
  147.         temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  148.         gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  149.         tmp=chisquare(K[i].ctz,K[i].ctk,K[i].ctv,gamma);
  150.         K[i].cchisq=tmp;
  151.         gamma_x=K[i].ctk1/2+1;
  152.         temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  153.         gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  154.         tmp=chisquare(K[i].ctz1,K[i].ctk1,K[i].ctv1,gamma);
  155.         K[i].cchisq1=tmp;
  156.         gamma_x=K[i].ptk/2+1;
  157.         temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  158.         gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  159.         tmp=chisquare(K[i].ptz,K[i].ptk,K[i].ptv,gamma);
  160.         K[i].pchisq1=tmp;
  161.         gamma_x=K[i].ptk1/2+1;
  162.         temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  163.         gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  164.         tmp=chisquare(K[i].ptz1,K[i].ptk1,K[i].ptv1,gamma);
  165.         K[i].pchisq=tmp;
  166.         K[i].cp=S*exp(-q*T)*(1-K[i].cchisq)-K[i].strike*exp(-r*T)*K[i].cchisq1;
  167.         K[i].pp=K[i].strike*exp(-r*T)*(1-K[i].pchisq1)-S*exp(-q*T)*K[i].pchisq;
  168.       };
  169.         xx=0;
  170.         zz=0;
  171.       for(int i=0;i<VALUE;i++)
  172.       {   //xx==0;
  173.         xx=xx+(pow(K[i].cp-K[i].cmp,2))+pow(K[i].pp-K[i].pmp,2);
  174.       };
  175.       if(xx<min)
  176.       {min=xx;
  177.       minalpha=alpha/100;
  178.       minvol=vol/100;
  179.       }
  180. }//for loop(alpha)
  181. }//for loop(vol)
  182. cout<<"Summation of the least square test :"<<min<<endl;
  183. cout<<"Corresponding alpha:"<<minalpha<<endl;
  184. cout<<"Corresponding sigma:"<<minvol<<endl;
  185. alpha=minalpha;
  186. vol=minvol;
  187. /*
  188. for (i=0;i<VALUE;i++)
  189. {
  190.   K[i].cv=((vol*vol)/(2*(r-q)*(alpha-1)))*(exp(2*(r-q)*(alpha-1)*T)-1);
  191.   K[i].pv=((vol*vol)/(2*(r-q)*(alpha-1)))*(exp(2*(r-q)*(alpha-1)*T)-1);
  192.   K[i].ca=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha)))/((pow(1-alpha,2))*K[i].cv);
  193.   K[i].pa=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha)))/((pow(1-alpha,2))*K[i].pv);
  194.   K[i].b=1/(1-alpha);
  195.   K[i].cc=pow (S,2*(1-alpha))/(pow((1-alpha),2)*K[i].cv);
  196.   K[i].pc=pow (S,2*(1-alpha))/(pow((1-alpha),2)*K[i].pv);
  197. }
  198. for(i=0;i<VALUE;i++)
  199. { if(alpha<1)
  200. {
  201.   K[i].ctz=K[i].ca ;
  202.   K[i].ctk=K[i].b + 2 ;
  203.   K[i].ctv=K[i].cc ;
  204.   K[i].ctz1=K[i].cc ;
  205.   K[i].ctk1=K[i].b ;
  206.   K[i].ctv1=K[i].ca ;
  207.   K[i].ptz=K[i].pc ;
  208.   K[i].ptk=K[i].b ;
  209.   K[i].ptv=K[i].pa ;
  210.   K[i].ptz1=K[i].pa ;
  211.   K[i].ptk1=K[i].b+2 ;
  212.   K[i].ptv1=K[i].pc ;
  213. }
  214. else {
  215.   K[i].ctz=K[i].cc ;
  216.   K[i].ctk=-K[i].b ;
  217.   K[i].ctv=K[i].ca ;
  218.   K[i].ctz1=K[i].ca ;
  219.   K[i].ctk1=2-K[i].b ;
  220.   K[i].ctv1=K[i].cc ;
  221.   K[i].ptz=K[i].pa ;
  222.   K[i].ptk=2-K[i].b ;
  223.   K[i].ptv=K[i].pc ;
  224.   K[i].ptz1=K[i].pc ;
  225.   K[i].ptk1=K[i].b ;
  226.   K[i].ptv1=K[i].pa ; }
  227. gamma_x=K[i].ctk/2+1;
  228. temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  229. gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  230. tmp=chisquare(K[i].ctz,K[i].ctk,K[i].ctv,gamma);
  231. K[i].cchisq=tmp;
  232. gamma_x=K[i].ctk1/2+1;
  233. temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  234. gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  235. tmp=chisquare(K[i].ctz1,K[i].ctk1,K[i].ctv1,gamma);
  236. K[i].cchisq1=tmp;
  237. gamma_x=K[i].ptk/2+1;
  238. temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  239. gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  240. tmp=chisquare(K[i].ptz,K[i].ptk,K[i].ptv,gamma);
  241. K[i].pchisq1=tmp;
  242. gamma_x=K[i].ptk1/2+1;
  243. temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
  244. gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
  245. tmp=chisquare(K[i].ptz1,K[i].ptk1,K[i].ptv1,gamma);
  246. K[i].pchisq=tmp;
  247. K[i].cp=S*exp(-q*T)*(1-K[i].cchisq)-K[i].strike*exp(-r*T)*K[i].cchisq1;
  248. K[i].pp=K[i].strike*exp(-r*T)*(1-K[i].pchisq1)-S*exp(-q*T)*K[i].pchisq;
  249. }*/
  250. for(int i=0;i<VALUE;i++)
  251. {   cout << "For Strike Price =" << K[i].strike << ", call price ="<<K[i].cp<<endl;
  252.   cout << "For Strike Price =" << K[i].strike << ", put price ="<<K[i].pp<<endl;
  253.   }
  254. return (0);
  255. }
[ 本文被雲佬~~SY在2011-04-16 20:33重新編輯 ]
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 2  發表于: 2011-04-15
第2個program:(SOURCE CODE)





  1. // jd41414141.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <math.h>
  6. using namespace std ;
  7. //#undef main
  8. double EuroCall(double S,double K,double r,double q,double T,double sig_call,double lambda,double k,double s,int n);
  9. double EuroPut(double S,double K,double r, double q,double T,double sig_put,double lambda,double k,double s,int n);
  10. double NP(double x);
  11. double N(double x);
  12. int main(int argc, char** argv)
  13. {
  14. double S;     // price of stock or underlying security
  15. double K1;     // strike price
  16. double K2;
  17. double K3;
  18. double K4;
  19. double K5;
  20. double K6;
  21. double K7;
  22. double K8;
  23. double K9;
  24. double K10;
  25. double K11;
  26. double K12;
  27. double K13;
  28. double K14;
  29. double K15;
  30. double r;     // interest rate
  31. double q;     // divident yield
  32. double T;     // reminding life
  33. double sigma;   // fixed voltility
  34. double lambda; // average number of jumps per year
  35. double k;     // average jump sizw measured as a percentage of the asset price
  36. double s;     // stardard deviation of the normal distribution for logarithm of the size of the percentage jump
  37. int n ;
  38. int VALUE = 30 ; // number of iteration
  39. double market_call_1;
  40. double market_call_2;
  41. double market_call_3;
  42. double market_call_4;
  43. double market_call_5;
  44. double market_call_6;
  45. double market_call_7;
  46. double market_call_8;
  47. double market_call_9;
  48. double market_call_10;
  49. double market_call_11;
  50. double market_call_12;
  51. double market_call_13;
  52. double market_call_14;
  53. double market_call_15;
  54. double market_put_1;
  55. double market_put_2;
  56. double market_put_3;
  57. double market_put_4;
  58. double market_put_5;
  59. double market_put_6;
  60. double market_put_7;
  61. double market_put_8;
  62. double market_put_9;
  63. double market_put_10;
  64. double market_put_11;
  65. double market_put_12;
  66. double market_put_13;
  67. double market_put_14;
  68. double market_put_15;
  69. cout << " Enter spot price :" << endl;
  70. cin >> S;
  71. cout << " Enter risk-free rate :" << endl;
  72. cin >> r;
  73. cout << " Enter dividend yield :" << endl;
  74. cin >> q;
  75. cout << " Enter period of maturity :" << endl;
  76. cin >> T;
  77. cout << endl;
  78. cout << " Enter 15 strike prices with corresponding market call and put prices:" << endl ;
  79. cout << endl;
  80. cout << " Enter strike price 1 :" <<endl;
  81. cin >> K1;
  82. cout << " Enter call option 1 market price :" <<endl;
  83. cin >> market_call_1;
  84. cout << " Enter put option market price :" <<endl;
  85. cin >> market_put_1;
  86. cout << endl;
  87. cout << " Enter strike price 2 :" <<endl;
  88. cin >> K2;
  89. cout << " Enter call option 2 market price :" <<endl;
  90. cin >> market_call_2;
  91. cout << " Enter put option 2 market price :" <<endl;
  92. cin >> market_put_2;
  93. cout << endl;
  94. cout << " Enter strike price 3:" <<endl;
  95. cin >> K3;
  96. cout << " Enter call option 3 market price :" <<endl;
  97. cin >> market_call_3;
  98. cout << " Enter put option 3 market price :" <<endl;
  99. cin >> market_put_3;
  100. cout << endl;
  101. cout << " Enter strike price 4 :" <<endl;
  102. cin >> K4;
  103. cout << " Enter call option 4 market price :" <<endl;
  104. cin >> market_call_4;
  105. cout << " Enter put option 4 market price :" <<endl;
  106. cin >> market_put_4;
  107. cout << endl;
  108. cout << " Enter strike price 5 :" <<endl;
  109. cin >> K5;
  110. cout << " Enter call option 5 market price :" <<endl;
  111. cin >> market_call_5;
  112. cout << " Enter put option 5 market price :" <<endl;
  113. cin >> market_put_5;
  114. cout << endl;
  115. cout << " Enter strike price 6 :" <<endl;
  116. cin >> K6;
  117. cout << " Enter call option 6 market price :" <<endl;
  118. cin >> market_call_6;
  119. cout << " Enter put option 6 market price :" <<endl;
  120. cin >> market_put_6;
  121. cout << endl;
  122. cout << " Enter strike price 7 :" <<endl;
  123. cin >> K7;
  124. cout << " Enter call option 7 market price :" <<endl;
  125. cin >> market_call_7;
  126. cout << " Enter put option 7 market price :" <<endl;
  127. cin >> market_put_7;
  128. cout << endl;
  129. cout << " Enter strike price 8 :" <<endl;
  130. cin >> K8;
  131. cout << " Enter call option 8 market price :" <<endl;
  132. cin >> market_call_8;
  133. cout << " Enter put option 8 market price :" <<endl;
  134. cin >> market_put_8;
  135. cout << endl;
  136. cout << " Enter strike price 9 :" <<endl;
  137. cin >> K9;
  138. cout << " Enter call option 9 market price :" <<endl;
  139. cin >> market_call_9;
  140. cout << " Enter put option 9 market price :" <<endl;
  141. cin >> market_put_9;
  142. cout << endl;
  143. cout << " Enter strike price 10:" <<endl;
  144. cin >> K10;
  145. cout << " Enter call option 10 market price :" <<endl;
  146. cin >> market_call_10;
  147. cout << " Enter put option 10 market price :" <<endl;
  148. cin >> market_put_10;
  149. cout << endl;
  150. cout << " Enter strike price 11 :" <<endl;
  151. cin >> K11;
  152. cout << " Enter call option 11 market price :" <<endl;
  153. cin >> market_call_11;
  154. cout << " Enter put option 11 market price :" <<endl;
  155. cin >> market_put_11;
  156. cout << endl;
  157. cout << " Enter strike price 12 :" <<endl;
  158. cin >> K12;
  159. cout << " Enter call option 12 market price :" <<endl;
  160. cin >> market_call_12;
  161. cout << " Enter put option 12 market price :" <<endl;
  162. cin >> market_put_12;
  163. cout << endl;
  164. cout << " Enter strike price 13 :" <<endl;
  165. cin >> K13;
  166. cout << " Enter call option 13 market price :" <<endl;
  167. cin >> market_call_13;
  168. cout << " Enter put option 13 market price :" <<endl;
  169. cin >> market_put_13;
  170. cout << endl;
  171. cout << " Enter strike price 14 :" <<endl;
  172. cin >> K14;
  173. cout << " Enter call option 14 market price :" <<endl;
  174. cin >> market_call_14;
  175. cout << " Enter put option 14 market price :" <<endl;
  176. cin >> market_put_14;
  177. cout << endl;
  178. cout << " Enter strike price 15 :" <<endl;
  179. cin >> K15;
  180. cout << " Enter call option 15 market price :" <<endl;
  181. cin >> market_call_15;
  182. cout << " Enter put option 15 market price :" <<endl;
  183. cin >> market_put_15;
  184. cout << endl;
  185. cout<<"In progress ... "<< endl;
  186. cout << endl;
  187. int a=0;
  188. double temp_min_call;
  189. double temp_min_put;
  190. double min_call;
  191. double min_put;
  192. double min_sum;
  193. int min_i_call;
  194. int min_h_put;
  195. int h;
  196. int i;
  197. int j;
  198. static int factorial[300000];
  199. static double temp[300000];
  200. static double f_call_1[300000];
  201. static double f_call_2[300000];
  202. static double f_call_3[300000];
  203. static double f_call_4[300000];
  204. static double f_call_5[300000];
  205. static double f_call_6[300000];
  206. static double f_call_7[300000];
  207. static double f_call_8[300000];
  208. static double f_call_9[300000];
  209. static double f_call_10[300000];
  210. static double f_call_11[300000];
  211. static double f_call_12[300000];
  212. static double f_call_13[300000];
  213. static double f_call_14[300000];
  214. static double f_call_15[300000];
  215. static double f_put_1[300000];
  216. static double f_put_2[300000];
  217. static double f_put_3[300000];
  218. static double f_put_4[300000];
  219. static double f_put_5[300000];
  220. static double f_put_6[300000];
  221. static double f_put_7[300000];
  222. static double f_put_8[300000];
  223. static double f_put_9[300000];
  224. static double f_put_10[300000];
  225. static double f_put_11[300000];
  226. static double f_put_12[300000];
  227. static double f_put_13[300000];
  228. static double f_put_14[300000];
  229. static double f_put_15[300000];
  230. class merton
  231. {
  232. public :
  233.   double price;
  234.   double jump_num;  
  235.   double jump_size;  
  236.   double sd;
  237.   double vol;
  238. };
  239. static double merton_call_1[300000];
  240. static double merton_call_2[300000];
  241. static double merton_call_3[300000];
  242. static double merton_call_4[300000];
  243. static double merton_call_5[300000];
  244. static double merton_call_6[300000];
  245. static double merton_call_7[300000];
  246. static double merton_call_8[300000];
  247. static double merton_call_9[300000];
  248. static double merton_call_10[300000];
  249. static double merton_call_11[300000];
  250. static double merton_call_12[300000];
  251. static double merton_call_13[300000];
  252. static double merton_call_14[300000];
  253. static double merton_call_15[300000];
  254. static double merton_put_1[300000];
  255. static double merton_put_2[300000];
  256. static double merton_put_3[300000];
  257. static double merton_put_4[300000];
  258. static double merton_put_5[300000];
  259. static double merton_put_6[300000];
  260. static double merton_put_7[300000];
  261. static double merton_put_8[300000];
  262. static double merton_put_9[300000];
  263. static double merton_put_10[300000];
  264. static double merton_put_11[300000];
  265. static double merton_put_12[300000];
  266. static double merton_put_13[300000];
  267. static double merton_put_14[300000];
  268. static double merton_put_15[300000];
  269. static merton temp_call_1[300000];
  270. static merton temp_call_2[300000];
  271. static merton temp_call_3[300000];
  272. static merton temp_call_4[300000];
  273. static merton temp_call_5[300000];
  274. static merton temp_call_6[300000];
  275. static merton temp_call_7[300000];
  276. static merton temp_call_8[300000];
  277. static merton temp_call_9[300000];
  278. static merton temp_call_10[300000];
  279. static merton temp_call_11[300000];
  280. static merton temp_call_12[300000];
  281. static merton temp_call_13[300000];
  282. static merton temp_call_14[300000];
  283. static merton temp_call_15[300000];
  284. static merton temp_put_1[300000];
  285. static merton temp_put_2[300000];
  286. static merton temp_put_3[300000];
  287. static merton temp_put_4[300000];
  288. static merton temp_put_5[300000];
  289. static merton temp_put_6[300000];
  290. static merton temp_put_7[300000];
  291. static merton temp_put_8[300000];
  292. static merton temp_put_9[300000];
  293. static merton temp_put_10[300000];
  294. static merton temp_put_11[300000];
  295. static merton temp_put_12[300000];
  296. static merton temp_put_13[300000];
  297. static merton temp_put_14[300000];
  298. static merton temp_put_15[300000];
  299. for (sigma=0;sigma<=1 ; sigma+=0.1)
  300. {
  301. for (lambda=0;lambda<=1 ; lambda+=0.1)
  302. {
  303. for (k=0;k<=1 ; k+=0.1)
  304. {
  305. for (s=0;s<=1 ; s+=0.1)
  306. {
  307. for (n=0;n<=VALUE ; n++)
  308. {
  309. double callPrice_1;
  310. double callPrice_2;
  311. double callPrice_3;
  312. double callPrice_4;
  313. double callPrice_5;
  314. double callPrice_6;
  315. double callPrice_7;
  316. double callPrice_8;
  317. double callPrice_9;
  318. double callPrice_10;
  319. double callPrice_11;
  320. double callPrice_12;
  321. double callPrice_13;
  322. double callPrice_14;
  323. double callPrice_15;
  324. double putPrice_1;
  325. double putPrice_2;
  326. double putPrice_3;
  327. double putPrice_4;
  328. double putPrice_5;
  329. double putPrice_6;
  330. double putPrice_7;
  331. double putPrice_8;
  332. double putPrice_9;
  333. double putPrice_10;
  334. double putPrice_11;
  335. double putPrice_12;
  336. double putPrice_13;
  337. double putPrice_14;
  338. double putPrice_15;
  339. callPrice_1 = EuroCall (S , K1 , r , q , T , sigma , lambda , k , s , n );
  340. callPrice_2 = EuroCall (S , K2 , r , q , T , sigma , lambda , k , s , n );
  341. callPrice_3 = EuroCall (S , K3 , r , q , T , sigma , lambda , k , s , n );
  342. callPrice_4 = EuroCall (S , K4 , r , q , T , sigma , lambda , k , s , n );
  343. callPrice_5 = EuroCall (S , K5 , r , q , T , sigma , lambda , k , s , n );
  344. callPrice_6 = EuroCall (S , K6 , r , q , T , sigma , lambda , k , s , n );
  345. callPrice_7 = EuroCall (S , K7 , r , q , T , sigma , lambda , k , s , n );
  346. callPrice_8 = EuroCall (S , K8 , r , q , T , sigma , lambda , k , s , n );
  347. callPrice_9 = EuroCall (S , K9 , r , q , T , sigma , lambda , k , s , n );
  348. callPrice_10 = EuroCall (S , K10 , r , q , T , sigma , lambda , k , s , n );
  349. callPrice_11 = EuroCall (S , K11 , r , q , T , sigma , lambda , k , s , n );
  350. callPrice_12 = EuroCall (S , K12 , r , q , T , sigma , lambda , k , s , n );
  351. callPrice_13 = EuroCall (S , K13 , r , q , T , sigma , lambda , k , s , n );
  352. callPrice_14 = EuroCall (S , K14 , r , q , T , sigma , lambda , k , s , n );
  353. callPrice_15 = EuroCall (S , K15 , r , q , T , sigma , lambda , k , s , n );
  354. putPrice_1 = EuroPut (S , K1 , r , q , T , sigma , lambda , k , s , n );
  355. putPrice_2 = EuroPut (S , K2 , r , q , T , sigma , lambda , k , s , n );
  356. putPrice_3 = EuroPut (S , K3 , r , q , T , sigma , lambda , k , s , n );
  357. putPrice_4 = EuroPut (S , K4 , r , q , T , sigma , lambda , k , s , n );
  358. putPrice_5 = EuroPut (S , K5 , r , q , T , sigma , lambda , k , s , n );
  359. putPrice_6 = EuroPut (S , K6 , r , q , T , sigma , lambda , k , s , n );
  360. putPrice_7 = EuroPut (S , K7 , r , q , T , sigma , lambda , k , s , n );
  361. putPrice_8 = EuroPut (S , K8 , r , q , T , sigma , lambda , k , s , n );
  362. putPrice_9 = EuroPut (S , K9 , r , q , T , sigma , lambda , k , s , n );
  363. putPrice_10 = EuroPut (S , K10 , r , q , T , sigma , lambda , k , s , n );
  364. putPrice_11 = EuroPut (S , K11 , r , q , T , sigma , lambda , k , s , n );
  365. putPrice_12 = EuroPut (S , K12 , r , q , T , sigma , lambda , k , s , n );
  366. putPrice_13 = EuroPut (S , K13 , r , q , T , sigma , lambda , k , s , n );
  367. putPrice_14 = EuroPut (S , K14 , r , q , T , sigma , lambda , k , s , n );
  368. putPrice_15 = EuroPut (S , K15 , r , q , T , sigma , lambda , k , s , n );
  369. f_call_1[n] = callPrice_1;
  370. f_call_2[n] = callPrice_2;
  371. f_call_3[n] = callPrice_3;
  372. f_call_4[n] = callPrice_4;
  373. f_call_5[n] = callPrice_5;
  374. f_call_6[n] = callPrice_6;
  375. f_call_7[n] = callPrice_7;
  376. f_call_8[n] = callPrice_8;
  377. f_call_9[n] = callPrice_9;
  378. f_call_10[n] = callPrice_10;
  379. f_call_11[n] = callPrice_11;
  380. f_call_12[n] = callPrice_12;
  381. f_call_13[n] = callPrice_13;
  382. f_call_14[n] = callPrice_14;
  383. f_call_15[n] = callPrice_15;
  384. f_put_1[n] = putPrice_1;
  385. f_put_2[n] = putPrice_2;
  386. f_put_3[n] = putPrice_3;
  387. f_put_4[n] = putPrice_4;
  388. f_put_5[n] = putPrice_5;
  389. f_put_6[n] = putPrice_6;
  390. f_put_7[n] = putPrice_7;
  391. f_put_8[n] = putPrice_8;
  392. f_put_9[n] = putPrice_9;
  393. f_put_10[n] = putPrice_10;
  394. f_put_11[n] = putPrice_11;
  395. f_put_12[n] = putPrice_12;
  396. f_put_13[n] = putPrice_13;
  397. f_put_14[n] = putPrice_14;
  398. f_put_15[n] = putPrice_15;
  399. }
  400. j = 1 ;
  401. factorial[0] = 1;
  402. for (i=1; i<=VALUE; i++)
  403. {
  404.   j=j*1;
  405.   factorial[i] = j;
  406. }
  407. temp[0] = 1;
  408. for ( i=0; i<VALUE ; i++)
  409. {
  410.   temp[i+1] = ( lambda*(1+k)*T) * temp [i];
  411. }
  412. merton_call_1[0] = exp(-(lambda*(1+k)*T)) * f_call_1[0];
  413. merton_call_2[0] = exp(-(lambda*(1+k)*T)) * f_call_2[0];
  414. merton_call_3[0] = exp(-(lambda*(1+k)*T)) * f_call_3[0];
  415. merton_call_4[0] = exp(-(lambda*(1+k)*T)) * f_call_4[0];
  416. merton_call_5[0] = exp(-(lambda*(1+k)*T)) * f_call_5[0];
  417. merton_call_6[0] = exp(-(lambda*(1+k)*T)) * f_call_6[0];
  418. merton_call_7[0] = exp(-(lambda*(1+k)*T)) * f_call_7[0];
  419. merton_call_8[0] = exp(-(lambda*(1+k)*T)) * f_call_8[0];
  420. merton_call_9[0] = exp(-(lambda*(1+k)*T)) * f_call_9[0];
  421. merton_call_10[0] = exp(-(lambda*(1+k)*T)) * f_call_10[0];
  422. merton_call_11[0] = exp(-(lambda*(1+k)*T)) * f_call_11[0];
  423. merton_call_12[0] = exp(-(lambda*(1+k)*T)) * f_call_12[0];
  424. merton_call_13[0] = exp(-(lambda*(1+k)*T)) * f_call_13[0];
  425. merton_call_14[0] = exp(-(lambda*(1+k)*T)) * f_call_14[0];
  426. merton_call_15[0] = exp(-(lambda*(1+k)*T)) * f_call_15[0];
  427. merton_put_1[0] = exp(-(lambda*(1+k)*T)) * f_put_1[0];
  428. merton_put_2[0] = exp(-(lambda*(1+k)*T)) * f_put_2[0];
  429. merton_put_3[0] = exp(-(lambda*(1+k)*T)) * f_put_3[0];
  430. merton_put_4[0] = exp(-(lambda*(1+k)*T)) * f_put_4[0];
  431. merton_put_5[0] = exp(-(lambda*(1+k)*T)) * f_put_5[0];
  432. merton_put_6[0] = exp(-(lambda*(1+k)*T)) * f_put_6[0];
  433. merton_put_7[0] = exp(-(lambda*(1+k)*T)) * f_put_7[0];
  434. merton_put_8[0] = exp(-(lambda*(1+k)*T)) * f_put_8[0];
  435. merton_put_9[0] = exp(-(lambda*(1+k)*T)) * f_put_9[0];
  436. merton_put_10[0] = exp(-(lambda*(1+k)*T)) * f_put_10[0];
  437. merton_put_11[0] = exp(-(lambda*(1+k)*T)) * f_put_11[0];
  438. merton_put_12[0] = exp(-(lambda*(1+k)*T)) * f_put_12[0];
  439. merton_put_13[0] = exp(-(lambda*(1+k)*T)) * f_put_13[0];
  440. merton_put_14[0] = exp(-(lambda*(1+k)*T)) * f_put_14[0];
  441. merton_put_15[0] = exp(-(lambda*(1+k)*T)) * f_put_15[0];
  442. for (i=0 ; i<VALUE; i++)
  443. {
  444.   merton_call_1[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_1[i+1]) / factorial[i+1]) + merton_call_1[i];
  445.   merton_call_2[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_2[i+1]) / factorial[i+1]) + merton_call_2[i];
  446.   merton_call_3[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_3[i+1]) / factorial[i+1]) + merton_call_3[i];
  447.   merton_call_4[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_4[i+1]) / factorial[i+1]) + merton_call_4[i];
  448.   merton_call_5[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_5[i+1]) / factorial[i+1]) + merton_call_5[i];
  449.   merton_call_6[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_6[i+1]) / factorial[i+1]) + merton_call_6[i];
  450.   merton_call_7[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_7[i+1]) / factorial[i+1]) + merton_call_7[i];
  451.   merton_call_8[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_8[i+1]) / factorial[i+1]) + merton_call_8[i];
  452.   merton_call_9[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_9[i+1]) / factorial[i+1]) + merton_call_9[i];
  453.   merton_call_10[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_10[i+1]) / factorial[i+1]) + merton_call_10[i];
  454.   merton_call_11[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_11[i+1]) / factorial[i+1]) + merton_call_11[i];
  455.   merton_call_12[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_12[i+1]) / factorial[i+1]) + merton_call_12[i];
  456.   merton_call_13[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_13[i+1]) / factorial[i+1]) + merton_call_13[i];
  457.   merton_call_14[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_14[i+1]) / factorial[i+1]) + merton_call_14[i];
  458.   merton_call_15[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_call_15[i+1]) / factorial[i+1]) + merton_call_15[i];
  459.   merton_put_1[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_1[i+1]) / factorial [i+1]) + merton_put_1[i];
  460.   merton_put_2[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_2[i+1]) / factorial [i+1]) + merton_put_2[i];
  461.   merton_put_3[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_3[i+1]) / factorial [i+1]) + merton_put_3[i];
  462.   merton_put_4[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_4[i+1]) / factorial [i+1]) + merton_put_4[i];
  463.   merton_put_5[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_5[i+1]) / factorial [i+1]) + merton_put_5[i];
  464.   merton_put_6[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_6[i+1]) / factorial [i+1]) + merton_put_6[i];
  465.   merton_put_7[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_7[i+1]) / factorial [i+1]) + merton_put_7[i];
  466.   merton_put_8[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_8[i+1]) / factorial [i+1]) + merton_put_8[i];
  467.   merton_put_9[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_9[i+1]) / factorial [i+1]) + merton_put_9[i];
  468.   merton_put_10[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_10[i+1]) / factorial [i+1]) + merton_put_10[i];
  469.   merton_put_11[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_11[i+1]) / factorial [i+1]) + merton_put_11[i];
  470.   merton_put_12[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_12[i+1]) / factorial [i+1]) + merton_put_12[i];
  471.   merton_put_13[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_13[i+1]) / factorial [i+1]) + merton_put_13[i];
  472.   merton_put_14[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_14[i+1]) / factorial [i+1]) + merton_put_14[i];
  473.   merton_put_15[i+1] = ((exp(-(lambda*(1+k)*T)) * temp[i+1] * f_put_15[i+1]) / factorial [i+1]) + merton_put_15[i];
  474.   }
  475. temp_call_1[a].price = merton_call_1[VALUE];
  476. temp_call_1[a].jump_num = lambda;
  477. temp_call_1[a].jump_size = k;
  478. temp_call_1[a].sd = s;
  479. temp_call_1[a].vol = sigma;
  480. temp_call_2[a].price = merton_call_2[VALUE];
  481. temp_call_2[a].jump_num = lambda;
  482. temp_call_2[a].jump_size = k;
  483. temp_call_2[a].sd = s;
  484. temp_call_2[a].vol = sigma;
  485. temp_call_3[a].price = merton_call_3[VALUE];
  486. temp_call_3[a].jump_num = lambda;
  487. temp_call_3[a].jump_size = k;
  488. temp_call_3[a].sd = s;
  489. temp_call_3[a].vol = sigma;
  490. temp_call_4[a].price = merton_call_4[VALUE];
  491. temp_call_4[a].jump_num = lambda;
  492. temp_call_4[a].jump_size = k;
  493. temp_call_4[a].sd = s;
  494. temp_call_4[a].vol = sigma;
  495. temp_call_5[a].price = merton_call_5[VALUE];
  496. temp_call_5[a].jump_num = lambda;
  497. temp_call_5[a].jump_size = k;
  498. temp_call_5[a].sd = s;
  499. temp_call_5[a].vol = sigma;
  500. temp_call_6[a].price = merton_call_6[VALUE];
  501. temp_call_6[a].jump_num = lambda;
  502. temp_call_6[a].jump_size = k;
  503. temp_call_6[a].sd = s;
  504. temp_call_6[a].vol = sigma;
  505. temp_call_7[a].price = merton_call_7[VALUE];
  506. temp_call_7[a].jump_num = lambda;
  507. temp_call_7[a].jump_size = k;
  508. temp_call_7[a].sd = s;
  509. temp_call_7[a].vol = sigma;
  510. temp_call_8[a].price = merton_call_8[VALUE];
  511. temp_call_8[a].jump_num = lambda;
  512. temp_call_8[a].jump_size = k;
  513. temp_call_8[a].sd = s;
  514. temp_call_8[a].vol = sigma;
  515. temp_call_9[a].price = merton_call_9[VALUE];
  516. temp_call_9[a].jump_num = lambda;
  517. temp_call_9[a].jump_size = k;
  518. temp_call_9[a].sd = s;
  519. temp_call_9[a].vol = sigma;
  520. temp_call_10[a].price = merton_call_10[VALUE];
  521. temp_call_10[a].jump_num = lambda;
  522. temp_call_10[a].jump_size = k;
  523. temp_call_10[a].sd = s;
  524. temp_call_10[a].vol = sigma;
  525. temp_call_11[a].price = merton_call_11[VALUE];
  526. temp_call_11[a].jump_num = lambda;
  527. temp_call_11[a].jump_size = k;
  528. temp_call_11[a].sd = s;
  529. temp_call_11[a].vol = sigma;
  530. temp_call_12[a].price = merton_call_12[VALUE];
  531. temp_call_12[a].jump_num = lambda;
  532. temp_call_12[a].jump_size = k;
  533. temp_call_12[a].sd = s;
  534. temp_call_12[a].vol = sigma;
  535. temp_call_13[a].price = merton_call_13[VALUE];
  536. temp_call_13[a].jump_num = lambda;
  537. temp_call_13[a].jump_size = k;
  538. temp_call_13[a].sd = s;
  539. temp_call_13[a].vol = sigma;
  540. temp_call_14[a].price = merton_call_14[VALUE];
  541. temp_call_14[a].jump_num = lambda;
  542. temp_call_14[a].jump_size = k;
  543. temp_call_14[a].sd = s;
  544. temp_call_14[a].vol = sigma;
  545. temp_call_15[a].price = merton_call_15[VALUE];
  546. temp_call_15[a].jump_num = lambda;
  547. temp_call_15[a].jump_size = k;
  548. temp_call_15[a].sd = s;
  549. temp_call_15[a].vol = sigma;
  550. temp_put_1[a].price = merton_put_1[VALUE];
  551. temp_put_1[a].jump_num = lambda;
  552. temp_put_1[a].jump_size = k;
  553. temp_put_1[a].sd = s;
  554. temp_put_1[a].vol = sigma;
  555. temp_put_2[a].price = merton_put_2[VALUE];
  556. temp_put_2[a].jump_num = lambda;
  557. temp_put_2[a].jump_size = k;
  558. temp_put_2[a].sd = s;
  559. temp_put_2[a].vol = sigma;
  560. temp_put_3[a].price = merton_put_3[VALUE];
  561. temp_put_3[a].jump_num = lambda;
  562. temp_put_3[a].jump_size = k;
  563. temp_put_3[a].sd = s;
  564. temp_put_3[a].vol = sigma;
  565. temp_put_4[a].price = merton_put_4[VALUE];
  566. temp_put_4[a].jump_num = lambda;
  567. temp_put_4[a].jump_size = k;
  568. temp_put_4[a].sd = s;
  569. temp_put_4[a].vol = sigma;
  570. temp_put_5[a].price = merton_put_5[VALUE];
  571. temp_put_5[a].jump_num = lambda;
  572. temp_put_5[a].jump_size = k;
  573. temp_put_5[a].sd = s;
  574. temp_put_5[a].vol = sigma;
  575. temp_put_6[a].price = merton_put_6[VALUE];
  576. temp_put_6[a].jump_num = lambda;
  577. temp_put_6[a].jump_size = k;
  578. temp_put_6[a].sd = s;
  579. temp_put_6[a].vol = sigma;
  580. temp_put_7[a].price = merton_put_7[VALUE];
  581. temp_put_7[a].jump_num = lambda;
  582. temp_put_7[a].jump_size = k;
  583. temp_put_7[a].sd = s;
  584. temp_put_7[a].vol = sigma;
  585. temp_put_8[a].price = merton_put_8[VALUE];
  586. temp_put_8[a].jump_num = lambda;
  587. temp_put_8[a].jump_size = k;
  588. temp_put_8[a].sd = s;
  589. temp_put_8[a].vol = sigma;
  590. temp_put_9[a].price = merton_put_9[VALUE];
  591. temp_put_9[a].jump_num = lambda;
  592. temp_put_9[a].jump_size = k;
  593. temp_put_9[a].sd = s;
  594. temp_put_9[a].vol = sigma;
  595. temp_put_10[a].price = merton_put_10[VALUE];
  596. temp_put_10[a].jump_num = lambda;
  597. temp_put_10[a].jump_size = k;
  598. temp_put_10[a].sd = s;
  599. temp_put_10[a].vol = sigma;
  600. temp_put_11[a].price = merton_put_11[VALUE];
  601. temp_put_11[a].jump_num = lambda;
  602. temp_put_11[a].jump_size = k;
  603. temp_put_11[a].sd = s;
  604. temp_put_11[a].vol = sigma;
  605. temp_put_12[a].price = merton_put_12[VALUE];
  606. temp_put_12[a].jump_num = lambda;
  607. temp_put_12[a].jump_size = k;
  608. temp_put_12[a].sd = s;
  609. temp_put_12[a].vol = sigma;
  610. temp_put_13[a].price = merton_put_13[VALUE];
  611. temp_put_13[a].jump_num = lambda;
  612. temp_put_13[a].jump_size = k;
  613. temp_put_13[a].sd = s;
  614. temp_put_13[a].vol = sigma;
  615. temp_put_14[a].price = merton_put_14[VALUE];
  616. temp_put_14[a].jump_num = lambda;
  617. temp_put_14[a].jump_size = k;
  618. temp_put_14[a].sd = s;
  619. temp_put_14[a].vol = sigma;
  620. temp_put_15[a].price = merton_put_15[VALUE];
  621. temp_put_15[a].jump_num = lambda;
  622. temp_put_15[a].jump_size = k;
  623. temp_put_15[a].sd = s;
  624. temp_put_15[a].vol = sigma;
  625.   a++;
  626.   }
  627.  
  628.   }
  629.  
  630.   }
  631.   }
  632. min_call = 9999; // sum of the square difference of Merton's call
  633. min_put = 9999; // sum of the square difference of Merton's put
  634. min_sum = 9999; // total sum of sum of least square difference for both Merton's call and put
  635. for (i=0 ; i<a ; i++)
  636. {
  637.   for (h=0; h<a ; i++)
  638.   {
  639.     if ((temp_call_1[i].vol == temp_put_1[h].vol) && (temp_call_1[i].jump_num == temp_put_1[h].jump_num)
  640.       && (temp_call_1[i].jump_size == temp_put_1[h].jump_size) && (temp_call_1[i].sd = temp_put_1[h].sd))
  641.   {
  642.     temp_min_call = (( temp_call_1[i].price - market_call_1) * (temp_call_1[i].price - market_call_1))
  643.     + ((temp_call_2[i].price - market_call_2) * (temp_call_2[i].price - market_call_2))
  644.     + ((temp_call_3[i].price - market_call_3) * (temp_call_3[i].price - market_call_3))
  645.     + ((temp_call_4[i].price - market_call_4) * (temp_call_4[i].price - market_call_4))
  646.     + ((temp_call_5[i].price - market_call_5) * (temp_call_5[i].price - market_call_5))
  647.     + ((temp_call_6[i].price - market_call_6) * (temp_call_6[i].price - market_call_6))
  648.     + ((temp_call_7[i].price - market_call_7) * (temp_call_7[i].price - market_call_7))
  649.     + ((temp_call_8[i].price - market_call_8) * (temp_call_8[i].price - market_call_8))
  650.     + ((temp_call_9[i].price - market_call_9) * (temp_call_9[i].price - market_call_9))
  651.     + ((temp_call_10[i].price - market_call_10) * (temp_call_10[i].price - market_call_10))
  652.     + ((temp_call_11[i].price - market_call_11) * (temp_call_11[i].price - market_call_11))
  653.     + ((temp_call_12[i].price - market_call_12) * (temp_call_12[i].price - market_call_12))
  654.     + ((temp_call_13[i].price - market_call_13) * (temp_call_13[i].price - market_call_13))
  655.     + ((temp_call_14[i].price - market_call_14) * (temp_call_14[i].price - market_call_14))
  656.     + ((temp_call_15[i].price - market_call_15) * (temp_call_15[i].price - market_call_15));
  657.     temp_min_put = (( temp_put_1[h].price - market_put_1) * (temp_put_1[h].price - market_put_1))
  658.     + ((temp_put_2[h].price - market_put_2) * (temp_call_2[h].price - market_put_2))
  659.     + ((temp_put_3[h].price - market_put_3) * (temp_call_2[h].price - market_put_3))
  660.     + ((temp_put_4[h].price - market_put_4) * (temp_call_2[h].price - market_put_4))
  661.     + ((temp_put_5[h].price - market_put_5) * (temp_call_2[h].price - market_put_5))
  662.     + ((temp_put_6[h].price - market_put_6) * (temp_call_2[h].price - market_put_6))
  663.     + ((temp_put_7[h].price - market_put_7) * (temp_call_2[h].price - market_put_7))
  664.     + ((temp_put_8[h].price - market_put_8) * (temp_call_2[h].price - market_put_8))
  665.     + ((temp_put_9[h].price - market_put_9) * (temp_call_2[h].price - market_put_9))
  666.     + ((temp_put_10[h].price - market_put_10) * (temp_call_2[h].price - market_put_10))
  667.     + ((temp_put_11[h].price - market_put_11) * (temp_call_2[h].price - market_put_11))
  668.     + ((temp_put_12[h].price - market_put_12) * (temp_call_2[h].price - market_put_12))
  669.     + ((temp_put_13[h].price - market_put_13) * (temp_call_2[h].price - market_put_13))
  670.     + ((temp_put_14[h].price - market_put_14) * (temp_call_2[h].price - market_put_14))
  671.     + ((temp_put_15[h].price - market_put_15) * (temp_call_2[h].price - market_put_15));
  672.     if ((temp_min_call+temp_min_put) < min_sum)
  673.     {
  674.       min_sum = (temp_min_call+temp_min_put);
  675.       min_call = temp_min_call;
  676.       min_i_call = i;
  677.       min_put = temp_min_put;
  678.       min_h_put = h;
  679.     }
  680.     }
  681.   }
  682. }
  683. cout << "Volatility fixed number Merton's model: " << temp_call_1[min_i_call].vol << endl;
  684. cout << "Jump number: " << temp_call_1[min_i_call].jump_num << endl;
  685. cout << "Jump size: " << temp_call_1[min_i_call].jump_size << endl;
  686. cout << "Standard deviation of normal distribution: " << temp_call_1[min_i_call].sd << endl;
  687. cout << endl;
  688. cout << "Merton's European call price 1: " << temp_call_1[min_i_call].price << endl;
  689. cout << "Merton's European call price 2: " << temp_call_2[min_i_call].price << endl;
  690. cout << "Merton's European call price 3: " << temp_call_3[min_i_call].price << endl;
  691. cout << "Merton's European call price 4: " << temp_call_4[min_i_call].price << endl;
  692. cout << "Merton's European call price 5: " << temp_call_5[min_i_call].price << endl;
  693. cout << "Merton's European call price 6: " << temp_call_6[min_i_call].price << endl;
  694. cout << "Merton's European call price 7: " << temp_call_7[min_i_call].price << endl;
  695. cout << "Merton's European call price 8: " << temp_call_8[min_i_call].price << endl;
  696. cout << "Merton's European call price 9: " << temp_call_9[min_i_call].price << endl;
  697. cout << "Merton's European call price 10: " << temp_call_10[min_i_call].price << endl;
  698. cout << "Merton's European call price 11: " << temp_call_11[min_i_call].price << endl;
  699. cout << "Merton's European call price 12: " << temp_call_12[min_i_call].price << endl;
  700. cout << "Merton's European call price 13: " << temp_call_13[min_i_call].price << endl;
  701. cout << "Merton's European call price 14: " << temp_call_14[min_i_call].price << endl;
  702. cout << "Merton's European call price 15: " << temp_call_15[min_i_call].price << endl;
  703. cout << "Sum of least square difference between Merton's call and Market call: " << min_call << endl;
  704. cout << endl;
  705. cout << "Merton's European put price 1: " << temp_put_1[min_h_put].price << endl;
  706. cout << "Merton's European put price 2: " << temp_put_2[min_h_put].price << endl;
  707. cout << "Merton's European put price 3: " << temp_put_3[min_h_put].price << endl;
  708. cout << "Merton's European put price 4: " << temp_put_4[min_h_put].price << endl;
  709. cout << "Merton's European put price 5: " << temp_put_5[min_h_put].price << endl;
  710. cout << "Merton's European put price 6: " << temp_put_6[min_h_put].price << endl;
  711. cout << "Merton's European put price 7: " << temp_put_7[min_h_put].price << endl;
  712. cout << "Merton's European put price 8: " << temp_put_8[min_h_put].price << endl;
  713. cout << "Merton's European put price 9: " << temp_put_9[min_h_put].price << endl;
  714. cout << "Merton's European put price 10: " << temp_put_10[min_h_put].price << endl;
  715. cout << "Merton's European put price 11: " << temp_put_11[min_h_put].price << endl;
  716. cout << "Merton's European put price 12: " << temp_put_12[min_h_put].price << endl;
  717. cout << "Merton's European put price 13: " << temp_put_13[min_h_put].price << endl;
  718. cout << "Merton's European put price 14: " << temp_put_14[min_h_put].price << endl;
  719. cout << "Merton's European put price 15: " << temp_put_15[min_h_put].price << endl;
  720. cout << "Sum of least square difference between Merton's put and Market put: " << min_put << endl;
  721. cout << endl;
  722. //Wait for the user to read the output on the console
  723. system("PAUSE");
  724. return 0;
  725. }
  726. double EuroCall(double S,double K,double r,double q,double T,double sig_call,double lambda,double k,double s,int n)
  727. {
  728.     double d1,d2;
  729.     double new_sig;
  730.     double new_r;
  731.     double new_var;
  732.     new_var = sig_call*sig_call + n*s*s / T;
  733.     new_sig = sqrt(new_var);
  734.     new_r = r - lambda*k + n*log(1+k) / T;
  735.    
  736.     d1 = (log(S/K) + (new_r-q+(new_sig*new_sig)*0.5 ) * T ) / (new_sig*sqrt(T));
  737.     d2 = d1 - new_sig*sqrt(T);
  738.     return S*exp(-q*T)*N(d1) - K*exp(-new_r*T)*N(d2);
  739. }
  740. double EuroPut(double S,double K,double r, double q,double T,double sig_put,double lambda,double k,double s,int n)
  741. {
  742.     double d1,d2;
  743.     double new_sig;
  744.     double new_r;
  745.     double new_var;
  746.     new_var = sig_put*sig_put + n*s*s / T;
  747.     new_sig = sqrt(new_var);
  748.     new_r = r - lambda*k + n*log(1+k) / T;
  749.    
  750.     d1 = (log(S/K) + (new_r-q+(new_sig*new_sig)*0.5 ) * T ) / (new_sig*sqrt(T));
  751.     d2 = d1 - new_sig*sqrt(T);
  752.     return K*exp(-new_r*T)*N(-d2) - S*exp(-q*T)*N(-d1);
  753. }
  754. double NP(double x)
  755. {
  756.     return (1.0/sqrt(2.0 * 3.1415)* exp(-x*x*0.5));
  757. }
  758. double N(double x)
  759. {
  760.     double a1 = 0.319381530;
  761.     double a2 = -0.356563782;
  762.     double a3 = 1.781477937;
  763.     double a4 = -1.821255978;
  764.     double a5 = 1.330274429;
  765.     double k;
  766.     k = 1/(1+0.2316419*x);
  767.     if ( x >= 0.0)
  768.     {
  769.       return(1-NP(x)*((a1*k) + (a2*k*k) + (a3*k*k*k) + (a4*k*k*k*k) + (a5*k*k*k*k*k)));
  770.     }
  771.     else
  772.     {
  773.       return (1-N(-x));
  774.     }
  775. }
[ 本文被雲佬~~SY在2011-04-16 20:34重新編輯 ]
離線reve
發帖
55251
好友元
7186
閱讀權限
55251
貢獻值
2
只看該作者 3  發表于: 2011-04-15
外星文應該直接搵桶笑啦!
keep walking, keep scoring, let's do it again!!! YNWA
離線PonG
發帖
38500
好友元
116168
閱讀權限
38500
貢獻值
2
只看該作者 4  發表于: 2011-04-15
i am sick ....

死左係邊, breakpt CHECK 唔check 到
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 5  發表于: 2011-04-15
引用第3樓reve2011-04-15 01:13發表的“”:
外星文應該直接搵桶笑啦! [表情] [表情] [表情] [表情] [表情]


桶少都愛莫能助..所以先要各大好友出手相助呀..
離線智者
發帖
14653
好友元
46535
閱讀權限
37357
貢獻值
2
只看該作者 6  發表于: 2011-04-15
你問人都要有題目架
  
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 7  發表于: 2011-04-15
引用第4樓→※Pong※←2011-04-15 01:16發表的“”:
i am sick ....
死左係邊, breakpt CHECK 唔check 到 [表情]


死係d for-loop 到..

pong 妹 你得唔得閒用visual studio 開黎睇下/.

2個program係run到的,但中間d for-loop 就死左.
離線PonG
發帖
38500
好友元
116168
閱讀權限
38500
貢獻值
2
只看該作者 8  發表于: 2011-04-15
引用第7樓雲佬~~SY2011-04-15 01:19發表的“”:
死係d for-loop 到..
pong 妹 [表情] [表情] 你得唔得閒用visual studio 開黎睇下/.
.......

#include "stdafx.h" < 係邊
離線PonG
發帖
38500
好友元
116168
閱讀權限
38500
貢獻值
2
只看該作者 9  發表于: 2011-04-15
你唔趕我聽朝幫你睇睇, but 我D PROGRAM 幾差你都知, 同埋我唔識C++  
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 10  發表于: 2011-04-15
引用第8樓→※Pong※←2011-04-15 01:22發表的“”:
#include "stdafx.h" < 係邊


你有冇VISUAL STUDIO?
咁你直接開個NEW PROJECT,跟住揀WIN32,再跟住就唔好PRESS EMPTY PROJECT , PRESS CONSOLE, 之後就有依個FILE 架LA
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 11  發表于: 2011-04-15
引用第9樓→※Pong※←2011-04-15 01:23發表的“”:
你唔趕我聽朝幫你睇睇, but 我D PROGRAM 幾差你都知, 同埋我唔識C++   [表情]


其實聽日都OK.的..都係D NESTED FOR-LOOP GE 問題..
唔知係咪D 擺位問題..

攪左好耐都係唔得.

BTW, 都THZ

第一個PROGRAM要留意依(其實):

for(vol=1;vol<500;vol++)
{
for(alpha=1;alpha<300;alpha++)
{
    for (i=0;i<VALUE;i++)
    {
    K.cv=((vol*vol/10000)/(2*(r-q)*(alpha/100-1)))*(exp(2*(r-q)*(alpha/100-1)*T)-1);
    K.pv=((vol*vol/10000)/(2*(r-q)*(alpha/100-1)))*(exp(2*(r-q)*(alpha/100-1)*T)-1);
    K.ca=pow((K.strike*exp (-(r-q)*T)),(2*(1-alpha/100)))/(((1-alpha)*(1-alpha))*K.cv);
    K.pa=pow((K.strike*exp (-(r-q)*T)),(2*(1-alpha/100)))/(((1-alpha)*(1-alpha))*K.pv);
    K.b=1/(1-alpha/100);
    K.cc=pow(S,2*(1-alpha/100))/(((1-alpha)*(1-alpha))*K.cv);
    K.pc=pow(S,2*(1-alpha/100))/(((1-alpha)*(1-alpha))*K.pv);
    };

    for(int i=0;i<VALUE;i++)
    { if(alpha/100<1)
    {
    K.ctz=K.ca ;
    K.ctk=K.b + 2 ;
    K.ctv=K.cc ;
    K.ctz1=K.cc ;
    K.ctk1=K.b ;
    K.ctv1=K.ca ;
    K.ptz=K.pc ;
    K.ptk=K.b ;
    K.ptv=K.pa ;
    K.ptz1=K.pa ;
    K.ptk1=K.b+2 ;
    K.ptv1=K.pc ;
    }
    else {
    K.ctz=K.cc ;
    K.ctk=-K.b ;
    K.ctv=K.ca ;
    K.ctz1=K.ca ;
    K.ctk1=2-K.b ;
    K.ctv1=K.cc ;
    K.ptz=K.pa ;
    K.ptk=2-K.b ;
    K.ptv=K.pc ;
    K.ptz1=K.pc ;
    K.ptk1=K.b ;
    K.ptv1=K.pa ;}

    gamma_x=K.ctk/2+1;
    temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
    gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
    tmp=chisquare(K.ctz,K.ctk,K.ctv,gamma);
    K.cchisq=tmp;
    gamma_x=K.ctk1/2+1;
    temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
    gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
    tmp=chisquare(K.ctz1,K.ctk1,K.ctv1,gamma);
    K.cchisq1=tmp;
    gamma_x=K.ptk/2+1;
    temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
    gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
    tmp=chisquare(K.ptz,K.ptk,K.ptv,gamma);
    K.pchisq1=tmp;
    gamma_x=K.ptk1/2+1;
    temp=p0+p1/(gamma_x+1)+p2/(gamma_x+2)+p3/(gamma_x+3)+p4/(gamma_x+4)+p5/(gamma_x+5)+p6/(gamma_x+6);
    gamma=(sqrt(2*3.1452)/gamma_x)*temp*(pow(gamma_x+5.5,gamma_x+0.5))*exp(-(gamma_x+5.5));
    tmp=chisquare(K.ptz1,K.ptk1,K.ptv1,gamma);
    K.pchisq=tmp;

    K.cp=S*exp(-q*T)*(1-K.cchisq)-K.strike*exp(-r*T)*K.cchisq1;
    K.pp=K.strike*exp(-r*T)*(1-K.pchisq1)-S*exp(-q*T)*K.pchisq;

    };

    xx=0;
    zz=0;

    for(int i=0;i<VALUE;i++)
    {   //xx==0;
    xx=xx+(pow(K.cp-K.cmp,2))+pow(K.pp-K.pmp,2);
    };
    if(xx<min)
    {min=xx;
    minalpha=alpha/100;
    minvol=vol/100;
    }

}//for loop(alpha)
}//for loop(vol)

cout<<"Summation of the least square test :"<<min<<endl;
cout<<"Corresponding alpha:"<<minalpha<<endl;
cout<<"Corresponding sigma:"<<minvol<<endl;
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 12  發表于: 2011-04-15
第2個PROGRAM 其實主要都係依5個FOR-LOOP睇下有冇問題:

for (sigma=0;sigma<=1 ; sigma+=0.1)

{

for (lambda=0;lambda<=1 ; lambda+=0.1)

{

for (k=0;k<=1 ; k+=0.1)

{

for (s=0;s<=1 ; s+=0.1)

{

for (n=0;n<=VALUE ; n++)
{

離線煙花
發帖
37458
好友元
377091
閱讀權限
37458
貢獻值
3
只看該作者 13  發表于: 2011-04-15
用戶被禁言,該主題自動屏蔽!
離線雲佬~~SY
發帖
12285
好友元
35671
閱讀權限
12308
貢獻值
0
只看該作者 14  發表于: 2011-04-15
引用第13樓煙花2011-04-15 01:31發表的“”:
[表情] [表情]
我睇完....其實....想講........
.......


明白的..PROGRAMMING D 野唔係正常人所能明白的..