CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    4

    Error LINK2019 and fatal error LINK1120

    I am trying to solve a explicit finite difference method on C++ to price a Barrier Option and i get the following two errors. Can someone please help me with this. Thanks. The code is as follows:


    #include<iostream>
    #include<cmath>
    using namespace std;

    double max(double a, double b)
    {
    return((a>b)?a:b);
    }

    //-----------------------------------------------------------------------------------

    class ExplicitPricer{
    private:
    double Price;
    public:
    ExplicitPricer(double s_now, double K, double T, double vol, double r, int I);
    double Value(int flag);
    ~ExplicitPricer(){}
    };

    ExplicitPricer::ExplicitPricer(double s_now, double K, double T, double vol, double r, int I)
    {
    int i, j;
    const double delta_S = (2 * K) / I; // A choice
    const int i_star = floor(s_now / delta_S);
    const double WEIGHT = (s_now - i_star * delta_S) / delta_S;
    double delta_t = 1 / (vol*vol*I*I);
    const int J = floor(T/delta_t) + 1;
    delta_t = T / J ;

    double* Vprevious_j; Vprevious_j= new double[I+1];
    double* Vcurrent_j; Vcurrent_j = new double[I+1];
    double* P_u;P_u = new double[I+1];
    double* P_m; P_m = new double[I+1];
    double* P_d; P_d = new double[I+1];
    double* S;S = new double[I+1];
    double* S_squared; S_squared = new double[I+1];

    const double Halfvol_squared = 0.5*vol*vol;
    const double q = r - Halfvol_squared; //drift
    double temp1, temp2, temp3;

    for (i = 0; i<=I ; i++)
    {
    S[i] = i*delta_S;
    S_squared[i] = S[i]*S[i];
    Vprevious_j[i] = max(S[i] - K, 0);
    }

    for (j = 1; j<=J; j++)
    {
    for (i = 1; i<=I-1; i++)
    {
    P_u[i] = (Halfvol_squared* delta_t) / (delta_S * delta_S) + (q * delta_t) / (2 * delta_S);
    P_m[i] = 1 - (vol * vol * delta_t) / (delta_S * delta_S);
    P_d[i] = (Halfvol_squared * delta_t) / (delta_S * delta_S) - (q*delta_t) / (2 * delta_S);
    temp1 = P_d[i] * Vprevious_j[i-1];
    temp2 = P_m[i] * Vprevious_j[i];
    temp3 = P_u[i] * Vprevious_j[i+1];
    Vcurrent_j[i] = temp1 + temp2 + temp3;

    //Vcurrent_j[0] = 0.0;
    //Vcurrent_j[I] = 2* Vcurrent_j[I - 1] - Vcurrent_j[I - 2];
    }

    Price = (Vprevious_j[i_star] + WEIGHT*Vprevious_j[i_star + 1]);

    delete[] Vprevious_j;
    delete[] Vcurrent_j;
    delete[] P_u;
    delete[] P_m;
    delete[] P_d;
    delete[] S;
    delete[] S_squared;

    }
    }

    double ExplicitPricer::Value(int flag)
    {
    if(flag==0)
    return Price;
    }

    int main()
    {
    ExplicitPricer Ep(100,100, 1, 0.2, 0.05, 40);
    cout << "Explicit's Price is : " << Ep.Value(0) << endl;
    return 0;
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Error LINK2019 and fatal error LINK1120

    Please re-edit your post to use code tags. The code you posted is unreadable.

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured