Matlab Price Instrument
MathWorksOfficialCreated by MathWorks
- Skill
- Tool integration
- Science and research
- BSD-2-Clause
- No issues found
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
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/matlab/matlab-price-instrument/downloadUnzip 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:
| Method | Reference | When to Use |
|---|---|---|
| Monte Carlo (MC) | references/monte-carlo.md | Simulation-based pricing: path-dependent options, exotic options, Interest Rate (IR) derivatives via MC, rough volatility |
| FFT / FRFT / Numerical Integration | references/ni-fft.md | Fast pricing: European vanilla options under Heston/Bates/Merton via characteristic functions |
| Interest Rate Trees | references/embedded-bond-tree.md | Callable/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:
User mentions a specific pricer:
AssetMonteCarlo,RoughVolMonteCarlo,IRMonteCarlo->references/monte-carlo.mdFFT,NumericalIntegration->references/ni-fft.mdIRTree->references/embedded-bond-tree.md
User mentions a specific numerical method and associated concepts:
Monte Carlo, simulation, NumTrials, SimulationDates ->
references/monte-carlo.mdFFT, FRFT, characteristic function, CharacteristicFcnStep, LogStrikeStep ->
references/ni-fft.mdInterest-rate tree, TreeDates, exercise probability ->
references/embedded-bond-tree.md
User mentions instrument type without a method:
Path-dependent options or other exotic options (Asian, Barrier, Lookback, Cliquet, Touch, Spread, Binary) ->
references/monte-carlo.mdEuropean vanilla options under stochastic vol/jump models ->
references/ni-fft.mdCallable/puttable fixed-rate bonds ->
references/embedded-bond-tree.mdIR derivatives (caps, floors, swaptions, swaps) ->
references/monte-carlo.md
User mentions model name without a method:
Heston, Bates, Merton + European vanilla ->
references/ni-fft.mdHeston, Bates, Merton + exotic/path-dependent ->
references/monte-carlo.mdHull-White, Black-Karasinski, BDT, CIR + callable/puttable bond ->
references/embedded-bond-tree.mdHull-White, BK, Linear Gaussian 2 Factor (G2PP), Brace-Gatarek-Musiela (BGM), SABR-BGM + caps/floors/swaptions ->
references/monte-carlo.mdRough volatility (RoughBergomi, RoughHeston) ->
references/monte-carlo.md
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.mdIf 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/ratecurveobjects (modern OO API) over legacy functionsNever 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 argumentsParameter names are case-insensitive but write them in MixedCase for clarity
Always use
datetimefor dates (notdatenum)Do not use
priceas a variable name — it shadows thepricefunction; preferp, or capitalizedPriceRequest 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.
| Mistake | Correct |
|---|---|
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 datenum | Always 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
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md6.3 KiB
- manifest.yaml462 B
- references/embedded-bond-tree.md10.2 KiB
- references/monte-carlo.md5.2 KiB
- references/monte-carlo/asset-monte-carlo.md13.0 KiB
- references/monte-carlo/ir-monte-carlo.md17.9 KiB
- references/ni-fft.md20.5 KiB
- references/ni-fft/bates-legacy-api.md2.1 KiB
- references/ni-fft/heston-legacy-api.md1.9 KiB
- references/ni-fft/legacy-api-shared.md4.3 KiB
- references/ni-fft/merton-legacy-api.md2.3 KiB
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.
| finmodel | Parameters | Internal Pricer |
|---|---|---|
finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01) | Alpha, Sigma: positive scalar or timetable | HWMonteCarlo |
finmodel("BlackKarasinski", "Alpha", 0.1, "Sigma", 0.01) | Alpha, Sigma: positive scalar or timetable | BKMonteCarlo |
finmodel("LinearGaussian2F", "Alpha1", 0.07, "Sigma1", 0.01, "Alpha2", 0.5, "Sigma2", 0.006, "Correlation", -0.7) | 5 required parameters | G2PPMonteCarlo |
finmodel("BraceGatarekMusiela", "Volatility", VolFunc, "Correlation", CorrMat) | VolFunc: cell array of function handles; Correlation: matrix | BGMMonteCarlo |
finmodel("SABRBraceGatarekMusiela", "Alpha", a, "Beta", b, "VolatilityofVolatility", vvFunc, "FwdFwdCorrelation", c1, "VolVolCorrelation", c2) | Complex multi-parameter setup | SABRBGMMonteCarlo |
Never use finpricer("HWMonteCarlo", ...) or finpricer("BGMMonteCarlo", ...) directly. Always use finpricer("IRMonteCarlo", ...) and let the model determine the engine.
Supported Instruments
| Instrument | Key Parameters | Notes |
|---|---|---|
| FixedBond | Maturity, CouponRate, Period, Principal | CouponRate can be scalar or timetable (stepped coupon). Principal can be timetable (amortizing). |
| FloatBond | Maturity, Spread, Reset, Principal | LatestFloatingRate for seasoned bonds. Spread of 0 gives par (price ~100). |
| FixedBondOption | ExerciseDate, Strike, Bond, ExerciseStyle, OptionType | Bond must reference a FixedBond instrument. Supports European, American, Bermudan. |
| FloatBondOption | ExerciseDate, Strike, Bond, ExerciseStyle, OptionType | Bond must reference a FloatBond instrument. Supports European, American, Bermudan. |
| OptionEmbeddedFixedBond | Maturity, CouponRate, CallSchedule or PutSchedule | Schedule is a timetable with dates and strike prices. CallExerciseStyle/PutExerciseStyle for American/Bermudan. |
| OptionEmbeddedFloatBond | Maturity, Spread, CallSchedule or PutSchedule | Same schedule pattern as OptionEmbeddedFixedBond. |
| Cap | Maturity, Strike, Reset, Principal | Caps on floating rate. Reset determines payment frequency. |
| Floor | Maturity, Strike, Reset, Principal | Floors on floating rate. Same structure as Cap. |
| Swap | Maturity, LegRate, LegType, Reset, Notional | LegType: ["fixed","float"] or ["float","fixed"]. Notional can be timetable (amortizing); dates must align with coupon dates. StartDate for forward-starting swaps. |
| Swaption | ExerciseDate, Strike, Swap, OptionType | Swap must reference a Swap instrument. European exercise only. |
| RangeAccrualNote | Maturity, ReferenceType, ReferenceTenor, CouponRate, TargetRange | ReferenceType: "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. |
| OptionEmbeddedRangeAccrualNote | Same as RangeAccrualNote + call/put schedule | HullWhite and LinearGaussian2F only. R2026a+; see SimulationDates Rules for fallback. |
Model-Instrument Compatibility
| Model | Instruments | Sensitivities | Notes |
|---|---|---|---|
| HullWhite | All 12 instruments | price, delta, gamma, vega | Most complete support |
| BlackKarasinski | All except RangeAccrualNote variants | price, delta, gamma, vega | |
| LinearGaussian2F | All 12 instruments | price, delta, gamma, vega | Vega returns a 2-element vector (one per sigma factor) |
| BraceGatarekMusiela | FixedBond, FloatBond, FixedBondOption, FloatBondOption, OptionEmbeddedFixedBond, OptionEmbeddedFloatBond, Cap, Floor | price, delta, gamma | No vega. No Swap/Swaption. |
| SABRBraceGatarekMusiela | Same as BGM | price, delta, gamma | No 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 datesOptional
| Parameter | Type | Default | Notes |
|---|---|---|---|
NumTrials | positive integer | 1000 | Use 1e4+ for production |
RandomNumbers | struct 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: usefinmodel("HullWhite", ...)withsimTermStructsto 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)+1forward rates andPeriod). 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 dateRandom 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 NumTrialsLinearGaussian2F:
NumSimDates x 2 x NumTrialsBraceGatarekMusiela:
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
| Mistake | Why It Fails | Correct |
|---|---|---|
finpricer("HWMonteCarlo", ...) | Not a valid pricer name | finpricer("IRMonteCarlo", ...) with a HullWhite model |
finpricer("IRMonteCarlo", ..., "SpotPrice", 100) | IRMonteCarlo has no SpotPrice parameter | Remove SpotPrice; that belongs to AssetMonteCarlo |
finmodel("HullWhite", "MeanReversion", 0.1, "Volatility", 0.01) | Wrong parameter names | finmodel("HullWhite", "Alpha", 0.1, "Sigma", 0.01) |
finmodel("LinearGaussian2F", "Alpha", ..., "Sigma", ...) | Wrong parameter names for G2PP | Use Alpha1, Sigma1, Alpha2, Sigma2, Correlation |
Bond option without "Bond" parameter | Missing required instrument reference | fininstrument("FixedBondOption", ..., "Bond", bondInst) |
Swaption without "Swap" parameter | Missing required instrument reference | fininstrument("Swaption", ..., "Swap", swapInst) |
price(pricer, swaption, "vega") with BGM model | BGM doesn't support vega | Only "delta" and "gamma" are available for BGM/SABR-BGM |
| Pricing Swap/Swaption with BGM model | BGM only supports bonds, bond options, caps, floors | Use HullWhite, BK, or G2PP for Swap/Swaption |
bondbyhw, capbyhw, swaptionbyhw | Legacy functions | Use finpricer("IRMonteCarlo", ...) + price(pricer, inst) |
| BGM SimulationDates beyond tenor dates | Error: 'fininst:finpricer:InvalidBGMSimulationDates' | SimulationDates must not exceed last tenor date of the model |
| RangeAccrualNote with BK or BGM model | Not supported | Use HullWhite or LinearGaussian2F only |
fininstrument("RangeAccrualNote", ...) on pre-R2026a | Not a valid instrument type | RangeAccrualNote requires R2026a or later — implement manually with simTermStructs (see SimulationDates Rules) |
| Expecting scalar Vega from G2PP | G2PP returns [vega_sigma1, vega_sigma2] | Handle 2-element Vega vector for LinearGaussian2F |
| BGM Volatility as scalar or vector | Must be cell array of function handles | VolFunc = {@(t) 0.2, @(t) 0.15, ...} |
finmodel("BraceGatarekMusiela", "Volatility", 0.2, ...) | Volatility must be cell of function handles | finmodel("BraceGatarekMusiela", "Volatility", {@(t) 0.2}, ...) |
Amortizing Notional timetable with arbitrary dates | Error: "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