Generated banner for Matlab Price Instrument
Generated logo for Matlab Price Instrument

Matlab Price Instrument

MathWorksOfficialCreated by MathWorks

  • Skill
  • Tool integration
  • Science and research
  • BSD-2-Clause
  • No issues found

From the author

Price financial instruments in MATLAB using the Financial Instruments Toolbox. Route to the appropriate numerical method reference based on the user's request: Monte Carlo simulation (AssetMonteCarlo, IRMonteCarlo, RoughVolMonteCarlo), FFT / Numerical Integration (Vanilla European options), or Interest-Rate Trees (option-embedded bonds with IRTree). Use when the user asks to price financial instruments or compute Greeks using any of these methods. Use one of the following models depending on the pricing method and instrument: Black-Scholes, Bachelier, Heston, Bates, Merton, Hull-White, Black-Karasinski, Black-Derman-Toy, Cox-Ingersoll-Ross, Linear Gaussian 2 Factor (G2PP), Brace-Gatarek-Musiela (BGM), SABR-BGM, RoughBergomi, RoughHeston.
— the description by MathWorks

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured approach to pricing financial instruments and calculating sensitivities (Greeks) within MATLAB. It guides users through the Financial Instruments Toolbox, routing requests to the appropriate numerical method—Monte Carlo simulation, FFT/Numerical Integration, or Interest-Rate Trees—based on the specific instrument and model requirements. It emphasizes modern object-oriented practices, such as using finpricer, fininstrument, and finmodel, while discouraging legacy functions to ensure efficient and accurate financial modeling.

What it does

  • Routes pricing requests to Monte Carlo, FFT/Numerical Integration, or IR Tree methods.
  • Supports a wide range of models including Black-Scholes, Heston, Hull-White, and SABR-BGM.
  • Facilitates the calculation of Greeks such as delta, vega, gamma, theta, and rho.
  • Provides standardized workflows for constructing instruments, models, and pricers.
  • Enforces best practices like using datetime objects and modern object-oriented APIs.
  • Enables pricing of complex instruments like exotic options and callable bonds.

When to use it

  • When pricing options, bonds, swaps, or derivatives in MATLAB.
  • When you need to compute Greeks or sensitivities for financial instruments.
  • When choosing between simulation, tree-based, or transform-based pricing methods.
  • When working with stochastic volatility or jump-diffusion models.
  • When you need to compare pricing results across different numerical methods.

Advantages

  • Ensures consistent and modern coding standards using the latest toolbox APIs.
  • Reduces errors by routing to the most appropriate numerical method for the instrument.
  • Simplifies the implementation of complex financial models and sensitivity analysis.
  • Provides clear guidance on object-oriented instrument construction.
  • Prevents common pitfalls like using legacy functions or incorrect date formats.

Usage examples

“How do I price an Asian option using Monte Carlo in MATLAB?”
The agent will guide you to use the AssetMonteCarlo pricer, detailing the setup of the stochastic model, instrument, and the simulation parameters required for path-dependent options.
“Price a callable fixed-rate bond using a Hull-White tree.”
The agent will provide the workflow for creating an OptionEmbeddedFixedBond instrument and a HullWhite model, then using the IRTree pricer to calculate the price.
“Calculate the delta and vega for a European vanilla call option under Heston.”
The agent will direct you to the FFT/Numerical Integration reference, showing how to use the price function with the Heston model to return both the price and the requested Greeks.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/matlab/matlab-price-instrument/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip matlab-price-instrument.zip -d .agents/skills

Documentation by MathWorks

Price Financial Instruments in MATLAB

Price financial instruments in MATLAB using the Financial Instruments Toolbox. Route to the correct numerical pricing method based on the user's request, then follow the method-specific reference for implementation details.

When to Use

  • User asks to price options, bonds, swaps, or derivatives in MATLAB

  • User asks for Greeks/sensitivities (delta, vega, gamma, theta, rho, lambda)

  • User mentions finpricer, fininstrument, finmodel, or ratecurve

  • User asks about Monte Carlo, tree / lattice, or FFT (Fast Fourier Transform) / FRFT (Fractional FFT) pricing

  • User wants to compare pricing methods for the same instrument

