SkillAgentSearch skills...

Torchquant

PyTorch for Quantitative Finance : Refine Derivatives Hedging and Pricing with Architecture Alightment in Operators

Install / Use

/learn @jialuechen/Torchquant

README

<div align=center> <img src="assets/torchquant.png" width="20%" loc>

PyPI version License: Apache-2.0 PyPI Downloads Python versions PyTorch version Documentation Status

</div>

TorchQuant is a high-performance, differentiable quantitative finance library built on top of PyTorch's automatic differentiation and GPU acceleration. It provides comprehensive tools for derivatives pricing, risk management, and stochastic model calibration. The core innovation in this pytorch extension library is to delicately convert various exotic characteristics into corresponding deep learing mechanisms (see the below table). More kinds of derivatives will be supported as the library grows.

Financial Instruments and Deep Mechanisms Analogy (Partial Examples)

This table outlines the analogy between financial instruments and neural network components, reflecting how structural and functional characteristics of financial derivatives can inspire the design of all the pricing components in TorchQuant.

| Financial Instrument / Attribute | Core Feature / Description | Analogous Neural Network Mechanism | Analogy Explanation | |----------------------------------------|--------------------------------------------------------|-----------------------------------------------------|--------------------------------------------------------------------------------------| | European Option | Call: max(S − K, 0); Put: max(K − S, 0) | ReLU | Activation occurs when input exceeds or falls below a threshold | | Softplus Option Proxy | Smooth version of option payoff | Softplus Activation Function | Provides smooth derivatives, suitable for differentiable training | | American Option | Early exercise right; optimal stopping strategy | Optimal Stopping / Gated RNN | Dynamic decision-making akin to gating mechanisms | | Bermudan Option | Exercise allowed on specific discrete dates | Scheduled Halting / Discrete Gating | Like dynamic layers with only certain positions allowing early exit | | Parisian Option | Knock-in/out only if condition persists for duration | Temporal Gate / Duration Accumulator | Requires a condition to hold continuously for a given duration to trigger action | | Everest Option | Long-dated, multiple barriers, path-dependent | Deep Memory Attention + Gated RNN Layers | Multi-barrier tracking and long-term conditioning via memory-driven control | | Himalaya Option | Stage-wise best-of selection, dropping winners | Top-k Routing + Feature Elimination | Picks best performer at each stage, then excludes it from future decisions | | Altiplano Option | Payoff depends jointly on FX and IR movements | Cross-Modality Attention / Dual Input Fusion | Combines dual risk channels like FX and interest rates through joint attention | | Exchange Option | Option to enter an asset swap | Conditional Task-Switch Module / Policy Redirector | Switches task head at trigger point to alternate payoff policy | | Accumulator Option | Recurrent gain/loss accumulation with early exit | Loss Aggregation + Time-Gated RNN | Iteratively accumulates risk/reward, may terminate on breach | | Barrier Option | Activation/deactivation upon reaching a barrier | Conditional Activation / Dropout-like Mechanism | Activation triggered by specific conditions | | Asian Option | Payoff depends on average price over time | Average Pooling | Aggregates information over time, similar to pooling layers | | Lookback Option | Payoff depends on maximum or minimum asset price | Self-Attention / Max Pooling | Focuses on historical extrema, akin to attention mechanisms | | Cliquet Option | Periodic capped accumulation of returns | Recurrent Accumulation with Clipping | Accumulates over time with upper/lower bounds | | Chooser Option | Choice between call or put at a future date | Routing / Path Selection | Dynamic selection of computational paths based on conditions | | Digital Option | Fixed payoff if condition is met; zero otherwise | Binary Neuron / Step Function | Outputs fixed value upon meeting a threshold | | Auto-callable Note | Early redemption upon reaching certain conditions | Early Exit Policy | Mechanism for early stopping based on specific criteria | | Rainbow Option | Payoff based on multiple underlying assets | Multi-Modal Fusion / Feature Aggregation | Combines multiple inputs, similar to multi-head attention | | Basket Option | Payoff based on weighted aggregation of multiple assets | Weighted Sum / Attention Pooling | Similar to attention-based input fusion over multi-stream inputs | | Spread Option | Payoff based on difference between assets | Difference Layer / Contrastive Module | Captures relative value gap like pairwise ranking or Siamese net | | Snowball Option | Knock-in/knock-out with structured returns | Nested Conditional Networks / Loss Scheduling | Complex conditional structures with layered conditions | | Shout Option | Lock in payoff once during life, compare with terminal | Checkpoint / Write-Once Memory / Path Override | Saves a snapshot for later comparison, simulating a "one-time memory commit" | | Reverse Convertible Bond | Converts to equity under certain conditions | Cost-sensitive Loss | Loss function varies based on specific conditions | | Capital Protected Note | Downside protection with capped upside | Leaky ReLU | Activation with lower bound protection and upper limit | | Credit Default Swap (CDS) | Protection against default risk | Adversarial Training / Defense Mechanisms | Enhances model robustness against worst-case scenarios | | Credit Index (CDX) | Basket of credit exposures | Ensemble Adversarial Defense | Combines multiple defenses to mitigate diverse risks | | Tranches | Structured layers with prioritized risk absorption | Deep Layered Modules / Loss Routing | Similar to deep networks where higher layers absorb losses first | | Credit Default Swaption | Option to enter CDS at a fixed spread in future | Meta-Gated Path Selector / Delayed Activation | Path activation based on credit risk trigger, similar to conditional policy | | Total Return Swap (TRS) | Receive full asset return, pay fixed rate | Cross-Head Surrogate Module / Distilled Proxy | Like one module receiving another's performance without owning full state |

Features

  • Asset Pricing:

    • Advanced options pricing support ranging from vanilla to exotics, shown in above tale.
    • Reducing computation costs for exotics options (a good example is the lookback option pricing that leverages max pooling, reducing time complexity from Monte Carlo simulation O(N*T) to O(T/L+N), L is the window length and N if the number of windows)
    • Bond pricing models including callable, putable, and convertible bonds.
    • Implied volatility calculation using "Let's be rational" algorithm.
  • Risk Management:

    • Greeks calculation utilizing AAD.
    • Market risk measures such as VaR and Expected Shortfall.
  • Neural Network-based Model Calibration:

    • Calibration for stochastic models like Heston, Vasicek, SABR, and more.
    • Local volatility models including Dupire.
  • Sequence Methods:

    • Seq2Seq PDE solvers

Examples

<div> <img src="assets/lookback_option.png" loc> <img src="assets/asian_option.png" loc> </div>

Installation

You can install torchquant via pip:

pip install --up

Related Skills

View on GitHub
GitHub Stars195
CategoryFinance
Updated1mo ago
Forks28

Languages

Python

Security Score

100/100

Audited on Feb 22, 2026

No findings