Class ReplicatingVarianceSwapEngine
- Namespace
- NanoQL.PricingEngines
- Assembly
- NanoQL.dll
The pricing engine for variance swaps by the cost of their replicating portfolio of out-of-the-money calls and puts, as Demeterfi, Derman, Kamal and Zou describe it ("A Guide to Volatility and Variance Swaps", 1999).
public static class ReplicatingVarianceSwapEngine
- Inheritance
-
ReplicatingVarianceSwapEngine
- Inherited Members
Remarks
The portfolio replicates the log contract piecewise linearly between the strikes given, each option priced by the analytic European engine on the process. The fair variance is the drift's, less the log contract's adjustment at the forward, plus the portfolio's value carried to maturity; the NPV is the notional times the fair variance less the strike, discounted on the risk-free curve, and signed by the position. The additional result "optionWeights" holds each option's payoff and weight, calls first.
The drift is 2·(z_r − z_q) and the forward S·D_q/D_r, with z_q and D_q the dividend curve's zero rate and discount
read by the maturity date. QuantLib's drift is 2·z_r and its forward S/D_r, as if the dividend yield were zero,
which misprices the fair variance at any other yield; its value is that of a zero-dividend process whose risk-free
discount is D_r/D_q, which is the check (Divergences/ReplicatingVarianceSwapDividendTests.cs). At a zero
dividend yield the value is QuantLib's.
A put strike at or below the strike step refuses: the portfolio's added end strike is then 0, whose log payoff
QuantLib divides into a NaN or an infinite variance (Divergences/ReplicatingVarianceSwapRefusalTests.cs).
The variance is per year of the swap's time on the risk-free curve's day counter from the earliest reference date of
the process's structures, each accruing nothing before its own. QuantLib's time is the risk-free curve's own, so
where a later risk-free curve beside an earlier volatility shortens it, QuantLib divides the volatility's variance
by the shorter time: 1.1% high at a year on a curve dated four days after the volatility, 2.3 times at a week. Where
no structure is dated before the risk-free curve, the time is QuantLib's
(Divergences/VarianceSwapMismatchedTimesTests.cs).
Methods
Calculate(VarianceSwap, EvaluationContext, GeneralizedBlackScholesProcess, double, ReadOnlySpan<double>, ReadOnlySpan<double>)
Prices a variance swap.
public static VarianceSwapResults Calculate(VarianceSwap swap, EvaluationContext context, GeneralizedBlackScholesProcess process, double dk = 5, ReadOnlySpan<double> callStrikes = default, ReadOnlySpan<double> putStrikes = default)
Parameters
swapVarianceSwapThe variance swap.
contextEvaluationContextThe evaluation context.
processGeneralizedBlackScholesProcessThe Black-Scholes process the options are priced on.
dkdoubleThe strike step beyond the outermost strikes.
callStrikesReadOnlySpan<double>The call strikes.
putStrikesReadOnlySpan<double>The put strikes.
Returns
- VarianceSwapResults
The swap's results: its NPV, its fair variance, and the additional result "optionWeights".
Exceptions
- ArgumentNullException
The swap, the context or the process is null.
- ArgumentException
No call or no put strike is given, the lowest put strike isn't positive, the lowest call strike and the highest put strike differ, or a put strike is at or below
dk.- NanoQLException
The swap's strike or notional isn't positive, or a curve or the volatility can't be read at the maturity.