查看完整版本: [-- PROGRAMMING 難題 (厚酬: 50000x2=100000好友元)(URGENT!!)(最主要都係睇NESTED FOR-LOOP!!) --]

【好友論壇】- 以足球會好友 -> 【學術交流】 -> PROGRAMMING 難題 (厚酬: 50000x2=100000好友元)(URGENT!!)(最主要都係睇NESTED FOR-LOOP!!) [打印本頁] 登錄 -> 注冊 -> 回復主題 -> 發表主題

雲佬~~SY 2011-04-15 01:03

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

是咁的,小弟有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-15 01:04
第一個program: (PROGRAM1 GESOURCE CODE)

  1. // CEV4_14.cpp : Defines the entry point for the console application.

    #include "stdafx.h"
    #include <fstream>
    #include <iostream>
    #include <math.h>
    #include <string>
    using namespace std;

    class price
    {
    public:
          double strike;
          double ca;
          double pa;
          double b;
          double cc;
          double pc;
          double cv;
          double pv;
          double ctz;
          double ctk;
          double ctv;
          double ctz1;
          double ctk1;
          double ctv1;
          double ptz;
          double ptk;
          double ptv;
          double ptz1;
          double ptk1;
          double ptv1;
          double cchisq;
          double cchisq1;
          double pchisq;
          double pchisq1;
          double cp;
          double pp;
          double cmp;
          double pmp;
    };

    double chisquare(double a,double b,double c,double d)
    {
          double x=0;
          double t[1500],w[1500],u[1500];
          t[0]=((1/d))*(pow(a/2,b/2))*exp(-a/2);
          u[0]=exp(-c/2);
          w[0]=exp(-c/2);
          x=w[0]*t[0];
          for(int y=1;y<1500;y++)
              {
                t[y]=t[y-1]*(a/(b+2*y));
                u[y]=u[y-1]*c/(2*y);
                w[y]=w[y-1]+u[y];
                x=x+w[y]*t[y];
                }
          return x;
    }


    int main(int argc, char** argv)
    {
    double S;
    double r,q,T;
    int alpha;
    int vol;
    double command;
    int i, VALUE=0;
    double p0=1, p1=76.18009173 , p2=-86.50532033 , p3=24.01409824;
    double p4=-1.231739572, p5=0.001208651, p6=-0.00000539524;
    double gamma_x, gamma, temp ;
    double tmp;
    double xx=0 , min=10000 , minalpha , minvol ;
    double zz=0 , min1=10000;
    cout << "Enter spot price:" << endl;
    cin >> command;
    S = command;
    cout << "Enter risk-free rate:" << endl;
    cin >> command;
    r = command;
    cout << "Enter dividend yield:" << endl;
    cin >> command;
    q = command;
    cout << "Enter period of maturity:" << endl;
    cin >> command;
    T = command;
    price K[30];
    i = 0;
    while (i==0)
    {
      cout << "Enter strike price: (enter 9999 if there is no more strike price) " << endl;
      cin >> command;
    if (command<9999)
      {
        K[VALUE].strike = command;
        cout << "Enter put options' market price" << endl;
        cin >> command;
        K[VALUE].pmp = command;
        cout << "Enter call options' market price" << endl;
        cin >> command;
        K[VALUE].cmp = command;
        VALUE++;
      }
    else            
    {i=1;}
    }





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

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

            gamma_x=K[i].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[i].ctz,K[i].ctk,K[i].ctv,gamma);
            K[i].cchisq=tmp;
            gamma_x=K[i].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[i].ctz1,K[i].ctk1,K[i].ctv1,gamma);
            K[i].cchisq1=tmp;
            gamma_x=K[i].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[i].ptz,K[i].ptk,K[i].ptv,gamma);
            K[i].pchisq1=tmp;
            gamma_x=K[i].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[i].ptz1,K[i].ptk1,K[i].ptv1,gamma);
            K[i].pchisq=tmp;

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

          };

            xx=0;
            zz=0;

          for(int i=0;i<VALUE;i++)
          {   //xx==0;
            xx=xx+(pow(K[i].cp-K[i].cmp,2))+pow(K[i].pp-K[i].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;

    alpha=minalpha;
    vol=minvol;
    /*
    for (i=0;i<VALUE;i++)
    {
      K[i].cv=((vol*vol)/(2*(r-q)*(alpha-1)))*(exp(2*(r-q)*(alpha-1)*T)-1);
      K[i].pv=((vol*vol)/(2*(r-q)*(alpha-1)))*(exp(2*(r-q)*(alpha-1)*T)-1);
      K[i].ca=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha)))/((pow(1-alpha,2))*K[i].cv);
      K[i].pa=pow((K[i].strike*exp (-(r-q)*T)),(2*(1-alpha)))/((pow(1-alpha,2))*K[i].pv);
      K[i].b=1/(1-alpha);
      K[i].cc=pow (S,2*(1-alpha))/(pow((1-alpha),2)*K[i].cv);
      K[i].pc=pow (S,2*(1-alpha))/(pow((1-alpha),2)*K[i].pv);
    }
    for(i=0;i<VALUE;i++)
    { if(alpha<1)
    {
      K[i].ctz=K[i].ca ;
      K[i].ctk=K[i].b + 2 ;
      K[i].ctv=K[i].cc ;
      K[i].ctz1=K[i].cc ;
      K[i].ctk1=K[i].b ;
      K[i].ctv1=K[i].ca ;
      K[i].ptz=K[i].pc ;
      K[i].ptk=K[i].b ;
      K[i].ptv=K[i].pa ;
      K[i].ptz1=K[i].pa ;
      K[i].ptk1=K[i].b+2 ;
      K[i].ptv1=K[i].pc ;
    }
    else {

      K[i].ctz=K[i].cc ;
      K[i].ctk=-K[i].b ;
      K[i].ctv=K[i].ca ;
      K[i].ctz1=K[i].ca ;
      K[i].ctk1=2-K[i].b ;
      K[i].ctv1=K[i].cc ;
      K[i].ptz=K[i].pa ;
      K[i].ptk=2-K[i].b ;
      K[i].ptv=K[i].pc ;
      K[i].ptz1=K[i].pc ;
      K[i].ptk1=K[i].b ;
      K[i].ptv1=K[i].pa ; }

    gamma_x=K[i].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[i].ctz,K[i].ctk,K[i].ctv,gamma);
    K[i].cchisq=tmp;
    gamma_x=K[i].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[i].ctz1,K[i].ctk1,K[i].ctv1,gamma);
    K[i].cchisq1=tmp;
    gamma_x=K[i].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[i].ptz,K[i].ptk,K[i].ptv,gamma);
    K[i].pchisq1=tmp;
    gamma_x=K[i].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[i].ptz1,K[i].ptk1,K[i].ptv1,gamma);
    K[i].pchisq=tmp;

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

    }*/

    for(int i=0;i<VALUE;i++)
    {   cout << "For Strike Price =" << K[i].strike << ", call price ="<<K[i].cp<<endl;
      cout << "For Strike Price =" << K[i].strike << ", put price ="<<K[i].pp<<endl;
      }

    return (0);
    }

雲佬~~SY 2011-04-15 01:07
第2個program:(SOURCE CODE)





  1. // jd41414141.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    #include <math.h>
    using namespace std ;
    //#undef main

    double EuroCall(double S,double K,double r,double q,double T,double sig_call,double lambda,double k,double s,int n);
    double EuroPut(double S,double K,double r, double q,double T,double sig_put,double lambda,double k,double s,int n);
    double NP(double x);
    double N(double x);

    int main(int argc, char** argv)
    {
    double S;     // price of stock or underlying security
    double K1;     // strike price
    double K2;
    double K3;
    double K4;
    double K5;
    double K6;
    double K7;
    double K8;
    double K9;
    double K10;
    double K11;
    double K12;
    double K13;
    double K14;
    double K15;
    double r;     // interest rate
    double q;     // divident yield
    double T;     // reminding life
    double sigma;   // fixed voltility
    double lambda; // average number of jumps per year
    double k;     // average jump sizw measured as a percentage of the asset price
    double s;     // stardard deviation of the normal distribution for logarithm of the size of the percentage jump
    int n ;
    int VALUE = 30 ; // number of iteration

    double market_call_1;
    double market_call_2;
    double market_call_3;
    double market_call_4;
    double market_call_5;
    double market_call_6;
    double market_call_7;
    double market_call_8;
    double market_call_9;
    double market_call_10;
    double market_call_11;
    double market_call_12;
    double market_call_13;
    double market_call_14;
    double market_call_15;

    double market_put_1;
    double market_put_2;
    double market_put_3;
    double market_put_4;
    double market_put_5;
    double market_put_6;
    double market_put_7;
    double market_put_8;
    double market_put_9;
    double market_put_10;
    double market_put_11;
    double market_put_12;
    double market_put_13;
    double market_put_14;
    double market_put_15;

    cout << " Enter spot price :" << endl;
    cin >> S;
    cout << " Enter risk-free rate :" << endl;
    cin >> r;
    cout << " Enter dividend yield :" << endl;
    cin >> q;
    cout << " Enter period of maturity :" << endl;
    cin >> T;
    cout << endl;
    cout << " Enter 15 strike prices with corresponding market call and put prices:" << endl ;

    cout << endl;

    cout << " Enter strike price 1 :" <<endl;
    cin >> K1;
    cout << " Enter call option 1 market price :" <<endl;
    cin >> market_call_1;
    cout << " Enter put option market price :" <<endl;
    cin >> market_put_1;

    cout << endl;

    cout << " Enter strike price 2 :" <<endl;
    cin >> K2;
    cout << " Enter call option 2 market price :" <<endl;
    cin >> market_call_2;
    cout << " Enter put option 2 market price :" <<endl;
    cin >> market_put_2;

    cout << endl;

    cout << " Enter strike price 3:" <<endl;
    cin >> K3;
    cout << " Enter call option 3 market price :" <<endl;
    cin >> market_call_3;
    cout << " Enter put option 3 market price :" <<endl;
    cin >> market_put_3;

    cout << endl;

    cout << " Enter strike price 4 :" <<endl;
    cin >> K4;
    cout << " Enter call option 4 market price :" <<endl;
    cin >> market_call_4;
    cout << " Enter put option 4 market price :" <<endl;
    cin >> market_put_4;

    cout << endl;

    cout << " Enter strike price 5 :" <<endl;
    cin >> K5;
    cout << " Enter call option 5 market price :" <<endl;
    cin >> market_call_5;
    cout << " Enter put option 5 market price :" <<endl;
    cin >> market_put_5;

    cout << endl;

    cout << " Enter strike price 6 :" <<endl;
    cin >> K6;
    cout << " Enter call option 6 market price :" <<endl;
    cin >> market_call_6;
    cout << " Enter put option 6 market price :" <<endl;
    cin >> market_put_6;

    cout << endl;

    cout << " Enter strike price 7 :" <<endl;
    cin >> K7;
    cout << " Enter call option 7 market price :" <<endl;
    cin >> market_call_7;
    cout << " Enter put option 7 market price :" <<endl;
    cin >> market_put_7;

    cout << endl;

    cout << " Enter strike price 8 :" <<endl;
    cin >> K8;
    cout << " Enter call option 8 market price :" <<endl;
    cin >> market_call_8;
    cout << " Enter put option 8 market price :" <<endl;
    cin >> market_put_8;

    cout << endl;

    cout << " Enter strike price 9 :" <<endl;
    cin >> K9;
    cout << " Enter call option 9 market price :" <<endl;
    cin >> market_call_9;
    cout << " Enter put option 9 market price :" <<endl;
    cin >> market_put_9;

    cout << endl;

    cout << " Enter strike price 10:" <<endl;
    cin >> K10;
    cout << " Enter call option 10 market price :" <<endl;
    cin >> market_call_10;
    cout << " Enter put option 10 market price :" <<endl;
    cin >> market_put_10;

    cout << endl;

    cout << " Enter strike price 11 :" <<endl;
    cin >> K11;
    cout << " Enter call option 11 market price :" <<endl;
    cin >> market_call_11;
    cout << " Enter put option 11 market price :" <<endl;
    cin >> market_put_11;

    cout << endl;

    cout << " Enter strike price 12 :" <<endl;
    cin >> K12;
    cout << " Enter call option 12 market price :" <<endl;
    cin >> market_call_12;
    cout << " Enter put option 12 market price :" <<endl;
    cin >> market_put_12;

    cout << endl;

    cout << " Enter strike price 13 :" <<endl;
    cin >> K13;
    cout << " Enter call option 13 market price :" <<endl;
    cin >> market_call_13;
    cout << " Enter put option 13 market price :" <<endl;
    cin >> market_put_13;

    cout << endl;

    cout << " Enter strike price 14 :" <<endl;
    cin >> K14;
    cout << " Enter call option 14 market price :" <<endl;
    cin >> market_call_14;
    cout << " Enter put option 14 market price :" <<endl;
    cin >> market_put_14;

    cout << endl;

    cout << " Enter strike price 15 :" <<endl;
    cin >> K15;
    cout << " Enter call option 15 market price :" <<endl;
    cin >> market_call_15;
    cout << " Enter put option 15 market price :" <<endl;
    cin >> market_put_15;

    cout << endl;

    cout<<"In progress ... "<< endl;
    cout << endl;

    int a=0;

    double temp_min_call;
    double temp_min_put;
    double min_call;
    double min_put;
    double min_sum;

    int min_i_call;
    int min_h_put;

    int h;
    int i;
    int j;
    static int factorial[300000];
    static double temp[300000];

    static double f_call_1[300000];
    static double f_call_2[300000];
    static double f_call_3[300000];
    static double f_call_4[300000];
    static double f_call_5[300000];
    static double f_call_6[300000];
    static double f_call_7[300000];
    static double f_call_8[300000];
    static double f_call_9[300000];
    static double f_call_10[300000];
    static double f_call_11[300000];
    static double f_call_12[300000];
    static double f_call_13[300000];
    static double f_call_14[300000];
    static double f_call_15[300000];

    static double f_put_1[300000];
    static double f_put_2[300000];
    static double f_put_3[300000];
    static double f_put_4[300000];
    static double f_put_5[300000];
    static double f_put_6[300000];
    static double f_put_7[300000];
    static double f_put_8[300000];
    static double f_put_9[300000];
    static double f_put_10[300000];
    static double f_put_11[300000];
    static double f_put_12[300000];
    static double f_put_13[300000];
    static double f_put_14[300000];
    static double f_put_15[300000];

    class merton
    {
    public :
      double price;
      double jump_num;  
      double jump_size;  
      double sd;
      double vol;
    };


    static double merton_call_1[300000];
    static double merton_call_2[300000];
    static double merton_call_3[300000];
    static double merton_call_4[300000];
    static double merton_call_5[300000];
    static double merton_call_6[300000];
    static double merton_call_7[300000];
    static double merton_call_8[300000];
    static double merton_call_9[300000];
    static double merton_call_10[300000];
    static double merton_call_11[300000];
    static double merton_call_12[300000];
    static double merton_call_13[300000];
    static double merton_call_14[300000];
    static double merton_call_15[300000];

    static double merton_put_1[300000];
    static double merton_put_2[300000];
    static double merton_put_3[300000];
    static double merton_put_4[300000];
    static double merton_put_5[300000];
    static double merton_put_6[300000];
    static double merton_put_7[300000];
    static double merton_put_8[300000];
    static double merton_put_9[300000];
    static double merton_put_10[300000];
    static double merton_put_11[300000];
    static double merton_put_12[300000];
    static double merton_put_13[300000];
    static double merton_put_14[300000];
    static double merton_put_15[300000];

    static merton temp_call_1[300000];
    static merton temp_call_2[300000];
    static merton temp_call_3[300000];
    static merton temp_call_4[300000];
    static merton temp_call_5[300000];
    static merton temp_call_6[300000];
    static merton temp_call_7[300000];
    static merton temp_call_8[300000];
    static merton temp_call_9[300000];
    static merton temp_call_10[300000];
    static merton temp_call_11[300000];
    static merton temp_call_12[300000];
    static merton temp_call_13[300000];
    static merton temp_call_14[300000];
    static merton temp_call_15[300000];

    static merton temp_put_1[300000];
    static merton temp_put_2[300000];
    static merton temp_put_3[300000];
    static merton temp_put_4[300000];
    static merton temp_put_5[300000];
    static merton temp_put_6[300000];
    static merton temp_put_7[300000];
    static merton temp_put_8[300000];
    static merton temp_put_9[300000];
    static merton temp_put_10[300000];
    static merton temp_put_11[300000];
    static merton temp_put_12[300000];
    static merton temp_put_13[300000];
    static merton temp_put_14[300000];
    static merton temp_put_15[300000];

    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++)
    {

    double callPrice_1;
    double callPrice_2;
    double callPrice_3;
    double callPrice_4;
    double callPrice_5;
    double callPrice_6;
    double callPrice_7;
    double callPrice_8;
    double callPrice_9;
    double callPrice_10;
    double callPrice_11;
    double callPrice_12;
    double callPrice_13;
    double callPrice_14;
    double callPrice_15;

    double putPrice_1;
    double putPrice_2;
    double putPrice_3;
    double putPrice_4;
    double putPrice_5;
    double putPrice_6;
    double putPrice_7;
    double putPrice_8;
    double putPrice_9;
    double putPrice_10;
    double putPrice_11;
    double putPrice_12;
    double putPrice_13;
    double putPrice_14;
    double putPrice_15;

    callPrice_1 = EuroCall (S , K1 , r , q , T , sigma , lambda , k , s , n );
    callPrice_2 = EuroCall (S , K2 , r , q , T , sigma , lambda , k , s , n );
    callPrice_3 = EuroCall (S , K3 , r , q , T , sigma , lambda , k , s , n );
    callPrice_4 = EuroCall (S , K4 , r , q , T , sigma , lambda , k , s , n );
    callPrice_5 = EuroCall (S , K5 , r , q , T , sigma , lambda , k , s , n );
    callPrice_6 = EuroCall (S , K6 , r , q , T , sigma , lambda , k , s , n );
    callPrice_7 = EuroCall (S , K7 , r , q , T , sigma , lambda , k , s , n );
    callPrice_8 = EuroCall (S , K8 , r , q , T , sigma , lambda , k , s , n );
    callPrice_9 = EuroCall (S , K9 , r , q , T , sigma , lambda , k , s , n );
    callPrice_10 = EuroCall (S , K10 , r , q , T , sigma , lambda , k , s , n );
    callPrice_11 = EuroCall (S , K11 , r , q , T , sigma , lambda , k , s , n );
    callPrice_12 = EuroCall (S , K12 , r , q , T , sigma , lambda , k , s , n );
    callPrice_13 = EuroCall (S , K13 , r , q , T , sigma , lambda , k , s , n );
    callPrice_14 = EuroCall (S , K14 , r , q , T , sigma , lambda , k , s , n );
    callPrice_15 = EuroCall (S , K15 , r , q , T , sigma , lambda , k , s , n );

    putPrice_1 = EuroPut (S , K1 , r , q , T , sigma , lambda , k , s , n );
    putPrice_2 = EuroPut (S , K2 , r , q , T , sigma , lambda , k , s , n );
    putPrice_3 = EuroPut (S , K3 , r , q , T , sigma , lambda , k , s , n );
    putPrice_4 = EuroPut (S , K4 , r , q , T , sigma , lambda , k , s , n );
    putPrice_5 = EuroPut (S , K5 , r , q , T , sigma , lambda , k , s , n );
    putPrice_6 = EuroPut (S , K6 , r , q , T , sigma , lambda , k , s , n );
    putPrice_7 = EuroPut (S , K7 , r , q , T , sigma , lambda , k , s , n );
    putPrice_8 = EuroPut (S , K8 , r , q , T , sigma , lambda , k , s , n );
    putPrice_9 = EuroPut (S , K9 , r , q , T , sigma , lambda , k , s , n );
    putPrice_10 = EuroPut (S , K10 , r , q , T , sigma , lambda , k , s , n );
    putPrice_11 = EuroPut (S , K11 , r , q , T , sigma , lambda , k , s , n );
    putPrice_12 = EuroPut (S , K12 , r , q , T , sigma , lambda , k , s , n );
    putPrice_13 = EuroPut (S , K13 , r , q , T , sigma , lambda , k , s , n );
    putPrice_14 = EuroPut (S , K14 , r , q , T , sigma , lambda , k , s , n );
    putPrice_15 = EuroPut (S , K15 , r , q , T , sigma , lambda , k , s , n );

    f_call_1[n] = callPrice_1;
    f_call_2[n] = callPrice_2;
    f_call_3[n] = callPrice_3;
    f_call_4[n] = callPrice_4;
    f_call_5[n] = callPrice_5;
    f_call_6[n] = callPrice_6;
    f_call_7[n] = callPrice_7;
    f_call_8[n] = callPrice_8;
    f_call_9[n] = callPrice_9;
    f_call_10[n] = callPrice_10;
    f_call_11[n] = callPrice_11;
    f_call_12[n] = callPrice_12;
    f_call_13[n] = callPrice_13;
    f_call_14[n] = callPrice_14;
    f_call_15[n] = callPrice_15;


    f_put_1[n] = putPrice_1;
    f_put_2[n] = putPrice_2;
    f_put_3[n] = putPrice_3;
    f_put_4[n] = putPrice_4;
    f_put_5[n] = putPrice_5;
    f_put_6[n] = putPrice_6;
    f_put_7[n] = putPrice_7;
    f_put_8[n] = putPrice_8;
    f_put_9[n] = putPrice_9;
    f_put_10[n] = putPrice_10;
    f_put_11[n] = putPrice_11;
    f_put_12[n] = putPrice_12;
    f_put_13[n] = putPrice_13;
    f_put_14[n] = putPrice_14;
    f_put_15[n] = putPrice_15;

    }

    j = 1 ;

    factorial[0] = 1;

    for (i=1; i<=VALUE; i++)
    {
      j=j*1;
      factorial[i] = j;
    }

    temp[0] = 1;

    for ( i=0; i<VALUE ; i++)
    {
      temp[i+1] = ( lambda*(1+k)*T) * temp [i];
    }

    merton_call_1[0] = exp(-(lambda*(1+k)*T)) * f_call_1[0];
    merton_call_2[0] = exp(-(lambda*(1+k)*T)) * f_call_2[0];
    merton_call_3[0] = exp(-(lambda*(1+k)*T)) * f_call_3[0];
    merton_call_4[0] = exp(-(lambda*(1+k)*T)) * f_call_4[0];
    merton_call_5[0] = exp(-(lambda*(1+k)*T)) * f_call_5[0];
    merton_call_6[0] = exp(-(lambda*(1+k)*T)) * f_call_6[0];
    merton_call_7[0] = exp(-(lambda*(1+k)*T)) * f_call_7[0];
    merton_call_8[0] = exp(-(lambda*(1+k)*T)) * f_call_8[0];
    merton_call_9[0] = exp(-(lambda*(1+k)*T)) * f_call_9[0];
    merton_call_10[0] = exp(-(lambda*(1+k)*T)) * f_call_10[0];
    merton_call_11[0] = exp(-(lambda*(1+k)*T)) * f_call_11[0];
    merton_call_12[0] = exp(-(lambda*(1+k)*T)) * f_call_12[0];
    merton_call_13[0] = exp(-(lambda*(1+k)*T)) * f_call_13[0];
    merton_call_14[0] = exp(-(lambda*(1+k)*T)) * f_call_14[0];
    merton_call_15[0] = exp(-(lambda*(1+k)*T)) * f_call_15[0];


    merton_put_1[0] = exp(-(lambda*(1+k)*T)) * f_put_1[0];
    merton_put_2[0] = exp(-(lambda*(1+k)*T)) * f_put_2[0];
    merton_put_3[0] = exp(-(lambda*(1+k)*T)) * f_put_3[0];
    merton_put_4[0] = exp(-(lambda*(1+k)*T)) * f_put_4[0];
    merton_put_5[0] = exp(-(lambda*(1+k)*T)) * f_put_5[0];
    merton_put_6[0] = exp(-(lambda*(1+k)*T)) * f_put_6[0];
    merton_put_7[0] = exp(-(lambda*(1+k)*T)) * f_put_7[0];
    merton_put_8[0] = exp(-(lambda*(1+k)*T)) * f_put_8[0];
    merton_put_9[0] = exp(-(lambda*(1+k)*T)) * f_put_9[0];
    merton_put_10[0] = exp(-(lambda*(1+k)*T)) * f_put_10[0];
    merton_put_11[0] = exp(-(lambda*(1+k)*T)) * f_put_11[0];
    merton_put_12[0] = exp(-(lambda*(1+k)*T)) * f_put_12[0];
    merton_put_13[0] = exp(-(lambda*(1+k)*T)) * f_put_13[0];
    merton_put_14[0] = exp(-(lambda*(1+k)*T)) * f_put_14[0];
    merton_put_15[0] = exp(-(lambda*(1+k)*T)) * f_put_15[0];

    for (i=0 ; i<VALUE; i++)
    {
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];

      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];
      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];

      }

    temp_call_1[a].price = merton_call_1[VALUE];
    temp_call_1[a].jump_num = lambda;
    temp_call_1[a].jump_size = k;
    temp_call_1[a].sd = s;
    temp_call_1[a].vol = sigma;

    temp_call_2[a].price = merton_call_2[VALUE];
    temp_call_2[a].jump_num = lambda;
    temp_call_2[a].jump_size = k;
    temp_call_2[a].sd = s;
    temp_call_2[a].vol = sigma;

    temp_call_3[a].price = merton_call_3[VALUE];
    temp_call_3[a].jump_num = lambda;
    temp_call_3[a].jump_size = k;
    temp_call_3[a].sd = s;
    temp_call_3[a].vol = sigma;

    temp_call_4[a].price = merton_call_4[VALUE];
    temp_call_4[a].jump_num = lambda;
    temp_call_4[a].jump_size = k;
    temp_call_4[a].sd = s;
    temp_call_4[a].vol = sigma;

    temp_call_5[a].price = merton_call_5[VALUE];
    temp_call_5[a].jump_num = lambda;
    temp_call_5[a].jump_size = k;
    temp_call_5[a].sd = s;
    temp_call_5[a].vol = sigma;

    temp_call_6[a].price = merton_call_6[VALUE];
    temp_call_6[a].jump_num = lambda;
    temp_call_6[a].jump_size = k;
    temp_call_6[a].sd = s;
    temp_call_6[a].vol = sigma;

    temp_call_7[a].price = merton_call_7[VALUE];
    temp_call_7[a].jump_num = lambda;
    temp_call_7[a].jump_size = k;
    temp_call_7[a].sd = s;
    temp_call_7[a].vol = sigma;

    temp_call_8[a].price = merton_call_8[VALUE];
    temp_call_8[a].jump_num = lambda;
    temp_call_8[a].jump_size = k;
    temp_call_8[a].sd = s;
    temp_call_8[a].vol = sigma;

    temp_call_9[a].price = merton_call_9[VALUE];
    temp_call_9[a].jump_num = lambda;
    temp_call_9[a].jump_size = k;
    temp_call_9[a].sd = s;
    temp_call_9[a].vol = sigma;

    temp_call_10[a].price = merton_call_10[VALUE];
    temp_call_10[a].jump_num = lambda;
    temp_call_10[a].jump_size = k;
    temp_call_10[a].sd = s;
    temp_call_10[a].vol = sigma;

    temp_call_11[a].price = merton_call_11[VALUE];
    temp_call_11[a].jump_num = lambda;
    temp_call_11[a].jump_size = k;
    temp_call_11[a].sd = s;
    temp_call_11[a].vol = sigma;

    temp_call_12[a].price = merton_call_12[VALUE];
    temp_call_12[a].jump_num = lambda;
    temp_call_12[a].jump_size = k;
    temp_call_12[a].sd = s;
    temp_call_12[a].vol = sigma;

    temp_call_13[a].price = merton_call_13[VALUE];
    temp_call_13[a].jump_num = lambda;
    temp_call_13[a].jump_size = k;
    temp_call_13[a].sd = s;
    temp_call_13[a].vol = sigma;

    temp_call_14[a].price = merton_call_14[VALUE];
    temp_call_14[a].jump_num = lambda;
    temp_call_14[a].jump_size = k;
    temp_call_14[a].sd = s;
    temp_call_14[a].vol = sigma;

    temp_call_15[a].price = merton_call_15[VALUE];
    temp_call_15[a].jump_num = lambda;
    temp_call_15[a].jump_size = k;
    temp_call_15[a].sd = s;
    temp_call_15[a].vol = sigma;

    temp_put_1[a].price = merton_put_1[VALUE];
    temp_put_1[a].jump_num = lambda;
    temp_put_1[a].jump_size = k;
    temp_put_1[a].sd = s;
    temp_put_1[a].vol = sigma;

    temp_put_2[a].price = merton_put_2[VALUE];
    temp_put_2[a].jump_num = lambda;
    temp_put_2[a].jump_size = k;
    temp_put_2[a].sd = s;
    temp_put_2[a].vol = sigma;

    temp_put_3[a].price = merton_put_3[VALUE];
    temp_put_3[a].jump_num = lambda;
    temp_put_3[a].jump_size = k;
    temp_put_3[a].sd = s;
    temp_put_3[a].vol = sigma;

    temp_put_4[a].price = merton_put_4[VALUE];
    temp_put_4[a].jump_num = lambda;
    temp_put_4[a].jump_size = k;
    temp_put_4[a].sd = s;
    temp_put_4[a].vol = sigma;

    temp_put_5[a].price = merton_put_5[VALUE];
    temp_put_5[a].jump_num = lambda;
    temp_put_5[a].jump_size = k;
    temp_put_5[a].sd = s;
    temp_put_5[a].vol = sigma;

    temp_put_6[a].price = merton_put_6[VALUE];
    temp_put_6[a].jump_num = lambda;
    temp_put_6[a].jump_size = k;
    temp_put_6[a].sd = s;
    temp_put_6[a].vol = sigma;

    temp_put_7[a].price = merton_put_7[VALUE];
    temp_put_7[a].jump_num = lambda;
    temp_put_7[a].jump_size = k;
    temp_put_7[a].sd = s;
    temp_put_7[a].vol = sigma;

    temp_put_8[a].price = merton_put_8[VALUE];
    temp_put_8[a].jump_num = lambda;
    temp_put_8[a].jump_size = k;
    temp_put_8[a].sd = s;
    temp_put_8[a].vol = sigma;

    temp_put_9[a].price = merton_put_9[VALUE];
    temp_put_9[a].jump_num = lambda;
    temp_put_9[a].jump_size = k;
    temp_put_9[a].sd = s;
    temp_put_9[a].vol = sigma;

    temp_put_10[a].price = merton_put_10[VALUE];
    temp_put_10[a].jump_num = lambda;
    temp_put_10[a].jump_size = k;
    temp_put_10[a].sd = s;
    temp_put_10[a].vol = sigma;

    temp_put_11[a].price = merton_put_11[VALUE];
    temp_put_11[a].jump_num = lambda;
    temp_put_11[a].jump_size = k;
    temp_put_11[a].sd = s;
    temp_put_11[a].vol = sigma;

    temp_put_12[a].price = merton_put_12[VALUE];
    temp_put_12[a].jump_num = lambda;
    temp_put_12[a].jump_size = k;
    temp_put_12[a].sd = s;
    temp_put_12[a].vol = sigma;

    temp_put_13[a].price = merton_put_13[VALUE];
    temp_put_13[a].jump_num = lambda;
    temp_put_13[a].jump_size = k;
    temp_put_13[a].sd = s;
    temp_put_13[a].vol = sigma;

    temp_put_14[a].price = merton_put_14[VALUE];
    temp_put_14[a].jump_num = lambda;
    temp_put_14[a].jump_size = k;
    temp_put_14[a].sd = s;
    temp_put_14[a].vol = sigma;

    temp_put_15[a].price = merton_put_15[VALUE];
    temp_put_15[a].jump_num = lambda;
    temp_put_15[a].jump_size = k;
    temp_put_15[a].sd = s;
    temp_put_15[a].vol = sigma;

      a++;

      }
     
      }
     
      }

      }

    min_call = 9999; // sum of the square difference of Merton's call
    min_put = 9999; // sum of the square difference of Merton's put
    min_sum = 9999; // total sum of sum of least square difference for both Merton's call and put

    for (i=0 ; i<a ; i++)
    {
      for (h=0; h<a ; i++)
      {
        if ((temp_call_1[i].vol == temp_put_1[h].vol) && (temp_call_1[i].jump_num == temp_put_1[h].jump_num)
          && (temp_call_1[i].jump_size == temp_put_1[h].jump_size) && (temp_call_1[i].sd = temp_put_1[h].sd))
      {
        temp_min_call = (( temp_call_1[i].price - market_call_1) * (temp_call_1[i].price - market_call_1))
        + ((temp_call_2[i].price - market_call_2) * (temp_call_2[i].price - market_call_2))
        + ((temp_call_3[i].price - market_call_3) * (temp_call_3[i].price - market_call_3))
        + ((temp_call_4[i].price - market_call_4) * (temp_call_4[i].price - market_call_4))
        + ((temp_call_5[i].price - market_call_5) * (temp_call_5[i].price - market_call_5))
        + ((temp_call_6[i].price - market_call_6) * (temp_call_6[i].price - market_call_6))
        + ((temp_call_7[i].price - market_call_7) * (temp_call_7[i].price - market_call_7))
        + ((temp_call_8[i].price - market_call_8) * (temp_call_8[i].price - market_call_8))
        + ((temp_call_9[i].price - market_call_9) * (temp_call_9[i].price - market_call_9))
        + ((temp_call_10[i].price - market_call_10) * (temp_call_10[i].price - market_call_10))
        + ((temp_call_11[i].price - market_call_11) * (temp_call_11[i].price - market_call_11))
        + ((temp_call_12[i].price - market_call_12) * (temp_call_12[i].price - market_call_12))
        + ((temp_call_13[i].price - market_call_13) * (temp_call_13[i].price - market_call_13))
        + ((temp_call_14[i].price - market_call_14) * (temp_call_14[i].price - market_call_14))
        + ((temp_call_15[i].price - market_call_15) * (temp_call_15[i].price - market_call_15));

        temp_min_put = (( temp_put_1[h].price - market_put_1) * (temp_put_1[h].price - market_put_1))
        + ((temp_put_2[h].price - market_put_2) * (temp_call_2[h].price - market_put_2))
        + ((temp_put_3[h].price - market_put_3) * (temp_call_2[h].price - market_put_3))
        + ((temp_put_4[h].price - market_put_4) * (temp_call_2[h].price - market_put_4))
        + ((temp_put_5[h].price - market_put_5) * (temp_call_2[h].price - market_put_5))
        + ((temp_put_6[h].price - market_put_6) * (temp_call_2[h].price - market_put_6))
        + ((temp_put_7[h].price - market_put_7) * (temp_call_2[h].price - market_put_7))
        + ((temp_put_8[h].price - market_put_8) * (temp_call_2[h].price - market_put_8))
        + ((temp_put_9[h].price - market_put_9) * (temp_call_2[h].price - market_put_9))
        + ((temp_put_10[h].price - market_put_10) * (temp_call_2[h].price - market_put_10))
        + ((temp_put_11[h].price - market_put_11) * (temp_call_2[h].price - market_put_11))
        + ((temp_put_12[h].price - market_put_12) * (temp_call_2[h].price - market_put_12))
        + ((temp_put_13[h].price - market_put_13) * (temp_call_2[h].price - market_put_13))
        + ((temp_put_14[h].price - market_put_14) * (temp_call_2[h].price - market_put_14))
        + ((temp_put_15[h].price - market_put_15) * (temp_call_2[h].price - market_put_15));

        if ((temp_min_call+temp_min_put) < min_sum)
        {
          min_sum = (temp_min_call+temp_min_put);
          min_call = temp_min_call;
          min_i_call = i;
          min_put = temp_min_put;
          min_h_put = h;
        }
        }
      }
    }

    cout << "Volatility fixed number Merton's model: " << temp_call_1[min_i_call].vol << endl;
    cout << "Jump number: " << temp_call_1[min_i_call].jump_num << endl;
    cout << "Jump size: " << temp_call_1[min_i_call].jump_size << endl;
    cout << "Standard deviation of normal distribution: " << temp_call_1[min_i_call].sd << endl;
    cout << endl;
    cout << "Merton's European call price 1: " << temp_call_1[min_i_call].price << endl;
    cout << "Merton's European call price 2: " << temp_call_2[min_i_call].price << endl;
    cout << "Merton's European call price 3: " << temp_call_3[min_i_call].price << endl;
    cout << "Merton's European call price 4: " << temp_call_4[min_i_call].price << endl;
    cout << "Merton's European call price 5: " << temp_call_5[min_i_call].price << endl;
    cout << "Merton's European call price 6: " << temp_call_6[min_i_call].price << endl;
    cout << "Merton's European call price 7: " << temp_call_7[min_i_call].price << endl;
    cout << "Merton's European call price 8: " << temp_call_8[min_i_call].price << endl;
    cout << "Merton's European call price 9: " << temp_call_9[min_i_call].price << endl;
    cout << "Merton's European call price 10: " << temp_call_10[min_i_call].price << endl;
    cout << "Merton's European call price 11: " << temp_call_11[min_i_call].price << endl;
    cout << "Merton's European call price 12: " << temp_call_12[min_i_call].price << endl;
    cout << "Merton's European call price 13: " << temp_call_13[min_i_call].price << endl;
    cout << "Merton's European call price 14: " << temp_call_14[min_i_call].price << endl;
    cout << "Merton's European call price 15: " << temp_call_15[min_i_call].price << endl;
    cout << "Sum of least square difference between Merton's call and Market call: " << min_call << endl;
    cout << endl;
    cout << "Merton's European put price 1: " << temp_put_1[min_h_put].price << endl;
    cout << "Merton's European put price 2: " << temp_put_2[min_h_put].price << endl;
    cout << "Merton's European put price 3: " << temp_put_3[min_h_put].price << endl;
    cout << "Merton's European put price 4: " << temp_put_4[min_h_put].price << endl;
    cout << "Merton's European put price 5: " << temp_put_5[min_h_put].price << endl;
    cout << "Merton's European put price 6: " << temp_put_6[min_h_put].price << endl;
    cout << "Merton's European put price 7: " << temp_put_7[min_h_put].price << endl;
    cout << "Merton's European put price 8: " << temp_put_8[min_h_put].price << endl;
    cout << "Merton's European put price 9: " << temp_put_9[min_h_put].price << endl;
    cout << "Merton's European put price 10: " << temp_put_10[min_h_put].price << endl;
    cout << "Merton's European put price 11: " << temp_put_11[min_h_put].price << endl;
    cout << "Merton's European put price 12: " << temp_put_12[min_h_put].price << endl;
    cout << "Merton's European put price 13: " << temp_put_13[min_h_put].price << endl;
    cout << "Merton's European put price 14: " << temp_put_14[min_h_put].price << endl;
    cout << "Merton's European put price 15: " << temp_put_15[min_h_put].price << endl;
    cout << "Sum of least square difference between Merton's put and Market put: " << min_put << endl;
    cout << endl;
    //Wait for the user to read the output on the console
    system("PAUSE");
    return 0;
    }



    double EuroCall(double S,double K,double r,double q,double T,double sig_call,double lambda,double k,double s,int n)
    {
        double d1,d2;
        double new_sig;
        double new_r;

        double new_var;

        new_var = sig_call*sig_call + n*s*s / T;
        new_sig = sqrt(new_var);

        new_r = r - lambda*k + n*log(1+k) / T;
       
        d1 = (log(S/K) + (new_r-q+(new_sig*new_sig)*0.5 ) * T ) / (new_sig*sqrt(T));
        d2 = d1 - new_sig*sqrt(T);

        return S*exp(-q*T)*N(d1) - K*exp(-new_r*T)*N(d2);
    }



    double EuroPut(double S,double K,double r, double q,double T,double sig_put,double lambda,double k,double s,int n)
    {
        double d1,d2;
        double new_sig;
        double new_r;

        double new_var;

        new_var = sig_put*sig_put + n*s*s / T;
        new_sig = sqrt(new_var);

        new_r = r - lambda*k + n*log(1+k) / T;
       
        d1 = (log(S/K) + (new_r-q+(new_sig*new_sig)*0.5 ) * T ) / (new_sig*sqrt(T));
        d2 = d1 - new_sig*sqrt(T);

        return K*exp(-new_r*T)*N(-d2) - S*exp(-q*T)*N(-d1);
    }



    double NP(double x)
    {
        return (1.0/sqrt(2.0 * 3.1415)* exp(-x*x*0.5));
    }


    double N(double x)
    {
        double a1 = 0.319381530;
        double a2 = -0.356563782;
        double a3 = 1.781477937;
        double a4 = -1.821255978;
        double a5 = 1.330274429;
        double k;

        k = 1/(1+0.2316419*x);

        if ( x >= 0.0)
        {
          return(1-NP(x)*((a1*k) + (a2*k*k) + (a3*k*k*k) + (a4*k*k*k*k) + (a5*k*k*k*k*k)));
        }
        else
        {
          return (1-N(-x));
        }
    }

