Welcome to the world of TorchQuant, an innovative and comprehensive derivatives pricing library that leverages the power of PyTorch’s automatic differentiation and GPU/TPU acceleration to provide a robust framework for asset pricing, risk management, and model calibration.
Advantages of TorchQuant
- Fast and accurate implementation of the
erffunction, making normal distribution calculations two orders of magnitude faster than scipy.stats. - Overcomes the limitations of the finite difference method in quantitative finance, particularly re-evaluation computations and approximation errors.
- Offers optional hardware acceleration for increased performance.
Key Features
Asset Pricing
- Option pricing models including BSM, Heston, binomial tree, and Monte Carlo simulations.
- Bond pricing models for callable, putable, and convertible bonds.
- Advanced options support for American, Bermudan, Asian, barrier, and look-back options.
- Implied volatility calculation using the Let’s be Rational algorithm.
- Pricing for futures and currencies.
Risk Management
- Greeks calculation utilizing Malliavin calculus.
- Scenario analysis and stress testing.
- Market risk measures such as VaR and Expected Shortfall.
- Credit risk models including both structural and reduced form models.
- Valuation adjustments like CVA, DVA, MVA, and FVA.
Neural Network-based Model Calibration
- Calibration for stochastic models like Heston, Vasicek, and SABR.
- Local volatility models including Dupire.
- Optimal Transport for enhanced model calibration.
Sequence Methods
- Seq2Seq PDE solvers for solving partial differential equations.
Installation Guide
To install TorchQuant, simply use the following pip command:
pip install -U torchquantlib
Usage Examples
Exotic Options
Let’s illustrate some common pricing methods using TorchQuant:
American Option
import torch
from torchquantlib.core.asset_pricing.option_pricing.american_option import american_option
spot = torch.tensor(100.0)
strike = torch.tensor(105.0)
expiry = torch.tensor(1.0)
volatility = torch.tensor(0.2)
rate = torch.tensor(0.05)
steps = 100
price = american_option(call, spot, strike, expiry, volatility, rate, steps)
print(f'American Option Price: {price.item()}')
Bermudan Option
import torch
from torchquantlib.core.asset_pricing.option_pricing.bermudan_option import bermudan_option
spot = torch.tensor(100.0)
strike = torch.tensor(105.0)
expiry = torch.tensor(1.0)
volatility = torch.tensor(0.2)
rate = torch.tensor(0.05)
steps = 100
exercise_dates = torch.tensor([30, 60, 90])
price = bermudan_option(call, spot, strike, expiry, volatility, rate, steps, exercise_dates)
print(f'Bermudan Option Price: {price.item()}')
Asian Option
import torch
from torchquantlib.core.asset_pricing.option_pricing.asian_option import asian_option
spot = torch.tensor(100.0)
strike = torch.tensor(105.0)
expiry = torch.tensor(1.0)
volatility = torch.tensor(0.2)
rate = torch.tensor(0.05)
steps = 100
price = asian_option(call, spot, strike, expiry, volatility, rate, steps)
print(f'Asian Option Price: {price.item()}')
Greeks Calculation via Malliavin Calculus
import torch
from torchquantlib.risk.greeks.malliavin import malliavin_greek
option_price = torch.tensor(10.0)
underlying_price = torch.tensor(100.0)
volatility = torch.tensor(0.2)
expiry = torch.tensor(1.0)
greek = malliavin_greek(option_price, underlying_price, volatility, expiry)
print(f'Malliavin Greek: {greek.item()}')
Explanation: Code Usage Analogy
Think of creating derivatives pricing models similar to a chef preparing various exquisite dishes. Each option type (American, Bermudan, Asian) is like a unique recipe that requires specific ingredients (parameters like spot, strike, expiry, etc.). In this kitchen, the torchquantlib library serves as your toolbox, providing utensils and appliances that help you get everything done efficiently. Just like different cooking methods yield distinct flavors, using the right function from TorchQuant offers tailored solutions for each financial option type.
Troubleshooting
If you encounter any issues or have questions while using TorchQuant, here are some solutions:
- Ensure that your Python installation is compatible (Python 3.6 or newer is required).
- Check that PyTorch is properly installed and matches the version supported by TorchQuant.
- Consult the documentation for detailed usage examples and explanations.
- For community support and collaboration on AI development projects, feel free to reach out.
- For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
At fxis.ai, we believe that advancements like TorchQuant are essential for the future of AI, enabling more effective solutions in finance. Our team continuously explores innovative methodologies to push the boundaries of artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
Roadmap
Future Developments
- Q4 2024: Develop an interactive dashboard for visualizing risk metrics and option pricing.
- Q3 2025: Add support for more asset classes such as commodities and real estate; enhance the calibration module to support broader models and optimization techniques.

