attack68 / rateslib

A fixed income library for pricing bonds and bond futures, and derivatives such as IRS, cross-currency and FX swaps. Contains tools for full Curveset construction with market standard optimisers and automatic differention (AD) and risk sensitivity calculations including delta and cross-gamma.
https://rateslib.readthedocs.io/en/latest/
Other
152 stars 28 forks source link

Rateslib Performance on large number of instuments #420

Closed ChrisSun19921016 closed 1 month ago

ChrisSun19921016 commented 1 month ago

Hi

Is there a faster way of pricing a large number of instruments in rateslib? Say I have a calibrated curve and would like to calculate rate for 10000 instrument, what is a better way than running a for loop on these 10000 instruments?

Chris

attack68 commented 1 month ago

See https://www.linkedin.com/pulse/rateslib-performance-1000-irs-rateslib/ and https://www.linkedin.com/pulse/rateslib-performance-1000-swaps-2024-rateslib-pufyf/

There are a number of things these discuss.

1) Turning off AD on the curves if you just want to value them and not obtain any risk sensitivities. 2) Add them to a Portfolio and setting cores in your defaults so that it can parallel calculate.

Interested to hear how you get on. I guess it is also relevant what type of Instruments you are building.

Also a few days ago you posted on QuantStack about turns in XCCY curves. Did you manage to solve the issue?

ChrisSun19921016 commented 1 month ago

ah thanks for the info.

Tried with Portfolio but seems it could only calculate NPV instead of implied yield. Also, tried testing it on 1000 instruments, speed of calculation seems similar to just calculating individually.

That said, I have found a way of work around it, without having to calculate large amount of instruments.

Yes I have managed to found a way to model XCCY turns in rateslib, your page on "how to handle turns" is actually pretty useful!