Undefined reference error

file :solver02.h

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
#ifndef Solver03_h
#define Solver03_h

template<typename Function> double SolveByBisect
   (Function* Fct,
   double Tgt, double LEnd, double REnd, double Acc)
{
   double left=LEnd, right=REnd, mid=(left+right)/2;
   double y_left=Fct->Value(left)-Tgt, y_mid=Fct->Value(mid)-Tgt;
   while (mid-left>Acc)
   {
      if ((y_left>0 && y_mid>0)||(y_left<0 && y_mid<0))
         {left=mid; y_left=y_mid;}
      else right=mid;
      mid=(left+right)/2;
      y_mid=Fct->Value(mid)-Tgt;
   }
   return mid;
}

template<typename Function> double SolveByNR
   (Function* Fct,
   double Tgt, double Guess, double Acc)
{
   double x_prev=Guess;
   double x_next=x_prev
      -(Fct->Value(x_prev)-Tgt)/Fct->Deriv(x_prev);
   while (x_next-x_prev>Acc || x_prev-x_next>Acc)
   {
      x_prev=x_next;
      x_next=x_prev
         -(Fct->Value(x_prev)-Tgt)/Fct->Deriv(x_prev);
   }
   return x_next;
}

#endif  



file:Margrabe.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef MARGRABE_H_INCLUDED
#define MARGRABE_H_INCLUDED

class EurCall
{
public:
    double T, Ki;
    EurCall (double T_, double Ki_) {T=T_; Ki=Ki_;}

    double di_plus ( double Si, double sigma, double r, double qi);
    double di_minus (double Si, double sigma, double r, double qi);

    double BSFormula (double Si, double sigma, double r ,double qi);

};

#endif // MARGRABE_H_INCLUDED 


file: Margrabe.cpp
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
#include "Margrabe.h"
#include <cmath>

double N (double x)

{
    double gamma = 0.2316419;
    double a1 = 0.319381530;
    double a2 = -0.356563782;
    double a3 = 1.781477937;
    double a4 = -1.821255978;
    double a5 = 1.330274429;
    double pi = 4.0*atan(1.0);
      double k     =1.0/(1.0+ gamma*x);

    if (x>=0.0)
    {
        return 1.0-((((a5*k+a4)*k+a3)*k+a2)*k+a1)*k*exp(-x*x/2.0)/sqrt(2.0*pi);
    }

    else return 1.0-N(-x);
}



double Eurcall::di_plus(double Si, double sigma, double r, double qi)
{
    return (log(Si/Ki) + (r-qi+((pow(sigma,2.0))/2.0))* (T)) / (sigma*sqrt(T));
}


double EurCall::di_minus(double Si, double sigma, double r, double qi)
{
    return ( log(Si/Ki) + (r-qi-((pow(sigma,2.0))/2.0)) * (T)) / (sigma*sqrt(T));
}


double EurCall::BSFormula(double Si, double sigma, double r, double qi)
{
    return Si*exp(-qi*(T)) * N(di_plus(Si, sigma, r, qi))- Ki*exp(-r*T)*N(di_minus(Si, sigma,r,qi));
}


file: main.cpp
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
#include "Solver03.h"
#include "Margrabe.h"
#include <iostream>
#include <cmath>

using namespace std;


class Intermediary: public  EurCall
{
private:
    double Si, r, qi;

public:

Intermediary( double Si_, double r_, double T_, double Ki_, double qi_)

: EurCall(T_, Ki_) {Si=Si_; r=r_; qi=qi_;}

double Value(double sigma)

{
    return BSFormula(Si, sigma, r, qi);
}

};


int main()
{

    double Si=95;
    double r=0.06;
    double T=0.5;
    double Ki=95;
    double qi=0.03;

    Intermediary Call(Si, r,  T, Ki, qi);

    double Acc=0.001;
    double LEnd=0.01, REnd=1.0;
    double Tgt=9.1206;

    cout << "Implied vol by bisect: "
         <<SolveByBisect(&Call, Tgt, LEnd, REnd, Acc)
         <<endl;


    return 0;
}


I am keep getting the error message
||=== Build: Debug in projectt2 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `ZN12Intermediary5ValueEd|
M:\projectt2\projectt2\main.cpp|23|undefined reference to `EurCall::BSFormula(double, double, double, double|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|


Can someone help with this undefined reference error?
Last edited on
Could you please edit your post and use code tags, would be much easier to spot it - http://www.cplusplus.com/articles/jEywvCM9/
TarikNeaj

I have edited it. please help
well are you linking to the cpp source file Margrabe.cpp?
how do you link it ?
I just added this Margrabe.cpp into my project
please help
Topic archived. No new replies allowed.