RustQuant icon indicating copy to clipboard operation
RustQuant copied to clipboard

Implement finite-difference pricers.

Open avhz opened this issue 2 years ago • 9 comments

avhz avatar Aug 26 '23 13:08 avhz

I'd take this one. Do you have some references for the implementation?

SimonG85 avatar Sep 18 '23 17:09 SimonG85

You could try Finite Difference Computing with PDEs. It's supposed to be quite good and it's open access here.

Also might be worth having a look at QuantLib.

avhz avatar Sep 18 '23 19:09 avhz

@avhz I also found a chapter in implementing quantlib. I'm reading, we will see soon.

SimonG85 avatar Sep 19 '23 08:09 SimonG85

You can take a look here, specifically at the PDE_European.jl and PDE_American.jl files. I worked on this very problem a while ago, albeit, in Julia. Feel free to translate this code to Rust.

jrinder42 avatar Feb 07 '24 03:02 jrinder42

You can take a look here, specifically at the PDE_European.jl and PDE_American.jl files. I worked on this very problem a while ago, albeit, in Julia. Feel free to translate this code to Rust.

Thanks. I'm a little bit busy at work but I'll take a look!

SimonG85 avatar Mar 07 '24 10:03 SimonG85

Hey @SimonG85

Would it be ok if I take this issue? I was able to make some progress on it. I would very happy for you to look at the PR once it is ready.

yfnaji avatar Apr 02 '24 15:04 yfnaji

@yfnaji yeah you can take it for sure!

SimonG85 avatar Apr 05 '24 14:04 SimonG85

@yfnaji

In the latest commit (74a90f0), I tried ATM option tests, and there a number of failures. In particular, the explicit() method seems to have an issue.

---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_explicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_explicit' panicked at src/instruments/options/finite_difference_pricer.rs:503:9:

Left:           NaN, 
Right:          2.179260421286685, 
Precision:      0.000000014901161193847656

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_put_explicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_put_explicit' panicked at src/instruments/options/finite_difference_pricer.rs:488:9:

Left:           54096898083232840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 
Right:          1.74684769403327, 
Precision:      0.000000014901161193847656


---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_call_explicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_call_explicit' panicked at src/instruments/options/finite_difference_pricer.rs:473:9:

Left:           inf, 
Right:          2.179260421286685, 
Precision:      0.000000014901161193847656


---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_put_explicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_put_explicit' panicked at src/instruments/options/finite_difference_pricer.rs:518:9:

Left:           NaN, 
Right:          1.691554666293824, 
Precision:      0.000000014901161193847656


---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_call_implicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::american_call_implicit' panicked at src/instruments/options/finite_difference_pricer.rs:478:9:

Left:           2.771814089100344, 
Right:          2.179260421286685, 
Precision:      0.000000014901161193847656


---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_implicit stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_implicit' panicked at src/instruments/options/finite_difference_pricer.rs:508:9:

Left:           2.771814089100344, 
Right:          2.179260421286685, 
Precision:      0.000000014901161193847656

---- instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_crank_nicolson stdout ----
thread 'instruments::options::finite_difference_pricer::tests_finite_difference_pricer::european_call_crank_nicolson' panicked at src/instruments/options/finite_difference_pricer.rs:513:9:

Left:           0.8579231906354501, 
Right:          2.179260421286685, 
Precision:      0.000000014901161193847656

Edit (see e5db8c0):

There also seems to be an issue with OTM Eur Call implicit() method.

explicit() also fails on OTM/ITM.

'instruments::options::finite_difference_pricer::tests_finite_difference_pricer_out_of_the_money::european_call_implicit' panicked at src/instruments/options/finite_difference_pricer.rs:758:9:

Left:           -0.41215437112011133, 
Right:          0.000001014047539618235, 
Precision:      0.000000014901161193847656

avhz avatar Apr 25 '24 19:04 avhz

@avhz thanks for bringing this to my attention - I am currently investigating and will update as soon as I find something

yfnaji avatar Apr 25 '24 21:04 yfnaji