When NOT to Use

  • User is working with a non-MATLAB environment

  • User wants to build a custom instrument with a novel payoff function

  • User explicitly asks for a from-scratch implementation without the Financial Instruments Toolbox

Method Routing

Identify the pricing method from the user's request and read the corresponding reference:

MethodReferenceWhen to Use
Monte Carlo (MC)references/monte-carlo.mdSimulation-based pricing: path-dependent options, exotic options, Interest Rate (IR) derivatives via MC, rough volatility
FFT / FRFT / Numerical Integrationreferences/ni-fft.mdFast pricing: European vanilla options under Heston/Bates/Merton via characteristic functions
Interest Rate Treesreferences/embedded-bond-tree.mdCallable/puttable fixed-rate bonds with Hull-White (HW), Black-Karasinski (BK), Black-Derman-Toy (BDT), Cox-Ingersoll-Ross (CIR) tree models
Routing Rules

Read exactly one reference (and any relevant sub-references) that best matches based on these rules:

  1. User mentions a specific pricer:

    • AssetMonteCarlo, RoughVolMonteCarlo, IRMonteCarlo -> references/monte-carlo.md

    • FFT, NumericalIntegration -> references/ni-fft.md

    • IRTree -> references/embedded-bond-tree.md

  2. User mentions a specific numerical method and associated concepts:

    • Monte Carlo, simulation, NumTrials, SimulationDates -> references/monte-carlo.md

    • FFT, FRFT, characteristic function, CharacteristicFcnStep, LogStrikeStep -> references/ni-fft.md

    • Interest-rate tree, TreeDates, exercise probability -> references/embedded-bond-tree.md

  3. User mentions instrument type without a method:

    • Path-dependent options or other exotic options (Asian, Barrier, Lookback, Cliquet, Touch, Spread, Binary) -> references/monte-carlo.md

    • European vanilla options under stochastic vol/jump models -> references/ni-fft.md

    • Callable/puttable fixed-rate bonds -> references/embedded-bond-tree.md

    • IR derivatives (caps, floors, swaptions, swaps) -> references/monte-carlo.md

  4. User mentions model name without a method:

    • Heston, Bates, Merton + European vanilla -> references/ni-fft.md

    • Heston, Bates, Merton + exotic/path-dependent -> references/monte-carlo.md

    • Hull-White, Black-Karasinski, BDT, CIR + callable/puttable bond -> references/embedded-bond-tree.md

    • Hull-White, BK, Linear Gaussian 2 Factor (G2PP), Brace-Gatarek-Musiela (BGM), SABR-BGM + caps/floors/swaptions -> references/monte-carlo.md

    • Rough volatility (RoughBergomi, RoughHeston) -> references/monte-carlo.md

  5. Ambiguous:

    • When asked to price European vanilla options without specifying pricing method (e.g., "price European call options with Heston in MATLAB"), default to references/ni-fft.md (faster, more accurate for European vanilla)

    • If user needs path simulation in addition to price and sensitivities, use references/monte-carlo.md

    • If user requests exercise probabilities at each time step for option embedded bonds, use references/embedded-bond-tree.md

Shared Conventions

All three methods share these conventions:

  • Always prefer to use finpricer/fininstrument/finmodel/ratecurve objects (modern OO API) over legacy functions

  • Never use legacy functions unless the user explicitly names them, or the reference suggests them for specific use cases

  • Use name-value pairs with string keys: "DiscountCurve", not positional arguments

  • Parameter names are case-insensitive but write them in MixedCase for clarity

  • Always use datetime for dates (not datenum)

  • Do not use price as a variable name — it shadows the price function; prefer p, or capitalized Price

  • Request two outputs from price() when Greeks or tree data are needed: [p, pr] = price(...)

Common Mistakes (Cross-Method)

Best practice: Check MATLAB documentation (doc <functionName>, or help <functionName>, etc.) via the MATLAB MCP server before writing code.

MistakeCorrect
finpricer("MonteCarlo", ...)finpricer("AssetMonteCarlo", ...) or finpricer("IRMonteCarlo", ...)
finpricer("HWMonteCarlo", ...)finpricer("IRMonteCarlo", ...) with a HullWhite model
Mixing pricer families (e.g., FFT pricer for Asian option)FFT/NI only works for European vanilla; use AssetMonteCarlo for exotics
Using datenumAlways use datetime
Forgetting second output for Greeks[p, pr] = price(pricer, inst, "delta") — Greeks are in pr.Results
discount(rc, dates)discountfactors(rc, dates) — ratecurve uses discountfactors(), not discount()

Copyright 2026 The MathWorks, Inc.


Files

references/monte-carlo/ir-monte-carlo.md

IR Monte Carlo Pricing

Price interest rate derivatives using Monte Carlo simulation with finpricer("IRMonteCarlo", ...).

Model-to-Pricer Mapping

The model you pass to the pricer determines the underlying SDE engine. Always use finpricer("IRMonteCarlo", ...) and the engine is selected automatically based on the model class.

finmodelParametersInternal Pricer
finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01)Alpha, Sigma: positive scalar or timetableHWMonteCarlo
finmodel("BlackKarasinski", "Alpha", 0.1, "Sigma", 0.01)Alpha, Sigma: positive scalar or timetableBKMonteCarlo
finmodel("LinearGaussian2F", "Alpha1", 0.07, "Sigma1", 0.01, "Alpha2", 0.5, "Sigma2", 0.006, "Correlation", -0.7)5 required parametersG2PPMonteCarlo
finmodel("BraceGatarekMusiela", "Volatility", VolFunc, "Correlation", CorrMat)VolFunc: cell array of function handles; Correlation: matrixBGMMonteCarlo
finmodel("SABRBraceGatarekMusiela", "Alpha", a, "Beta", b, "VolatilityofVolatility", vvFunc, "FwdFwdCorrelation", c1, "VolVolCorrelation", c2)Complex multi-parameter setupSABRBGMMonteCarlo

Never use finpricer("HWMonteCarlo", ...) or finpricer("BGMMonteCarlo", ...) directly. Always use finpricer("IRMonteCarlo", ...) and let the model determine the engine.

Supported Instruments

InstrumentKey ParametersNotes
FixedBondMaturity, CouponRate, Period, PrincipalCouponRate can be scalar or timetable (stepped coupon). Principal can be timetable (amortizing).
FloatBondMaturity, Spread, Reset, PrincipalLatestFloatingRate for seasoned bonds. Spread of 0 gives par (price ~100).
FixedBondOptionExerciseDate, Strike, Bond, ExerciseStyle, OptionTypeBond must reference a FixedBond instrument. Supports European, American, Bermudan.
FloatBondOptionExerciseDate, Strike, Bond, ExerciseStyle, OptionTypeBond must reference a FloatBond instrument. Supports European, American, Bermudan.
OptionEmbeddedFixedBondMaturity, CouponRate, CallSchedule or PutScheduleSchedule is a timetable with dates and strike prices. CallExerciseStyle/PutExerciseStyle for American/Bermudan.
OptionEmbeddedFloatBondMaturity, Spread, CallSchedule or PutScheduleSame schedule pattern as OptionEmbeddedFixedBond.
CapMaturity, Strike, Reset, PrincipalCaps on floating rate. Reset determines payment frequency.
FloorMaturity, Strike, Reset, PrincipalFloors on floating rate. Same structure as Cap.
SwapMaturity, LegRate, LegType, Reset, NotionalLegType: ["fixed","float"] or ["float","fixed"]. Notional can be timetable (amortizing); dates must align with coupon dates. StartDate for forward-starting swaps.
SwaptionExerciseDate, Strike, Swap, OptionTypeSwap must reference a Swap instrument. European exercise only.
RangeAccrualNoteMaturity, ReferenceType, ReferenceTenor, CouponRate, TargetRangeReferenceType: "cms" or "spot". ReferenceTenor can be scalar (single rate) or a 2-element vector [short long] for CMS spread (e.g., [2 10]). Requires daily SimulationDates. HullWhite and LinearGaussian2F only. R2026a+; see SimulationDates Rules for fallback.
OptionEmbeddedRangeAccrualNoteSame as RangeAccrualNote + call/put scheduleHullWhite and LinearGaussian2F only. R2026a+; see SimulationDates Rules for fallback.
Model-Instrument Compatibility
ModelInstrumentsSensitivitiesNotes
HullWhiteAll 12 instrumentsprice, delta, gamma, vegaMost complete support
BlackKarasinskiAll except RangeAccrualNote variantsprice, delta, gamma, vega
LinearGaussian2FAll 12 instrumentsprice, delta, gamma, vegaVega returns a 2-element vector (one per sigma factor)
BraceGatarekMusielaFixedBond, FloatBond, FixedBondOption, FloatBondOption, OptionEmbeddedFixedBond, OptionEmbeddedFloatBond, Cap, Floorprice, delta, gammaNo vega. No Swap/Swaption.
SABRBraceGatarekMusielaSame as BGMprice, delta, gammaNo vega. No Swap/Swaption.

