-
UID︰14056
-
- 注冊時間2007-08-11
- 最後登錄2024-11-24
- 在線時間2994小時
-
- 發帖12285
- 搜Ta的帖子
- 精華0
- 好友元35671
- 閱讀權限12308
- 貢獻值0
-
訪問TA的空間加好友用道具
- 發帖
- 12285
- 好友元
- 35671
- 閱讀權限
- 12308
- 貢獻值
- 0
|
第2個program:(SOURCE CODE) - // 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));
- }
- }
[ 本文被雲佬~~SY在2011-04-16 20:34重新編輯 ]
|