reve 2011-04-15 01:13
外星文應該直接搵桶笑啦!

PonG 2011-04-15 01:16
i am sick ....

死左係邊, breakpt CHECK 唔check 到

雲佬~~SY 2011-04-15 01:16
引用第3樓reve2011-04-15 01:13發表的“”:
外星文應該直接搵桶笑啦! [表情] [表情] [表情] [表情] [表情]


桶少都愛莫能助..所以先要各大好友出手相助呀..

智者 2011-04-15 01:18
你問人都要有題目架

雲佬~~SY 2011-04-15 01:19
引用第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 2011-04-15 01:22
引用第7樓雲佬~~SY2011-04-15 01:19發表的“”:
死係d for-loop 到..
pong 妹 [表情] [表情] 你得唔得閒用visual studio 開黎睇下/.
.......

#include "stdafx.h" < 係邊

PonG 2011-04-15 01:23
你唔趕我聽朝幫你睇睇, but 我D PROGRAM 幾差你都知, 同埋我唔識C++  

雲佬~~SY 2011-04-15 01:24
引用第8樓→※Pong※←2011-04-15 01:22發表的“”:
#include "stdafx.h" < 係邊


你有冇VISUAL STUDIO?
咁你直接開個NEW PROJECT,跟住揀WIN32,再跟住就唔好PRESS EMPTY PROJECT , PRESS CONSOLE, 之後就有依個FILE 架LA

