Main Content

optSensByHestonNI

Option price and sensitivities by Heston model using numerical integration

Description

PriceSens = optSensByHestonNI(Rate,AssetPrice,Settle,Maturity,OptSpec,Strike,V0,ThetaV,Kappa,SigmaV,RhoSV) computes vanilla European option price and sensitivities by Heston model, using numerical integration methods.

Note

Alternatively, you can use the Vanilla object to calculate price or sensitivities for vanilla options. For more information, see Get Started with Workflows Using Object-Based Framework for Pricing Financial Instruments.

example

PriceSens = optSensByHestonNI(___,Name,Value) adds optional name-value pair arguments.

example

Examples

collapse all

optSensByHestonNI uses numerical integration to compute option sensitivities and then to plot option sensitivity surfaces.

Define Option Variables and Heston Model Parameters

AssetPrice = 80;
Rate = 0.03;
DividendYield = 0.02;
OptSpec = 'call';

V0 = 0.04;
ThetaV = 0.05;
Kappa = 1.0;
SigmaV = 0.2;
RhoSV = -0.7;

Compute the Option Sensitivity for a Single Strike

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, 6);
Strike = 80; 

Delta = optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, 'OutSpec', "delta")
Delta = 
0.5775

Compute the Option Sensitivities for a Vector of Strikes

The Strike input can be a vector.

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, 6);
Strike = (76:2:84)';

Delta = optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, 'OutSpec', "delta")
Delta = 5×1

    0.7043
    0.6433
    0.5775
    0.5083
    0.4377

Compute the Option Sensitivities for a Vector of Strikes and a Vector of Dates of the Same Lengths

Use the Strike input to specify the strikes. Also, the Maturity input can be a vector, but it must match the length of the Strike vector if the ExpandOutput name-value pair argument is not set to "true".

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, [12 18 24 30 36]); % Five maturities
Strike = [76 78 80 82 84]'; % Five strikes

Delta = optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, ...
    'OutSpec', "delta") % Five values in vector output
Delta = 5×1

    0.6848
    0.6413
    0.6095
    0.5841
    0.5631

Expand the Output for a Surface

Set the ExpandOutput name-value pair argument to "true" to expand the output into a NStrikes-by-NMaturities matrix. In this case, it is a square matrix.

Delta = optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, ...
    'OutSpec', "delta", 'ExpandOutput', true) % (5 x 5) matrix output
Delta = 5×5

    0.6848    0.6762    0.6703    0.6654    0.6609
    0.6416    0.6413    0.6404    0.6390    0.6372
    0.5960    0.6048    0.6095    0.6119    0.6129
    0.5485    0.5671    0.5776    0.5841    0.5882
    0.4997    0.5286    0.5452    0.5559    0.5631

Compute the Option Sensitivities for a Vector of Strikes and a Vector of Dates of Different Lengths

When ExpandOutput is "true", NStrikes do not have to match NMaturities (that is, the output NStrikes-by-NMaturities matrix can be rectangular).

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, 12*(0.5:0.5:3)'); % Six maturities
Strike = (76:2:84)'; % Five strikes

Delta = optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, ...
    'OutSpec', "delta", 'ExpandOutput', true)  % (5 x 6) matrix output
Delta = 5×6

    0.7043    0.6848    0.6762    0.6703    0.6654    0.6609
    0.6433    0.6416    0.6413    0.6404    0.6390    0.6372
    0.5775    0.5960    0.6048    0.6095    0.6119    0.6129
    0.5083    0.5485    0.5671    0.5776    0.5841    0.5882
    0.4377    0.4997    0.5286    0.5452    0.5559    0.5631

Compute the Option Sensitivities for a Vector of Strikes and a Vector of Asset Prices

When ExpandOutput is "true", the output can also be a NStrikes-by-NAssetPrices rectangular matrix by accepting a vector of asset prices.

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, 12); % Single maturity
ManyAssetPrices = [70 75 80 85]; % Four asset prices
Strike = (76:2:84)'; % Five strikes

Delta = optSensByHestonNI(Rate, ManyAssetPrices, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, ...
    'OutSpec', "delta", 'ExpandOutput', true) % (5 x 4) matrix output