Pricer Parameters

Required
pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...        % ratecurve object
    "Model", mdl, ...               % finmodel object (determines engine)
    "SimulationDates", simDates);   % datetime vector — MUST include exercise dates
Optional
ParameterTypeDefaultNotes
NumTrialspositive integer1000Use 1e4+ for production
RandomNumbersstruct or numeric array[]Struct with field Z. Or pass the raw array directly.

Note: Unlike AssetMonteCarlo, IRMonteCarlo does not have SpotPrice, DividendType, DividendValue, MonteCarloMethod, or BrownianMotionMethod parameters.

SimulationDates Rules

  • Must be after ratecurve.Settle. Dates on or before settle cause error 'fininst:finpricer:SimulationDateBeforeSettle'.

  • Must include exercise dates for bond options, swaptions, and option-embedded bonds. Missing dates cause error 'fininst:finpricer:ExerciseDateNotSim'.

  • American exercise needs sufficient intermediate dates to capture early exercise opportunities.

  • RangeAccrualNote requires daily simulation dates (business days) for accurate accrual counting. Always try fininstrument("RangeAccrualNote", ...) first — it is the preferred API when available (R2026a and later). If MATLAB errors with an invalid instrument type, fall back to a manual implementation: use finmodel("HullWhite", ...) with simTermStructs to simulate daily short-rate paths, compute the reference rate (e.g., CMS 10Y par swap rate) at each date, count days within the target range, and discount the accrual-weighted coupons using the simulated discount factors.

  • BGM/SABR-BGM models: SimulationDates cannot extend beyond the model's tenor dates (determined by length(Volatility)+1 forward rates and Period). Error: 'fininst:finpricer:InvalidBGMSimulationDates'.

  • Dates are automatically sorted and deduplicated.

% Short-rate models (HW, BK, G2PP): typical setup
simDates = Settle + calmonths(1:48)';

% American bond option: denser dates around exercise window
simDates = [Settle+calmonths(1:6:48)'; ZeroDates];

% Range accrual note: daily business dates
simDates = busdate(Settle:caldays(1):Maturity, 'follow', holidays);

% BGM: limited by tenor
simDates = Settle:calmonths(1):Maturity;  % must not exceed last tenor date

Random Number Reuse

Same pattern as AssetMonteCarlo:

% First run: capture random numbers
[p1, pr1] = price(pricer, inst, "all");
savedRN = pr1.PricerData.RandomNumbers;

% Second run: feed them back
pricer.RandomNumbers = savedRN;
[p2, pr2] = price(pricer, inst2, "all");

The Z array dimensions depend on the model:

  • HullWhite, BlackKarasinski: NumSimDates x 1 x NumTrials

  • LinearGaussian2F: NumSimDates x 2 x NumTrials

  • BraceGatarekMusiela: NumPeriods x NumBrownians x NumTrials (NumBrownians = NumRates-1 or NumFactors)

Instrument Composition Patterns

Bond Options (FixedBondOption, FloatBondOption)

Bond options require a reference to an existing bond instrument:

bond = fininstrument("FixedBond", "Maturity", datetime(2025,1,1), "CouponRate", 0.05);

% European bond option
bondOpt = fininstrument("FixedBondOption", ...
    "ExerciseDate", datetime(2024,1,1), ...
    "Strike", 95, ...
    "Bond", bond);

% American bond option (specify date range)
bondOptAm = fininstrument("FixedBondOption", ...
    "ExerciseDate", [datetime(2022,1,1) datetime(2024,1,1)], ...
    "Strike", 95, ...
    "Bond", bond, ...
    "ExerciseStyle", "american");

% Bermudan bond option (multiple dates and strikes)
bondOptBer = fininstrument("FixedBondOption", ...
    "ExerciseDate", [datetime(2022,1,1) datetime(2023,1,1) datetime(2024,1,1)], ...
    "Strike", [95 95 95], ...
    "Bond", bond, ...
    "ExerciseStyle", "bermudan");
Option-Embedded Bonds

Callable/putable bonds use schedule timetables:

% Callable bond (Bermudan)
CallDates = [datetime(2022,1,1); datetime(2023,1,1); datetime(2024,1,1)];
CallStrikes = [100; 100; 105];
CallSchedule = timetable(CallDates, CallStrikes);

callableBond = fininstrument("OptionEmbeddedFixedBond", ...
    "Maturity", datetime(2025,1,1), ...
    "CouponRate", 0.05, ...
    "CallSchedule", CallSchedule, ...
    "CallExerciseStyle", "bermudan");

% Putable bond
PutSchedule = timetable(datetime(2023,1,1), 100);
putableBond = fininstrument("OptionEmbeddedFixedBond", ...
    "Maturity", datetime(2025,1,1), ...
    "CouponRate", 0.05, ...
    "PutSchedule", PutSchedule);
Swaptions

Swaptions require a reference to an existing swap instrument:

swap = fininstrument("Swap", ...
    "Maturity", datetime(2025,1,1), ...
    "LegRate", [0.05, 0], ...
    "LegType", ["fixed", "float"]);

swaption = fininstrument("Swaption", ...
    "ExerciseDate", datetime(2023,1,1), ...
    "Strike", 0.02, ...
    "Swap", swap);

Model Setup Examples

Hull-White (simplest)
% Constant parameters
mdl = finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01);

