hcomputeMTMValues, Expression or statement is incomplete or incorrect.

조회 수: 5 (최근 30일)
FLAVIA VITRANO
FLAVIA VITRANO 2018년 1월 5일
편집: Walter Roberson 2018년 12월 17일
I try to use the function "hcomputeMTMValues" on my matlab code but it doesn't work!I'm getting the following error when I try to run the function: "Expression or statement is incomplete or incorrect." Please, help me.
  댓글 수: 3
FLAVIA VITRANO
FLAVIA VITRANO 2018년 1월 10일
편집: Walter Roberson 2018년 12월 17일
% Read swaps from spreadsheet
FileSwap = ('DATASET.xls'); SwapPort = readtable(FileSwap, 'Sheet', 'Swap_Portfolio');
swaps.LegType = [SwapPort.LegType ~SwapPort.LegType]; swaps.LegRate = [SwapPort.LegRateReceiving SwapPort.LegRatePaying]; swaps.LegReset = ones(size(SwapPort,1),1);
numSwaps = size(SwapPort,1);
% Create ZeroCurve from the Interest Rate Curve
Settle = datenum('22-Dec-2017');
Tenor = [3 6 9 12 2*12 3*12 4*12 5*12 6*12 7*12 8*12 9*12 10*12 11*12 ... 12*12 13*12 14*12 15*12 16*12 17*12 18*12 19*12 20*12 21*12 22*12 ... 23*12 24*12 25*12 26*12 27*12 28*12 29*12 30*12]';
ZeroRates= [-0.00826033 -0.00813788 -0.00797468 -0.00777337 -0.00664987 ... -0.005174 -0.00353124 -0.00185911 -0.00024712 0.00125365 0.00261937 ... 0.00384398 0.00493208 0.005894 0.00674254 0.00749109 0.00815247 ... 0.00873837 0.00925918 0.00972392 0.01014033 0.010515 0.01085353 ... 0.01116065 0.01144038 0.01169612 0.01193075 0.01214674 0.01234619 ... 0.01253093 0.01270249 0.01286225 0.01301137]';
ZeroDates = datemnth(Settle,Tenor);
Compounding = 2;
Basis = 0;
ZeroCurve = intenvset('StartDates', Settle,'EndDates', ZeroDates, ... 'Rates', ZeroRates,'Compounding',Compounding,'Basis',Basis);
figure(1);
plot(ZeroDates, ZeroRates, '*-');
xlabel('Date');
datetick('keeplimits');
ylabel('Spot rate');
grid on;
title('Euro Area Spot Yield Curve al 22 Dicembre 2017');
%Calibrate Vasicek Model
alpha=0.01;
gamma=0.2;
sigma=0.03;
Tau=Tenor;
r0=ZeroRates(1);
Spot_Rate=ZeroRates';
R_vasicek=ZeroRatesVas(alpha,gamma,sigma,r0,Tau)';
X0=[alpha gamma sigma];
FUN=@(x) sum((ZeroRatesVas(x(1),x(2),x(3),r0,Tau)-Spot_Rate).^2);
xfinale=fminsearch(FUN,X0);
R_vasicek1=ZeroRatesVas(xfinale(1),xfinale(2),xfinale(3),r0,Tau)';
figure(2);
plot(Tau,R_vasicek1,'k',Tau,Spot_Rate,'r');
xlabel('Time to maturity');
ylabel('Rate');
legend('Vasicek Rate','Spot Rate','Location','southeast');
title('Vaiscek Model vs Zero Rate Curve')
% Setup Hull-White Single Factor Model
Alpha=xfinale(1);
Sigma=xfinale(3);
hw1 = HullWhite1F(ZeroCurve,Alpha,Sigma);
% Set Changeable Simulation Parameters
% Number of Monte Carlo simulations
numScenarios = 1000;
% Compute half-yearly simulation dates.
SimulationDates = datemnth(Settle,0:6:366,0,0,1)';
numDates = numel(SimulationDates);
%Compute Floating Reset Dates for each simulation date
ResetDates = cfdates(Settle-180,SwapPort.Maturity,SwapPort.Period);
SwapPort.FloatingResetDates = zeros(numSwaps,numDates);
for i = numDates:-1:1
thisDate = SimulationDates(i);
ResetDates(ResetDates > thisDate) = 0;
SwapPort.FloatingResetDates(:,i) = max(ResetDates,[],2);
end
% simulate the future interest rate curve at each valuation date using the Hull-White one-factor interest rate model.
prevRNG = rng(0, 'twister'); dt = diff(yearfrac(Settle,SimulationDates,2)); nPeriods = numel(dt); scenarios = hw1.simTermStructs(nPeriods, ... 'nTrials',numScenarios, ... 'deltaTime',dt);
% Restore random number generator state
rng(prevRNG);
%Inspect a Scenario (n.100)
j = 100; figure(3); surf(Tenor, SimulationDates, scenarios(:,:,j)) axis tight datetick('y','mmmyy'); xlabel('Tenor (Years)'); ylabel('Scenarios'); zlabel('Rates'); ax = gca; ax.View = [-49 32]; title(sprintf('Scenario %d Yield Curve Evolution\n',j));
% Compute Mark to Market Swap Prices
values = hcomputeMTMValues(SwapPort,SimulationDates,scenarios,Tenor);
Peter Meglis
Peter Meglis 2018년 8월 6일
편집: Walter Roberson 2018년 12월 17일
Flavia,
I tried reproducing the issue but was unable to do it due to some functions not being recognized. Is there more code to this?
You can use
which -all hcomputeMTMValues
to find where the function is located.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sharon He
Sharon He 2018년 12월 17일
Hi Flavia,
As Peter has mentioned, type the following code in the Matlab command line:
which -all hcomputeMTMValues
For me, I got
E:\bat\archive\R2018a\perfect\matlab\toolbox\fininst\fininstdemos\hcomputeMTMValues.m
Then add it to the path by typing:
addpath('E:\bat\archive\R2018a\perfect\matlab\toolbox\fininst\fininstdemos\hcomputeMTMValues.m')
Thanks,
Sharon

카테고리

Help CenterFile Exchange에서 MATLAB Functions in Microsoft Excel에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by