# Computational Finance

## Computational Finance

Computational finance uses numerical models to price contracts, measure risk, and optimize portfolios. Automatic differentiation is useful because most financial computations depend on many inputs: interest rates, volatilities, correlations, prices, credit spreads, liquidity parameters, and model calibration variables.

The central object is usually a value function

$$
V = F(x,\theta),
$$

where $x$ is market data and $\theta$ is a model parameter vector. The derivative

$$
\frac{\partial V}{\partial x}
$$

measures market sensitivity, while

$$
\frac{\partial V}{\partial \theta}
$$

measures model sensitivity.

### Greeks as Derivatives

In option pricing, sensitivities are called Greeks.

| Greek | Derivative | Meaning |
|---|---|---|
| Delta | $\partial V / \partial S$ | Sensitivity to underlying price |
| Gamma | $\partial^2 V / \partial S^2$ | Sensitivity of delta |
| Vega | $\partial V / \partial \sigma$ | Sensitivity to volatility |
| Theta | $\partial V / \partial t$ | Sensitivity to time |
| Rho | $\partial V / \partial r$ | Sensitivity to interest rate |

For a simple European option, the pricing function may be written as

$$
V = F(S,K,T,r,\sigma).
$$

AD computes the Greeks by differentiating the pricing program.

### Pricing Pipelines

A production pricing system is rarely a single formula. It is a pipeline:

```text
market data
    -> curve construction
    -> volatility surface construction
    -> model calibration
    -> pricing engine
    -> risk aggregation
```

Each stage may contain interpolation, optimization, simulation, linear algebra, and numerical integration.

AD can differentiate the entire pipeline, but practical systems often expose custom derivative rules for major components. This prevents the derivative from being tied to irrelevant implementation details.

### Monte Carlo Pricing

Many derivatives are priced by Monte Carlo simulation.

A generic estimator has the form

$$
V(\theta) =
\mathbb{E}[g(X_T(\theta))],
$$

where $X_T$ is a simulated terminal state and $g$ is the payoff.

The numerical estimator is

$$
\hat V(\theta) =
\frac{1}{N}
\sum_{i=1}^{N}
g(X_T^{(i)}(\theta)).
$$

AD can differentiate each simulated path with respect to $\theta$, then average the derivatives.

This gives the pathwise derivative estimator:

$$
\nabla_\theta \hat V =
\frac{1}{N}
\sum_{i=1}^{N}
\nabla_\theta g(X_T^{(i)}(\theta)).
$$

This works well when the simulation path and payoff are smooth in $\theta$.

### Discontinuous Payoffs

Financial payoffs often contain discontinuities. A digital option has payoff

$$
g(S_T)=\mathbf{1}_{S_T>K}.
$$

The pathwise derivative is zero almost everywhere and undefined at the strike. Direct AD gives a poor estimator.

Common responses include:

| Method | Idea |
|---|---|
| Smoothing | Replace hard payoff with smooth approximation |
| Likelihood ratio method | Differentiate probability density |
| Conditional expectation | Integrate out discontinuity analytically |
| Malliavin methods | Use stochastic calculus identities |
| Hybrid estimators | Combine pathwise and score-function terms |

AD works best when the computation is differentiable. Financial products often require estimator design before AD is useful.

### Algorithmic Adjoint Differentiation

In finance, reverse-mode AD is often called algorithmic adjoint differentiation, or AAD.

AAD is valuable because a portfolio may depend on thousands or millions of market inputs, but the output is often one scalar portfolio value or risk measure.

Reverse mode computes all first-order sensitivities at a cost proportional to a small multiple of the original valuation cost.

If

$$
V = F(x_1,\ldots,x_n),
$$

then AAD computes

$$
\nabla_x V
$$

efficiently even when $n$ is large.

This is why AAD became important for large-scale risk systems.

### Calibration

Financial models often have parameters chosen to match market prices.

Let model prices be

$$
P_i(\theta),
$$

and market prices be

$$
M_i.
$$

Calibration solves

$$
\min_\theta
\frac{1}{2}
\sum_i
\left(P_i(\theta)-M_i\right)^2.
$$

AD provides gradients:

$$
\nabla_\theta L =
J^\top(P(\theta)-M),
$$

where

$$
J_{ij} =
\frac{\partial P_i}{\partial \theta_j}.
$$

Calibration may contain constraints, bounds, and regularization. AD improves optimizer reliability, but it does not remove non-identifiability or poor model choice.

### Differentiating Through Calibration

Sometimes the calibrated model itself appears inside a larger computation.

Market data $m$ determines calibrated parameters:

$$
\theta^*(m) =
\arg\min_\theta L(\theta,m).
$$

A downstream price depends on the calibrated parameters:

$$
V = G(\theta^*(m),m).
$$

Differentiating through the calibration can be done by unrolling optimizer iterations, but that is expensive and sensitive to stopping criteria.

Implicit differentiation is often cleaner. At the optimum,

$$
\nabla_\theta L(\theta^*,m)=0.
$$

Differentiate this condition to obtain sensitivities of $\theta^*$ with respect to market data. This treats calibration as a solved optimization problem rather than a sequence of implementation steps.

### Interest Rate Curves