% Time-varying parameters (timetable)
AlphaTT = timetable(datetime(2019,1,1), 0.1);
SigmaTT = timetable([datetime(2019,1,1); datetime(2021,1,1)], [0.01; 0.015]);
mdl = finmodel("HullWhite", "Alpha", AlphaTT, "Sigma", SigmaTT);
LinearGaussian2F (G2++)
mdl = finmodel("LinearGaussian2F", ...
    "Alpha1", 0.07, ...
    "Sigma1", 0.01, ...
    "Alpha2", 0.5, ...
    "Sigma2", 0.006, ...
    "Correlation", -0.7);
BraceGatarekMusiela (BGM / LIBOR Market Model)
% Volatility: cell array of function handles (one per forward rate)
BGMVolFunc = @(a,t) (a(1)*t + a(2)).*exp(-a(3)*t) + a(4);
BGMVolParams = [.3 -.02 .7 .14];

numRates = 6;
VolFunc = cell(1, numRates-1);
for i = 1:numRates-1
    VolFunc{i} = @(t) BGMVolFunc(BGMVolParams, t);
end

% Correlation: exponential decay
Beta = 0.08;
CorrFunc = @(i,j,B) exp(-B*abs(i-j));
Correlation = CorrFunc(meshgrid(1:numRates-1)', meshgrid(1:numRates-1), Beta);

mdl = finmodel("BraceGatarekMusiela", ...
    "Volatility", VolFunc, ...
    "Correlation", Correlation, ...
    "Period", 2);  % semiannual forward rates (default)
SABRBraceGatarekMusiela
numRates = 5;
Alpha = 0.12 * ones(numRates-1, 1);
Beta = ones(numRates-1, 1);

SABRVolVolFunc = @(a,t) (a(1)*t + a(2)).*exp(-a(3)*t) + a(4);
SABRVolVolParams = [.3 -.02 .7 .14];
VolVolFunc = cell(numRates-1, 1);
for i = 1:numRates-1
    VolVolFunc{i} = @(t) SABRVolVolFunc(SABRVolVolParams, t);
end

CorrFunc = @(i,j,B) exp(-B*abs(i-j));
FwdFwdCorrelation = CorrFunc(meshgrid(1:numRates-1)', meshgrid(1:numRates-1), 0.08);
VolVolCorrelation = CorrFunc(meshgrid(1:numRates-1)', meshgrid(1:numRates-1), 0.04);

mdl = finmodel("SABRBraceGatarekMusiela", ...
    "Alpha", Alpha, ...
    "Beta", Beta, ...
    "VolatilityofVolatility", VolVolFunc, ...
    "FwdFwdCorrelation", FwdFwdCorrelation, ...
    "VolVolCorrelation", VolVolCorrelation);

Complete Examples

Cap with Hull-White and Greeks
Settle = datetime(2019,1,1);
ZeroTimes = calyears(1:4)';
ZeroDates = Settle + ZeroTimes;
ZeroRates = [0.035; 0.042; 0.047; 0.053];

rc = ratecurve('zero', Settle, ZeroDates, ZeroRates, "Compounding", 4);
mdl = finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01);

cap = fininstrument("Cap", "Maturity", datetime(2022,9,15), "Strike", 0.01, "Reset", 2);

pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...
    "Model", mdl, ...
    "SimulationDates", [Settle+calmonths(3:6:48)'; ZeroDates]);

rng('default')
[p, pr] = price(pricer, cap, "all");
fprintf("Cap Price: %.4f, Delta: %.4f, Vega: %.4f\n", p, pr.Results.Delta, pr.Results.Vega);
Callable Bond (Bermudan) with Hull-White
Settle = datetime(2019,1,1);
ZeroDates = Settle + calyears(1:4)';
ZeroRates = [0.035; 0.042; 0.047; 0.053];
rc = ratecurve('zero', Settle, ZeroDates, ZeroRates, "Compounding", 4);
mdl = finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01);

CallSchedule = timetable( ...
    [datetime(2020,1,1); datetime(2021,1,1); datetime(2022,1,1)], ...
    [100; 100; 100]);

callableBond = fininstrument("OptionEmbeddedFixedBond", ...
    "Maturity", datetime(2022,9,15), ...
    "CouponRate", 0.05, ...
    "CallSchedule", CallSchedule, ...
    "CallExerciseStyle", "bermudan");

simDates = [Settle+calmonths(3:6:48)'; ZeroDates];
pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...
    "Model", mdl, ...
    "SimulationDates", simDates);

rng('default')
[p, pr] = price(pricer, callableBond, "all");
Swaption with G2++ and Two-Factor Vega
Settle = datetime(2019,1,1);
ZeroDates = Settle + calyears(1:10)';
ZeroRates = 0.025 * ones(10,1);
rc = ratecurve('zero', Settle, ZeroDates, ZeroRates, "Compounding", -1);

mdl = finmodel("LinearGaussian2F", ...
    "Alpha1", 0.07, "Sigma1", 0.01, ...
    "Alpha2", 0.5, "Sigma2", 0.006, ...
    "Correlation", -0.7);

swap = fininstrument("Swap", ...
    "Maturity", datetime(2029,1,1), ...
    "LegRate", [0.05, 0], ...
    "Reset", [1, 1], ...
    "Notional", 100);

swaption = fininstrument("Swaption", ...
    "ExerciseDate", datetime(2023,1,1), ...
    "Strike", 0.02, ...
    "Swap", swap);

pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...
    "Model", mdl, ...
    "SimulationDates", ZeroDates);

rng('default')
[p, pr] = price(pricer, swaption, "all");
% pr.Results.Vega is a 1x2 vector: [vega_sigma1, vega_sigma2]
BGM Cap Pricing
Settle = datetime(2019,1,1);
ZeroTimes = [calmonths(6) calyears([1 2 3 4 5])];
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119];
ZeroDates = Settle + ZeroTimes;
rc = ratecurve('zero', Settle, ZeroDates, ZeroRates, "Compounding", -1);