雲佬~~SY 2011-04-15 01:25
引用第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 2011-04-15 01:27
第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++)
{


煙花 2011-04-15 01:31
用戶被禁言,該主題自動屏蔽!

雲佬~~SY 2011-04-15 01:32
引用第13樓煙花2011-04-15 01:31發表的“”:
[表情] [表情]
我睇完....其實....想講........
.......


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

雲佬~~SY 2011-04-15 01:37
如果可以的話,希望大家花少少時間RUN一次依2個PROGRAM 睇下有咩RESULT

him 2011-04-15 02:03
睇到想嘔 好好彩我冇揀到PROGRAMMING 突然覺得BUILDING好易

kamch116 2011-04-15 04:05
中四個時有讀...一開始覺得好易
不過之後開始HEA下HEA下最後DROP左

基斯坦奴 2011-04-15 10:45
電腦白痴純粹入黎留個名...
睇下有無高手解答到

plmplm 2011-04-15 11:54
d variable 我睇落去無意思...
跟死人

keicarlos 2011-04-15 16:30
sub K.cv by K.cv

智者 2011-04-15 17:43
第一題

你declare左個price array -------- price K[30];
但點解for loop裡面無index? (可能我睇唔明)

rubbish 2011-04-16 14:24
o係呢到post code 係出唔到 [ i ]

chongsir1206 2011-04-16 16:11
K.b=1/(1-alpha/100);
第一個progrem,,佢話呢句有問題
你上面initialize個alpha=1,,,1/0係除唔到,,所以error

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);

