lballabio / quantlib-old

The QuantLib C++ library and extensions (warning: out of date)
http://quantlib.org
471 stars 405 forks source link

Possible bug in `PerturbativeBarrierOptionEngine` #353

Closed lballabio closed 8 years ago

lballabio commented 8 years ago

In ql/experimental/barrieroption/perturbativebarrieroptionengine.cpp, the value assigned to caux at line 172 is never used. It might be just a dead assignment (in which acse we can delete it) but since there's another variable called ccaux and used in the rest of the function, it's also possible that the wrong variable was assigned or used. We should check the implementation based on the reference quoted in the header file.

pcaspers commented 8 years ago

Interesting. Did you get that from some compiler diagnostics?

The website given as a reference in the code contains a summary of the paper and Fortran code for download. The Fortran code shows the same peculiarity regarding caux and ccaux (lines 200 and 201 in Fmain.f90). The full paper can be downloaded here:

http://www.researchgate.net/publication/228454708_A_perturbative_formula_to_price_barrier_options_with_time-dependent_parameters_in_the_Black_and_Scholes_world

Formula 36 seems to be the function v implemented in pertubativebarrieroptionengine.cpp, L393. The loop starting at L163 seems to compute the integral of formula 34. Lines 172-173 correspond to [E(τ, t, x, x∗,γ)− E(τ, t, −x, x∗,γ) + E(τ, t, x, −x∗,γ)− E(τ, t, −x, −x∗,γ)] (see lines 4 to 6 of formula 34 in the paper).

If this is all true, we would have to replace caux by ccaux in L172 and would be fine.

We should probably send the corresponding fix of the Fortran implementation to the authors of the paper. Maybe they can confirm that it is correct. Do you know them ?

lballabio commented 8 years ago

I got this from clang's static analysis tools (http://clang-analyzer.llvm.org/scan-build.html).

I still have the email of one of the authors. I'll reach out to him and ask for confirmation.

pcaspers commented 8 years ago

that's good, thank you

lballabio commented 8 years ago

Hmm, I take that back--the email I had is no longer valid.

Ok, I'm doing the change anyway.

pcaspers commented 8 years ago

I am confident that this is ok.