1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include "Solver03.h"
#include "Margrabe.h"
#include "EurCall.h"
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
class Intermediary: public EurCall
{
private:
double S,r,q;
public:
Intermediary(double S_, double r_,double q_, double T_, double K_)
: EurCall(T_,K_) {S=S_; r=r_;q=q_;}
double Value(double sigma)
{
return PriceByBSFormula(S, sigma, r, q);
}
};
class Intermediary1 : public Margrabe
{
private :
double S10, S20, q10, q20, sigma10, sigma20;
public :
Intermediary1(double S10_, double S20_, double q10_, double q20_, double sigma10_, double sigma20_, double T_)
: Margrabe (T_){S10=S10_; S20=S20_; q10=q10_; q20=q20_; sigma10=sigma10_; sigma20=sigma20_;}
double Value(double rho)
{
return PriceByMargrabeFormula(S10, S20, q10, q20, sigma10, sigma20, rho);
}
};
int main()
{
double r=0.06;
double S1 = 95;
double S2 = 105;
double K1 = 95;
double K2 = 105;
double q1 = 0.03;
double q2 = 0.05;
double T1 = 0.5;
double T2 = 0.8;
double T3 = 0.6;
double sigma1 = 0.28;
double sigma2 = 0.009;
Intermediary Call_1(S1,q1,r,T1,K1);
Intermediary Call_2(S2,q2,r,T2,K2);
Intermediary1 Margrabe1 (S1, S2, T3,q1, q2, sigma1, sigma2);
double Acc=0.001;
double LEnd=0.01, REnd=1.0;
double Tgt_1=8.1206;
double Tgt_2= 5.2856;
double Tgt_3= 6.8833;
cout << "First Implied volatility by bisect: "
<< SolveByBisect(&Call_1,Tgt_1,LEnd,REnd,Acc) << '\n'
<< "Second Implied volatility by bisect: "
<< SolveByBisect(&Call_2,Tgt_2,LEnd,REnd,Acc) << '\n'
<< "Imlied Correlation Coefficient: "
<< SolveByBisect(&Margrabe1, Tgt_3, LEnd, REnd, Acc)
<< endl;
return 0;
}
|