chongsir1206 2011-04-16 16:25
第2個program
for (i=0 ; i<a ; i++)
{
for (h=0; h<a ; i++)
{

呢度係唔係打錯野,,第二個for loop係無限loop

if ((temp_min_call+temp_min_put) < min_sum)
  {
    min_sum = (temp_min_call+temp_min_put);
    min_call = temp_min_call;
    min_i_call = i;
    min_put = temp_min_put;
    min_h_put = h;
  }
  }
}
}

cout << "Volatility fixed number Merton's model: " << temp_call_1[min_i_call].vol << endl;
cout << "Jump number: " << temp_call_1[min_i_call].jump_num << endl;
cout << "Jump size: " << temp_call_1[min_i_call].jump_size << endl;
cout << "Standard deviation of normal distribution: " << temp_call_1[min_i_call].sd << endl;
cout << endl;
cout << "Merton's European call price 1: " << temp_call_1[min_i_call].price << endl;
cout << "Merton's European call price 2: " << temp_call_2[min_i_call].price << endl;
cout << "Merton's European call price 3: " << temp_call_3[min_i_call].price << endl;
cout << "Merton's European call price 4: " << temp_call_4[min_i_call].price << endl;

如果上面個for loop裡面既if condition satisfy唔到,,min_i_call究竟係幾多呢,,個variable無initialize到

