MarcusRainbow / QuantMath

Financial maths library for risk-neutral pricing and risk
MIT License
371 stars 43 forks source link

Check third party libraries #9

Open MarcusRainbow opened 6 years ago

MarcusRainbow commented 6 years ago

We rely on rand for random numbers. Is this as good as Mersenne Twister? (If not, it would be better to implement Mersenne Twister.)

We rely on statrs for Normal distribution functions. How accurate are these? It really matters for far out of the money options how good the cumulative normal function is in the wings.

petr-tik commented 4 years ago

Just found this library (amazing work) and I was wondering if you still have any time and interest in accepting PRs?

If so, there is a crate implementing the mersenne twister PRNG , which I can add behind a feature flag

MarcusRainbow commented 4 years ago

Hi, I've not done anything to this library for a while. However, if you want to make any contributions, they would be more than welcome. I agree it would be very good to use Mersenne Twister for the pseudo-random numbers. (Sobol sequences would also be very useful.)

I still think there is a real future in using Rust for financial maths. I'm just waiting for the rest of the world to cotton on to this idea... Thanks, Marcus

On Mon, 11 May 2020 at 17:35, petr-tik notifications@github.com wrote:

Just found this library (amazing work) and I was wondering if you still have any time and interest in accepting PRs?

If so, there is a crate implementing the mersenne twister PRNG https://docs.rs/mersenne_twister/1.1.1/mersenne_twister/, which I can add behind a feature flag

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcusRainbow/QuantMath/issues/9#issuecomment-626813555, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWFPPZ7KBS5EYUWHIFEBMDRRASNPANCNFSM4FHPKB3Q .

petr-tik commented 4 years ago

I still think there is a real future in using Rust for financial maths. I'm just waiting for the rest of the world to cotton on to this idea

Hear hear! I guess the hardest problem to solve is acknowledging the moat of C++ and integrating rust with existing codebases as seamlessly as possible. Have you had any success or problems with that?

I agree it would be very good to use Mersenne Twister for the pseudo-random numbers.

If you are happy to look at my PR do you want that behind a feature flag or do you prefer Mersenne Twister replaces rand by default?

petr-tik commented 4 years ago

I have been looking at your library, while learning about derivatives pricing and I have a question.

In your options pricing model you use the widespread Black-Scholes model with a normal distribution. I have read and heard about different flavours of Black-Scholes using other probability distributions eg. fat-tailed.

https://github.com/MarcusRainbow/QuantMath/blob/master/src/math/optionpricing.rs

Is there any scope/use for adding/trying other pdf for this?

MarcusRainbow commented 4 years ago

Hi,

Please could you point me to your pull request and I'll take a look. Personally, I'd be happy for Mersenne Twister to replace rand by default, though it would be useful to also support other pseudo-random and low-discrepancy sequences.

Yes, that is a problem, though as you can see I have Rust roughly integrating with C++ in the library. My preference is to have a facade layer around an analytics library anyway. If you were working in a bank, there would generally be one team doing the analytics and an IT team doing the surrounding databases, real-time feeds and connections to other IT systems (Goldman Sachs is not like this, but their IT is pretty broken anyway). It is therefore very useful to have a clear division between the analytics and the surrounding IT -- ideally one that allows serialisation of the objects passed between the layers, so you can easily debug the analytics or the IT without having to debug one system inside the other.

Thanks, Marcus

On Tue, 26 May 2020 at 13:49, petr-tik notifications@github.com wrote:

I still think there is a real future in using Rust for financial maths. I'm just waiting for the rest of the world to cotton on to this idea

Hear hear! I guess the hardest problem to solve is acknowledging the moat of C++ and integrating rust with existing codebases as seamlessly as possible. Have you had any success or problems with that?

I agree it would be very good to use Mersenne Twister for the pseudo-random numbers.

If you are happy to look at my PR do you want that behind a feature flag or do you prefer Mersenne Twister replaces rand by default?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcusRainbow/QuantMath/issues/9#issuecomment-634003619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWFPP6DFKTM4KQXP2RWTADRTO3GJANCNFSM4FHPKB3Q .

MarcusRainbow commented 4 years ago

In terms of using other pdfs for option pricing, yes that can be useful. In practice, options are "priced" using vanilla black scholes, which is not really a model at all.

It would be a model if the volatility used was consistent across times and strikes, but by making it strike and time dependent, effectively we are just saying the "volatility" is just an expression of the price. Calculating the price is really just unpacking it from the so-called vol surface. That is what the black scholes formula is used for. At best, it is a way of interpolating prices between strikes and expiry dates, though even then you have to be really careful with dividends and vol events.

For this reason, BNP Paribas use a local vol model for pricing even vanilla options. However, it is a pain in the neck for them.

All that said, the more formulae the better. They all have their uses.

Marcus

On Tue, 26 May 2020, 15:25 Marcus Rainbow, marcus.rainbow@gmail.com wrote:

Hi,

Please could you point me to your pull request and I'll take a look. Personally, I'd be happy for Mersenne Twister to replace rand by default, though it would be useful to also support other pseudo-random and low-discrepancy sequences.

  • acknowledging the moat of C++ and integrating rust with existing codebases.*

Yes, that is a problem, though as you can see I have Rust roughly integrating with C++ in the library. My preference is to have a facade layer around an analytics library anyway. If you were working in a bank, there would generally be one team doing the analytics and an IT team doing the surrounding databases, real-time feeds and connections to other IT systems (Goldman Sachs is not like this, but their IT is pretty broken anyway). It is therefore very useful to have a clear division between the analytics and the surrounding IT -- ideally one that allows serialisation of the objects passed between the layers, so you can easily debug the analytics or the IT without having to debug one system inside the other.

Thanks, Marcus

On Tue, 26 May 2020 at 13:49, petr-tik notifications@github.com wrote:

I still think there is a real future in using Rust for financial maths. I'm just waiting for the rest of the world to cotton on to this idea

Hear hear! I guess the hardest problem to solve is acknowledging the moat of C++ and integrating rust with existing codebases as seamlessly as possible. Have you had any success or problems with that?

I agree it would be very good to use Mersenne Twister for the pseudo-random numbers.

If you are happy to look at my PR do you want that behind a feature flag or do you prefer Mersenne Twister replaces rand by default?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcusRainbow/QuantMath/issues/9#issuecomment-634003619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWFPP6DFKTM4KQXP2RWTADRTO3GJANCNFSM4FHPKB3Q .

petr-tik commented 4 years ago

I started poking at it - haven't got a PR yet, but have experienced problems building with the current version of rustc as well as failing tests.

Judging from previous commits you must run CI locally, so I guess flaky tests are ok?

MarcusRainbow commented 4 years ago

Yes I've had trouble with tests not reproducing on different architectures. That was the tests involving pseudorandom numbers. Hopefully changing to Mersenne Twister will address that. Are the other tests ok for you? Thanks, Marcus

On Tue, 26 May 2020, 21:04 petr-tik, notifications@github.com wrote:

I started poking at it - haven't got a PR yet, but have experienced problems building with the current version of rustc as well as failing tests.

Judging from previous commits you must run CI locally, so I guess flaky tests are ok?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcusRainbow/QuantMath/issues/9#issuecomment-634249609, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWFPP42FJPGEO557GLL3X3RTQODHANCNFSM4FHPKB3Q .