### CDF problem with <cmath>

Hi guys!
I'm studying the book 'C++ for Quantitative Finance' and implementing the first example Vanilla Option, but in the function to calculate call / put option values, the IDE always reports a error: 'N was not declared in this scope'.
I bet the N stands for the calculation of CDF of a standard normal distribution, using <cmath>. I checked <cmath> documentation and found out that the library does not include function N.
Could u please give me some solution for this ?
Thanks a lot!!!

Here are the codes:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140`` ``````#ifndef VANILLAOPTION_H #define VANILLAOPTION_H class vanillaoption { public: vanillaoption(); vanillaoption(const double& _K, const double& _r, const double& _T, const double& _S, const double& _sigma); vanillaoption(const vanillaoption& rhs); vanillaoption& operator=(const vanillaoption& rhs); virtual ~vanillaoption(); // selector (getter) methods for our option parameters double getK() const; double getr() const; double getT() const; double getS() const; double getsigma() const; double calcalloption() const; double calputoption() const; protected: private: void init(); void copy(const vanillaoption& rhs); double K; double r; double T; double S; double sigma; }; #endif // VANILLAOPTION_H #include #include "vanillaoption.h" #include using namespace std; void vanillaoption::init(){ K = 100.0; r = 0.05; T = 1.0; S = 100.0; sigma = 0.2; } vanillaoption::vanillaoption() { init(); } vanillaoption::vanillaoption(const double& _K, const double& _r, const double& _T, const double& _S, const double& _sigma) { K = _K; r = _r; T = _T; S = _S; sigma = _sigma; } //copy constructor vanillaoption::vanillaoption(const vanillaoption& rhs) { copy(rhs); } //assignment operator vanillaoption& vanillaoption::operator=(const vanillaoption& rhs) { if (this == &rhs) return *this; copy(rhs); return *this; / } void vanillaoption::copy(const vanillaoption& rhs){ K = rhs.getK(); r = rhs.getr(); T = rhs.getT(); S = rhs.getS(); sigma = rhs.getsigma(); } vanillaoption::~vanillaoption() { //empty } double vanillaoption::getK() const { return K; } double vanillaoption::getr() const { return r; } double vanillaoption::getT() const { return T; } double vanillaoption::getS() const { return S; } double vanillaoption::getsigma() const { return sigma; } double vanillaoption::calcalloption() const { double sigma_squrt_T = sigma * sqrt(T); double d_1 = ( log(S/K) + sigma * sigma * 0.5 * T) / sigma_squrt_T; double d_2 = d_1 - sigma_squrt_T; return (S * exp(-r*T) * N(d_1)) - (K * exp(-r*T) * N(d_2)); // problem occurred in this line }; double vanillaoption::calputoption() const { double sigma_squrt_T = sigma * sqrt(T); double d_1 = ( log(S/K) + sigma * sigma * 0.5 * T) / sigma_squrt_T; double d_2 = d_1 - sigma_squrt_T; return (K * exp(-r*T) * N(-d_2)) - (S * exp(-r*T) * N(-d_1)); };``````

Thanks!
Last edited on
Line 89: Extraneous /

Line 132, 139: N appears to be a function call, but I see no such function.

I have not fooled with probability since the 90s so forgive me... but a quick google provided this function for N:

double normalCFD(double value)
{
return 0.5 * erfc(-value * M_SQRT1_2);
}

TEST it to see if it is correct and giving yuo what you expect.

erfc is in <cmath> as is the constant. It should flat out work if the formula is correct.
Last edited on
Thanks a lot, AbstractionAnon and jonnin, using the function indicated by jonnin, the problem has been solved!!!I'm so happy with this, my friends!
Topic archived. No new replies allowed.