r/rust • u/RustQuant • Mar 23 '23
RustQuant: a Rust library for quantitative finance.
Hi all, just posting as I would love to get some feedback on my project `RustQuant` which is available at https://crates.io/crates/RustQuant and https://github.com/avhz/RustQuant .
It's currently just a spare-time project and I welcome any criticisms and/or suggestions.
Some features include:
- reverse mode automatic (algorithmic) differentiation,
- a numerical integrator (double exponential aka. tanh-sinh)
- option pricing (closed-form, Monte-Carlo),
- stochastic process generation.
It's very early stages and hopefully I can add more features soon.
13
u/Snakehand Mar 23 '23 edited Mar 23 '23
Nice contribution, some comments:
There are a lot of f64 type annotation where the compiler will correctly infer the type. I think it is more idiomatic to only give type hints where the compiler has asked for it.
Also I spotted some stringly typed variables that results in code like this:
Firstly the CamelCase variable name is odd, and secondly it is the perfect use case for an enum + match statement, which is more ergonomic, as the error will be spotted compile time, and not cause a panic at run time when an incorrect &str is passed as an argument.
3
u/throw3142 Mar 24 '23
Nice! I think this looks really interesting and I might even use it myself. There's plenty to be learned by simply reading the source code.
I was surprised to see a full implementation of an autodiff engine in there - that seems a little overkill, have you considered using one of the existing libraries?
In terms of feedback, I was pleased to see the parameters S, K, r, etc properly documented in the option structs (like EuropeanOption). Too many times in financial and scientific computing, people simply use one-letter variable names from some equation, which may be hard for others to understand (even if they seem obvious to you). But this was very good.
I did notice that some of this kind of documentation was missing in the bond implementations (CoxIngersollRoss and Vasicek). It would be really useful for anyone not already experienced in quant finance (like myself) who's going through the docs or the source code. Granted, an explanation is present in the module docs anyway, so this is kind of a nitpick. I guess I just found it a little hard to understand and would have liked field-level docs as well.
3
u/Busy-Perspective-920 Mar 23 '23
Thank you.