How can I simulate daily instead of monthly in my Monte Carlo simulation for CVA?

2 views (last 30 days)
Using the mathworks guide for calculating CVA, however I want to simulated different frequencies, daily, weekly, monthly, quarterly, yearly.
% Compute monthly simulation dates
simulationDates = datemnth(Settle,0:1:60)';
numDates = numel(simulationDates);
I changed this to
% Compute monthly simulation dates, then quarterly dates later.
simulationDates = days360(Settle,Maturity)';
numDates = numel(simulationDates);
I have a portfolio of 5 years, with 360 days, making it 1800 simulationdates
However the thing I get stuck on is the following code for dt in the Hull-White model
dt = diff(yearfrac(Settle,simulationDates,1));
nPeriods = numel(dt);
scenarios = hw1.simTermStructs(nPeriods,...
'nTrials',numScenarios,...
'deltaTime',dt);
Because I don't get a proper array with for dt now, there are cell containing 0. Instead of every cell being (5/1800). Does anyone know a proper function instead of yearfrac for this?
The errors I'm getting
Error using HullWhite1F/simTermStructs (line 210)
NPERIODS must be a positive scalar integer.
Error in CVA_example (line 74)
scenarios = hw1.simTermStructs(nPeriods,...
Mathwork example: Mathworks CVA

Answers (0)

Categories

Find more on Model Predictive Control Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!