Curve construction maps market instruments to discount factors or forward rates.

A discount factor curve may be represented as

$$
D(t;\theta),
$$

where $\theta$ are knot values or spline coefficients.

Instrument prices depend on the curve:

$$
P_i = P_i(D).
$$

Bootstrapping solves curve parameters so that model prices match market quotes.

AD can compute sensitivities of portfolio value to curve quotes. These are often more useful than sensitivities to internal curve knots.

The derivative chain is:

$$
\text{market quotes}
\to
\text{curve parameters}
\to
\text{discount factors}
\to
\text{instrument values}
\to
\text{portfolio value}.
$$

### Value at Risk and Expected Shortfall

Risk systems often compute distributional quantities.

Value at Risk is a quantile:

$$
\operatorname{VaR}_\alpha =
\inf\{x : P(L \le x) \ge \alpha\}.
$$

Expected Shortfall averages losses beyond a quantile:

$$
\operatorname{ES}_\alpha =
\mathbb{E}[L \mid L \ge \operatorname{VaR}_\alpha].
$$

These are less smooth than ordinary expectations. Quantiles depend on ordering and thresholding. Direct AD through sorting or selection may produce unstable derivatives.

Practical systems often use smoothed quantile approximations, scenario-wise sensitivities, or analytic risk-factor approximations.

### XVA and Nested Simulation

Valuation adjustments such as CVA, DVA, FVA, and MVA require exposure profiles, counterparty credit models, collateral rules, funding assumptions, and often nested simulations.

The computational graph can be large:

```text
market scenarios
    -> future risk factors
    -> portfolio revaluation
    -> exposure profile
    -> default/funding model
    -> valuation adjustment
    -> sensitivities
```

AD is attractive because manual derivative implementation across this graph is error-prone.

The limiting factors are memory, stochastic variance, and discontinuous rules in collateral, netting, and default logic.

### Portfolio Optimization

Portfolio optimization chooses weights $w$ to optimize return, risk, or utility.

A common objective is

$$
L(w) =
-\mu^\top w
+
\lambda w^\top \Sigma w.
$$

The gradient is

$$
\nabla_w L =
-\mu
+
2\lambda \Sigma w.
$$

In more realistic systems, the objective includes transaction costs, constraints, stress losses, drawdown penalties, and nonlinear risk models. AD allows these objectives to be written directly as programs and differentiated for optimization.

### Constraints and KKT Systems

Many finance optimization problems are constrained:

$$
\min_x f(x)
$$

subject to

$$
g(x)=0,\qquad h(x)\le 0.
$$

At a regular optimum, the Karush-Kuhn-Tucker conditions define a system of equations and inequalities. Differentiating through an optimizer often means differentiating these optimality conditions.

This is another use of implicit differentiation. It avoids treating the optimizer as a black-box loop.

### Numerical Issues

Computational finance contains many numerical features that complicate AD.

| Feature | AD issue |
|---|---|
| Interpolation | Kinks at knots |
| Extrapolation | Unstable sensitivities |
| Payoff discontinuities | Zero or undefined pathwise derivatives |
| Calibration bounds | Active-set discontinuities |
| Monte Carlo randomness | Gradient variance |
| Sorting and quantiles | Non-smooth selection |
| Date logic | Discrete control flow |
| Rounding conventions | Discontinuous operations |

A derivative system must define which parts are mathematical and which parts are administrative. Date schedules, calendars, and rounding rules should usually be treated as fixed inputs, not differentiable variables.

### Practical Architecture

A robust differentiable finance system separates derivative concerns by layer.

| Layer | Differentiation treatment |
|---|---|
| Market data transforms | Quote-level sensitivities |
| Curves and surfaces | Custom interpolation derivatives |
| Calibration | Implicit or unrolled differentiation |
| Pricing engines | AD, analytic Greeks, or hybrid rules |
| Monte Carlo | Pathwise, likelihood ratio, or smoothed estimators |
| Portfolio aggregation | Reverse-mode accumulation |
| Risk reports | Scenario and factor-level derivatives |

This layered structure prevents the system from producing gradients that are formally correct but financially meaningless.

### Failure Modes

Differentiable finance systems fail in recognizable ways.

| Failure mode | Cause |
|---|---|
| Zero digital Greeks | Pathwise derivative through indicator payoff |
| Noisy sensitivities | Monte Carlo variance |
| Jumping risk numbers | Interpolation knot or active-set changes |
| Misleading curve risk | Sensitivity to internal knots instead of market quotes |
| Calibration instability | Non-identifiable model parameters |
| Excessive memory | Reverse mode through large simulation graphs |
| Wrong economic interpretation | Differentiating administrative logic |

AD gives derivative mechanics. Financial modeling still determines whether the derivative has useful economic meaning.

### Summary

In computational finance, automatic differentiation computes Greeks, calibration sensitivities, portfolio risks, and optimization gradients. Reverse-mode AD is especially valuable because many financial systems map large market data vectors to scalar values.

The main challenge is not basic differentiation. It is defining derivative semantics for stochastic simulation, discontinuous payoffs, calibration procedures, interpolation, constraints, and risk measures. Effective systems combine AD with financial estimator design, implicit differentiation, smoothing, and custom derivative rules.