雲佬~~SY 2011-04-16 20:35
引用第21樓智者2011-04-15 17:43發表的“”:
第一題
你declare左個price array -------- price K[30];
但點解for loop裡面無index? (可能我睇唔明)


依家出到了..唔係依個問題..

雲佬~~SY 2011-04-16 20:48
引用第23樓chongsir12062011-04-16 16:11發表的“”:
K.b=1/(1-alpha/100);
第一個progrem,,佢話呢句有問題
你上面initialize個alpha=1,,,1/0係除唔到,,所以error


K.b=1/(1-alpha/100);
但當ALPHA = 1, K.B = 1/(1-1/100) = 1/0.99   wo

chongsir1206 2011-04-16 21:13
引用第26樓雲佬~~SY2011-04-16 20:48發表的“”:
K.b=1/(1-alpha/100);
但當ALPHA = 1, K.B = 1/(1-1/100) = 1/0.99   wo [表情]

sorry,應該係當alpha = 100果時,,就會出現呢個問題

雲佬~~SY 2011-04-16 21:21
引用第27樓chongsir12062011-04-16 21:13發表的“”:
sorry,應該係當alpha = 100果時,,就會出現呢個問題


係wo..咁應該點改lei..我就係唔知點改

chongsir1206 2011-04-16 21:24
引用第28樓雲佬~~SY2011-04-16 21:21發表的“”:
係wo..咁應該點改lei..我就係唔知點改 [表情]

因為我唔係好知果d financial ratio係點計
所以我唔係好知你d formula 應該係點
其中一個可能解決到既就係 係個for loop度加句
if (i ==100)
  i ++;

但係我唔知咁樣對你條數有無影響

JHELSEA 2011-04-17 12:12
嘩,睇到

我既 programme 仲停留緊係 delphi 度


查看完整版本: [-- PROGRAMMING 難題 (厚酬: 50000x2=100000好友元)(URGENT!!)(最主要都係睇NESTED FOR-LOOP!!) --] [-- top --]


Powered by phpwind v8.7 Code ©2003-2011 phpwind
Time 0.154778 second(s),query:3 Gzip disabled