Delta = 5×4

    0.4293    0.5708    0.6848    0.7705
    0.3737    0.5193    0.6416    0.7364
    0.3200    0.4668    0.5960    0.6994
    0.2693    0.4143    0.5485    0.6597
    0.2226    0.3628    0.4997    0.6177

Plot Option Sensitivity Surfaces

The Strike and Maturity inputs can be vectors. Set ExpandOutput to "true" to output the surfaces as NStrikes-by-NMaturities matrices.

Settle = datetime(2017,6,29);
Maturity = datemnth(Settle, 12*[1/12 0.25 (0.5:0.5:3)]');
Times = yearfrac(Settle, Maturity);
Strike = (2:2:200)';

[Delta, Gamma, Rho, Theta, Vega, VegaLT] = ...
    optSensByHestonNI(Rate, AssetPrice, Settle, Maturity, OptSpec, Strike, ...
    V0, ThetaV, Kappa, SigmaV, RhoSV, 'DividendYield', DividendYield, ...
    'OutSpec', ["delta", "gamma", "rho", "theta", "vega", "vegalt"], ...
    'ExpandOutput', true);

[X,Y] = meshgrid(Times,Strike);

figure;
surf(X,Y,Delta);
title('Delta');
xlabel('Years to Option Expiry');
ylabel('Strike');
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title Delta, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

figure;
surf(X,Y,Gamma)
title('Gamma')
xlabel('Years to Option Expiry')
ylabel('Strike')
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title Gamma, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

figure;
surf(X,Y,Rho)
title('Rho')
xlabel('Years to Option Expiry')
ylabel('Strike')
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title Rho, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

figure;
surf(X,Y,Theta)
title('Theta')
xlabel('Years to Option Expiry')
ylabel('Strike')
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title Theta, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

figure;
surf(X,Y,Vega)
title('Vega')
xlabel('Years to Option Expiry')
ylabel('Strike')
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title Vega, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

figure;
surf(X,Y,VegaLT)
title('VegaLT')
xlabel('Years to Option Expiry')
ylabel('Strike')
view(-112,34);
xlim([0 Times(end)]);

Figure contains an axes object. The axes object with title VegaLT, xlabel Years to Option Expiry, ylabel Strike contains an object of type surface.

Input Arguments

collapse all

Continuously compounded risk-free interest rate, specified as a scalar decimal value.

Data Types: double

Current underlying asset price, specified as numeric value using a scalar or a NINST-by-1 or NColumns-by-1 vector.

For more information on the proper dimensions for AssetPrice, see the name-value pair argument ExpandOutput.

Data Types: double

Option settlement date, specified as a NINST-by-1 or NColumns-by-1 vector using a datetime array, string array, or date character vectors. The Settle date must be before the Maturity date.

To support existing code, optSensByHestonNI also accepts serial date numbers as inputs, but they are not recommended.

For more information on the proper dimensions for Settle, see the name-value pair argument ExpandOutput.

Option maturity date, specified as a NINST-by-1 or NColumns-by-1 vector using a datetime array, string array, or date character vectors.

To support existing code, optSensByHestonNI also accepts serial date numbers as inputs, but they are not recommended.

For more information on the proper dimensions for Maturity, see the name-value pair argument ExpandOutput.

Definition of the option, specified as a NINST-by-1 or NColumns-by-1 vector using a cell array of character vectors or string arrays with values 'call' or 'put'.

For more information on the proper dimensions for OptSpec, see the name-value pair argument ExpandOutput.

Data Types: cell | string

Option strike price value, specified as a NINST-by-1, NRows-by-1, NRows-by-NColumns vector of strike prices.

For more information on the proper dimensions for Strike, see the name-value pair argument ExpandOutput.

Data Types: double

Initial variance of the underlying asset, specified as a scalar numeric value.

Data Types: double

Long-term variance of the underlying asset, specified as a scalar numeric value.

Data Types: double

Mean revision speed for the underlying asset, specified as a scalar numeric value.

Data Types: double

Volatility of the variance of the underlying asset, specified as a scalar numeric value.

Data Types: double

Correlation between the Wiener processes for the underlying asset and its variance, specified as a scalar numeric value.

Data Types: double

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: PriceSens = optSensByHestonFFT(Rate, AssetPrice, Settle,Maturity, OptSpec, Strike, V0, ThetaV, Kappa, SigmaV, RhoSV,'Basis',7)

Day-count of the instrument, specified as the comma-separated pair consisting of 'Basis' and a scalar using a supported value:

  • 0 = actual/actual

  • 1 = 30/360 (SIA)

  • 2 = actual/360

  • 3 = actual/365

  • 4 = 30/360 (PSA)

  • 5 = 30/360 (ISDA)

  • 6 = 30/360 (European)

  • 7 = actual/365 (Japanese)

  • 8 = actual/actual (ICMA)

  • 9 = actual/360 (ICMA)

  • 10 = actual/365 (ICMA)

  • 11 = 30/360E (ICMA)

  • 12 = actual/365 (ISDA)

  • 13 = BUS/252

For more information, see Basis.

Data Types: double

Continuously compounded underlying asset yield, specified as the comma-separated pair consisting of 'DividendYield' and a scalar numeric value.

Data Types: double

Volatility risk premium, specified as the comma-separated pair consisting of 'VolRiskPremium' and a scalar numeric value.

Data Types: double

Flag indicating Little Heston Trap formulation by Albrecher et al, specified as the comma-separated pair consisting of 'LittleTrap' and a logical:

  • true — Use the Albrecher et al formulation.

  • false — Use the original Heston formation.

Data Types: logical

Define outputs, specified as the comma-separated pair consisting of 'OutSpec' and a NOUT- by-1 or a 1-by-NOUT string array or cell array of character vectors with supported values.

Note

"vega" is the sensitivity with respect the initial volatility sqrt(V0). In contrast, "vegalt" is the sensitivity with respect to the long-term volatility sqrt(ThetaV).

Example: OutSpec = ["price","delta","gamma","vega","rho","theta","vegalt"]

Data Types: string | cell

Absolute error tolerance for numerical integration, specified as the comma-separated pair consisting of 'AbsTol' and a scalar numeric value.

Data Types: double

Relative error tolerance for numerical integration, specified as the comma-separated pair consisting of 'RelTol' and a scalar numeric value.

Data Types: double

Numerical integration range used to approximate the continuous integral over [0 Inf], specified as the comma-separated pair consisting of 'IntegrationRange' and a 1-by-2 vector representing [LowerLimit UpperLimit].

Data Types: double

Framework for computing option prices and sensitivities using numerical integration of models, specified as the comma-separated pair consisting of 'Framework' and a scalar string or character vector with the following values:

  • "heston1993" or 'heston1993' — Method used in Heston (1993)

  • "lewis2001" or 'lewis2001' — Method used in Lewis (2001)

Data Types: char | string

Flag to expand the outputs, specified as the comma-separated pair consisting of 'ExpandOutput' and a logical:

  • true — If true, the outputs are NRows-by- NColumns matrices. NRows is the number of strikes for each column and it is determined by the Strike input. For example, Strike can be a NRows-by-1 vector, or a NRows-by-NColumns matrix. NColumns is determined by the sizes of AssetPrice, Settle, Maturity, and OptSpec, which must all be either scalar or NColumns-by-1 vectors.

  • false — If false, the outputs are NINST-by-1 vectors. Also, the inputs Strike, AssetPrice, Settle, Maturity, and OptSpec must all be either scalar or NINST-by-1 vectors.

Data Types: logical

Output Arguments

collapse all

Option prices or sensitivities, returned as a NINST-by-1, or NRows-by-NColumns, depending on ExpandOutput. The name-value pair argument OutSpec determines the types and order of the outputs.

More About

collapse all

References

[1] Heston, S. L. “A Closed-Form Solution for Options with Stochastic Volatility with Applications to Bond and Currency Options.” The Review of Financial Studies. Vol 6. No. 2. 1993.

[2] Lewis, A. L. “A Simple Option Formula for General Jump-Diffusion and Other Exponential Levy Processes.” Envision Financial Systems and OptionCity.net, 2001.

Version History

Introduced in R2018a

expand all