SERVING THE QUANTITATIVE FINANCE COMMUNITY

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunYes!So it'll be something like this?double N(double x) { return 0.5 +0.5*erf(x*0.7071067811865475244008443621); }Yep. I programmed it after you posted and I tested it as well.
Last edited by Cuchulainn on January 15th, 2016, 11:00 pm, edited 1 time in total.

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunI'm also puzzled about std::sqrt vs sqrt. I think all function in cmath are in the global namespace and *some* also in the std::. Very strange... It's also compiler specific it seems. What's the most portable (standard conforming) way to use cmath?Personally, I use std:: for all math stuff (I remember Polter advising std::abs etc.)On the case rho == 1; most solutions break down but the code for 26.3.3 works which is really, really super. None of if (rhs > 0.925) jibberish

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunjust that you know, C++11 has erfOne issue is accuracy, i.e. which algorithm is used to approximate it? Let's say it is O(10^-7), then if used with other methods then it may not help if these latter method have accuracy better than O(10^-7).
Last edited by Cuchulainn on January 15th, 2016, 11:00 pm, edited 1 time in total.

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

The fact that C++11 supports erf and erfc means it is easy to implement inverse cdf function using Newton or fixed point(you can immediately see it's a contraction), so the need for proprietary C libraries is less urgent.BTW C++11 also supports gamma and log gamma functions. // erf can be implemented using the incomplete gamma function or by exp(P(t)) where P is a 9th degree polynomial. Ideally, we should know the accuracy of erf and the number of arithmetic operations needed to achieve that accuracy, a bit like knowing how many miles per gallon the auto does. In the punch-card Fortran days you had to fill in #operations (running time) before the computer centre would accept your job.
Last edited by Cuchulainn on January 16th, 2016, 11:00 pm, edited 1 time in total.

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunUsing a local constexpr:Indeed! I tried that outside the scope of the function but it gave a compiler error. double CdfNormal(double x){ constexpr double sqrt2Inv = 1.0 / std::sqrt(2.0); return 0.5*(1.0 + std::erf(x * sqrt2Inv));}I still get error VS2015 " error C2131: expression did not evaluate to a constant1> CumulativeNormal.hpp(64): note: failure was caused by call of undefined function or one not declared 'constexpr'
Last edited by Cuchulainn on January 16th, 2016, 11:00 pm, edited 1 time in total.

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunStrange, how can it not evaluate to a constant? There isn't even a variable in the expression.Maybe a compiler limitation?.. it works at ideoneVS2015 has partial support for constexpr (in ctor it works).

Cuchulainn
Posts: 62371
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### ISO C++11 published

QuoteOriginally posted by: outrunI'm sorry that you now have to buy an upgrade of VS for .. Tsk tsk. Why are you still paying? You're basically paying for a toothless grandmaInstead use clang or gcc -which are free- and don't wast your time having to write mutant code.Good point. Mind the blood pressure.I want it for free, yeah.
 ABOUT WILMOTT

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...

 JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...

GZIP: On