Re: Adding new functions to blackcalculator
Posted by
Ferdinando M. Ametrano-3 on
Apr 20, 2009; 11:18am
URL: http://quantlib.414.s1.nabble.com/Adding-new-functions-to-blackcalculator-tp13518p13524.html
Hi Dima> I plan to add some new FX machinery to QuantLib.
if applicable please consider adding generic formulas to ql/pricingengines/blackformula.hpp
> In the BlackCalculator constructor we have
> if (stdDev_>=QL_EPSILON) {> ...
> } > else{
> if (forward>strike_) {> cum_d1_ = 1.0;
> cum_d2_= 1.0;> } else {
> cum_d1_ = 0.0;> cum_d2_= 0.0;
> }> }
> I wonder if that's 100% right or if I've overlooked something. But if> forward==strike,
> then we have log(f/K)=0, > so, if vol is not zero, we should rather have
> cum_d1=N (0*5*stdDev_)> which would be approximately 0.5 for very small vols. Opinions?
yeah, you're right. It should be patched as below, isn't it?
if (stdDev_>=QL_EPSILON) {
if (close(strike_, 0.0)) {
cum_d1_ = 1.0;
cum_d2_ = 1.0;
n_d1_ = 0.0;
n_d2_ = 0.0;
} else {
D1_ = std::log(forward/strike_)/stdDev_ + 0.5*stdDev_;
D2_ = D1_-stdDev_;
CumulativeNormalDistribution f;
cum_d1_ = f(D1_);
cum_d2_ = f(D2_);
n_d1_ = f.derivative(D1_);
n_d2_ = f.derivative(D2_);
}
} else {
if (close(forward, strike_)) {
cum_d1_ = 0.5;
cum_d2_ = 0.5;
n_d1_ = M_SQRT_2 * M_1_SQRTPI;
n_d2_ = M_SQRT_2 * M_1_SQRTPI;
} else if (forward>strike_) {
cum_d1_ = 1.0;
cum_d2_ = 1.0;
n_d1_ = 0.0;
n_d2_ = 0.0;
} else {
cum_d1_ = 0.0;
cum_d2_ = 0.0;
n_d1_ = 0.0;
n_d2_ = 0.0;
}
}
ciao -- Nando
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32.
http://p.sf.net/sfu/p_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev