Login  Register

Re: Adding new functions to blackcalculator

Posted by Dimathematician on Apr 21, 2009; 7:49am
URL: http://quantlib.414.s1.nabble.com/Adding-new-functions-to-blackcalculator-tp13518p13525.html

Nando, I think the modification should be ok for the blackcalculator. I've uploaded
my current working version of the deltacalculator including a testsuite(your recent change not incl.).

You can get it here:

longvega.com/DeltaEngine.zip

Now as you see its not really incorporated into blackcalculator and lets see
how we might be able to join the concepts. My reasons were the following:

1) First of all, we have 4 deltas to take care of and even more atm quotes, which
are rather FX specific, since we have 2 numeraires. So I have enums, which
basically have only FX specific types, don't know if that should go into a general
blackcalculator.

2)
I needed functions such as

Real deltaFromStrike(const Real &strike) const;
Real strikeFromDelta(const Real &delta)  const;

since they will be later called very often in some numerical procedures in the
smile setup. Again, its FX specific to quote vols again deltas from which we can
extract strikes. And again, the functions return different values for different deltas.
It would be a bit incoherent from my point of view to return a strike different from
the one given in the constructor, as would be the case for the blackcalc.

Here functions are generic, in a blackcalculator I might need to setup 8 new functions?
The bigger problem for me was, that the strike in blackcalc is in the payoff, and
I need it to change very often. So I've created a parsimonious constructor which doesn't need
a strike nor a delta. If you look into strikeFromDelta, you'll see numerical procedures
for premium adjusted stuff, so I can't really make use of cached data anyways and
it doesn't have to do a lot with the standard black formulas anymore.


Btw: I'd appreciate a function which returns d1 and d2 in blackcalc, which I need for
other functions I'm working on as well. If that would be possible, I'd setup a blackcalc
in my class and the whole class would be basically based on the blackcalc.

I'm open to discussion. Whats your oppinion? Thanks








2009/4/20 Ferdinando Ametrano <[hidden email]>
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