Hi Igor,
thanks a lot for the code, unfortunately, using Mathematica 11.1.1 that's not what I get:
In[1]:= zrates = {0.012, 0.015, 0.0167, 0.0176, 0.019, 0.0201, 0.0223,
0.0235};
times = {0.25, 0.5, 1, 1.5, 2, 3, 4, 5};
zrobj = TemporalData[zrates, {times}];
In[4]:= intrate = Interpolation[zrobj["Path"], Method -> "Spline"];
In[5]:= DF[x_] := Exp[-intrate[x]*x];
{dt, y, R} = {0.005, 5, 0.4};
In[8]:= cW[\[Rho]_] :=
Refine[ItoProcess[{{0, 0}, IdentityMatrix[2]}, {{n1, n2}, {0, 0}},
t, {{1, \[Rho]}, {\[Rho], 1}}], -1 < \[Rho] < 1];
In[9]:= combprc =
ItoProcess[{\[DifferentialD]s[
t] == \[Mu] s[t] \[DifferentialD]t + \[Sigma]1*
s[t] \[DifferentialD]n1[t], \[DifferentialD]c[
t] == \[Theta] (\[Beta] - c[t]) \[DifferentialD]t + \[Sigma]2*
Sqrt[Abs[c[t]]] \[DifferentialD]n2[t]}, {s[t],
c[t]}, {{s, c}, {s0, c0}}, t, {n1, n2} \[Distributed] cW[\[Rho]]];
In[10]:= simproc =
RandomFunction[
combprc /. {\[Mu] -> 0.022, \[Sigma]1 -> 0.2, \[Theta] ->
0.005, \[Beta] -> 0.015, \[Sigma]2 -> 0.05, \[Rho] -> 0.5,
s0 -> 0.025, c0 -> 0.0125}, {0, y, dt}, 1000,
Method -> "StochasticRungeKutta"];
In[11]:= Exposure[T_, S_, t_, v_] := (T - t)*Max[v - S, 0];
In[12]:= swapproc = simproc["PathComponent", 1];
In[13]:= expswap =
TimeSeriesMapThread[Exposure[5, 0.025, #1, #2] &, swapproc];
In[14]:= cdsproc = simproc["PathComponent", 2];
In[15]:= hazrate = TimeSeriesMap[#/(1 - R) &, cdsproc];
In[16]:= eeswap =
TimeSeriesThread[Mean, expswap, ResamplingMethod -> Interpolation];
eehaz = TimeSeriesThread[Mean, hazrate,
ResamplingMethod -> Interpolation];
In[18]:= epe[x_] :=
Mean[TimeSeriesWindow[eeswap, {0, Max[dt, x]},
ResamplingMethod -> Interpolation]];
In[19]:= exphazrate[x_] :=
Mean[TimeSeriesWindow[eehaz, {0, Max[dt, x]},
ResamplingMethod -> Interpolation]];
In[20]:= survfunc[x_] := Exp[-exphazrate[x]*x];
In[21]:= CVAS[n_, fr_, r_] :=
Module[{f, g, s},
f = TemporalData[Table[{i, survfunc[i]}, {i, 0, n, fr}]];
g = MovingMap[First[#] - Last[#] &, f, {2}];
s = (1 - r)*
Sum[DF[i]*epe[i]*g["PathFunction"][i], {i, fr, n, fr}];
s];
In[22]:= CVAS[5, 1/2, 0.4]*10^4
During evaluation of In[22]:= InterpolatingFunction::dmval: Input value {-(1/2)} lies outside the range of data in the interpolating function. Extrapolation will be used.
During evaluation of In[22]:= InterpolatingFunction::dmval: Input value {-1} lies outside the range of data in the interpolating function. Extrapolation will be used.
During evaluation of In[22]:= InterpolatingFunction::dmval: Input value {-(3/2)} lies outside the range of data in the interpolating function. Extrapolation will be used.
During evaluation of In[22]:= General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation.
Out[22]= 16.5418
Any ideas why is still not working?