Fast and scalable server for derivative pricing
- Async runtime
- Multithreading for compute intensive pricing
- swagger ui
- EuropeanOptions
- Black76
Rust for web sevrer and compute
Although we could easily achieve the same output with Python and Django/Flask the performance sensitive nature of our task begs for a better solution. I chose Rust, a modern language compiled to Assembly just like C, for the reasons outlined below:
- No garbage collector, making our server extremely fast and efficient
- async frameworks like Actix
- multi-core utilization for compute intensive work (options pricing). Unlike Python, we are not limited by GIL and hence can utilise all cores of the running host.
- Easy integration with Python. For example ultibi and polars are written in Rust and have very well-functioning python interface (for more details see pyo3)
Naturally, Market Data comes in various shapes and forms. A spot is a totally different object then say Volatility Surface. Hence, Non Structured database would be preffered to
- Importantly we use name (name of the market data object, eg US_OIS) and as_of (observation date of the object) as a unique index.
- docker
From the top level directory:
docker-compose up --build
- this builds two docker images (one from Dockerfile
which is the backend server and another is the standard mongo image) and run them.
To check out swagger docs
navigate to: http://localhost:8000/swagger-ui/
in your browser. You will see:
- Upload Market Data:
curl.exe -H 'content-type: application/json' -X POST http://localhost:8000/api/marketdata -d '[ {\"name\":\"Brent\",\"as_of\":\"2021-12-01\",\"value\":95.6},
{\"name\":\"OIS\",\"as_of\":\"2021-12-01\",\"day_count_conv\":\"Act365\",\"compounding\":\"Continuous\",\"values\":[[\"2021-12-02\",0.001],[\"2021-12-15\",0.02],[\"2021-12-31\",0.03]]},
{\"name\":\"ImplVol_Brent_100\",\"as_of\":\"2021-12-01\",\"day_count_conv\":\"Act365\",\"compounding\":\"Continuous\",\"values\":[[\"2021-12-02\",0.05],[\"2021-12-15\",0.1],[\"2021-12-31\",0.2]]}
]'
- Review/Retrieve Market Data:
curl.exe -X GET 'http://localhost:8000/api/marketdata?name=Brent&as_of=2021-12-01'
- Price an Option:
curl.exe -H 'content-type: application/json' -X POST http://localhost:8000/api/price -d '{\"type\":\"PriceRequest\",\"instrument\":{\"type\":\"EurpoeanOption\",\"underlying\":\"Brent\",\"yield_curve\":\"OIS\",\"implied_vol\":\"ImplVol_Brent_100\",\"strike\":100.0,\"direction\":\"Call\",\"exp\":\"2023-11-30\"},\"date\": \"2021-12-01\"}'
- Delete Market Data:
curl.exe -X DELETE 'http://localhost:8000/api/marketdata?name=Brent&as_of=2021-12-01'