Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 16th, 2016, 4:16 pm

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.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 16th, 2016, 4:27 pm

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 :)
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 16th, 2016, 7:58 pm

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.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 17th, 2016, 8:41 am

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.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 17th, 2016, 10:34 am

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.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 18th, 2016, 10:56 am

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).
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

ISO C++11 published

January 18th, 2016, 1:53 pm

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.