BGMVolFunc = @(a,t) (a(1)*t + a(2)).*exp(-a(3)*t) + a(4);
BGMVolParams = [.3 .02 .7 .14];
numRates = 4;
VolFunc(1:numRates-1) = {@(t) BGMVolFunc(BGMVolParams, numRates*0.5-t)};

Beta = 0.08;
CorrFunc = @(i,j,B) exp(-B*abs(i-j));
Correlation = CorrFunc(meshgrid(1:numRates-1)', meshgrid(1:numRates-1), Beta);

mdl = finmodel("BraceGatarekMusiela", ...
    "Volatility", VolFunc, ...
    "Correlation", Correlation);

cap = fininstrument("Cap", "Maturity", datetime(2021,1,1), "Strike", 0.005, "Reset", 2);

pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...
    "Model", mdl, ...
    "SimulationDates", Settle:calmonths(1):datetime(2021,1,1));

rng('default')
[p, pr] = price(pricer, cap, "all");
Mixed Instruments in One Call
Settle = datetime(2019,1,1);
ZeroDates = Settle + calyears(1:4)';
ZeroRates = [0.035; 0.042; 0.047; 0.053];
rc = ratecurve('zero', Settle, ZeroDates, ZeroRates, "Compounding", 4);
mdl = finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01);

fixBond = fininstrument("FixedBond", "Maturity", datetime(2022,9,15), "CouponRate", 0.05);
fltBond = fininstrument("FloatBond", "Maturity", datetime(2022,9,15), "Spread", 0.05);
cap = fininstrument("Cap", "Maturity", datetime(2022,9,15), "Strike", 0.01, "Reset", 2);
swap = fininstrument("Swap", "Maturity", datetime(2022,9,15), "LegRate", [0.05, 0.05], ...
    "LegType", ["float", "fixed"], "Reset", [2, 4]);

simDates = [Settle+calmonths(3:6:48)'; ZeroDates];
pricer = finpricer("IRMonteCarlo", ...
    "DiscountCurve", rc, ...
    "Model", mdl, ...
    "SimulationDates", simDates);

rng('default')
[prices, pr] = price(pricer, [fixBond; fltBond; cap; swap], "all");

Common Mistakes

MistakeWhy It FailsCorrect
finpricer("HWMonteCarlo", ...)Not a valid pricer namefinpricer("IRMonteCarlo", ...) with a HullWhite model
finpricer("IRMonteCarlo", ..., "SpotPrice", 100)IRMonteCarlo has no SpotPrice parameterRemove SpotPrice; that belongs to AssetMonteCarlo
finmodel("HullWhite", "MeanReversion", 0.1, "Volatility", 0.01)Wrong parameter namesfinmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01)
finmodel("LinearGaussian2F", "Alpha", ..., "Sigma", ...)Wrong parameter names for G2PPUse Alpha1, Sigma1, Alpha2, Sigma2, Correlation
Bond option without "Bond" parameterMissing required instrument referencefininstrument("FixedBondOption", ..., "Bond", bondInst)
Swaption without "Swap" parameterMissing required instrument referencefininstrument("Swaption", ..., "Swap", swapInst)
price(pricer, swaption, "vega") with BGM modelBGM doesn't support vegaOnly "delta" and "gamma" are available for BGM/SABR-BGM
Pricing Swap/Swaption with BGM modelBGM only supports bonds, bond options, caps, floorsUse HullWhite, BK, or G2PP for Swap/Swaption
bondbyhw, capbyhw, swaptionbyhwLegacy functionsUse finpricer("IRMonteCarlo", ...) + price(pricer, inst)
BGM SimulationDates beyond tenor datesError: 'fininst:finpricer:InvalidBGMSimulationDates'SimulationDates must not exceed last tenor date of the model
RangeAccrualNote with BK or BGM modelNot supportedUse HullWhite or LinearGaussian2F only
fininstrument("RangeAccrualNote", ...) on pre-R2026aNot a valid instrument typeRangeAccrualNote requires R2026a or later — implement manually with simTermStructs (see SimulationDates Rules)
Expecting scalar Vega from G2PPG2PP returns [vega_sigma1, vega_sigma2]Handle 2-element Vega vector for LinearGaussian2F
BGM Volatility as scalar or vectorMust be cell array of function handlesVolFunc = {@(t) 0.2, @(t) 0.15, ...}
finmodel("BraceGatarekMusiela", "Volatility", 0.2, ...)Volatility must be cell of function handlesfinmodel("BraceGatarekMusiela", "Volatility", {@(t) 0.2}, ...)
Amortizing Notional timetable with arbitrary datesError: "Sinking Face Schedule Dates must be cash flow dates"Notional timetable dates must align with coupon payment dates

Copyright 2026 The MathWorks, Inc.


Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs an MCP server

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
MathWorks
Publisher
MathWorks (Official)
Source
matlab/matlab-agentic-toolkit · skills-catalog/computational-finance/matlab-price-instrument · commit 2a7f215
Licence
BSD 2-Clause License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by MathWorks.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-price-instrument.zip