Finance - Maple Programming Help

Home : Support : Online Help : Mathematics : Finance : Stochastic Processes : Finance/ExpectedShortfall

Finance

 ExpectedShortfall
 calculate the expected shortfall

 Calling Sequence ExpectedShortfall(pathfunction, pathgenerator, opts) ExpectedShortfall(pathfunction, process, timegrid, opts) ExpectedShortfall(pathfunction, process, timeinterval, opts) ExpectedShortfall(expression, opts)

Parameters

 pathfunction - procedure; path function pathgenerator - path generator data structure; path generator process - one- or multi-dimensional stochastic process, or list or vector of one-dimensional stochastic processes timegrid - range or time grid data structure; time grid timeinterval - range; time interval expression - algebraic expression; expression whose shortfall is to be estimated opts - (optional) equation(s) of the form option = value where option is one of confidencelevel, replications, timesteps, or output; specify options for the ExpectedShortfall command

Options

 • confidencelevel = realcons -- This option specifies the confidence level for which the expected shortfall is computed. The value of this option must be a real constant between 0 and 1. By default, a .99 confidence level is used.
 • replications = posint -- This option specifies the number of replications of the sample path. By default, only one replication of the sample path is generated.
 • timesteps = posint -- This option specifies the number of time steps. This option is ignored if an explicit time grid is specified. By default, only one time step is used.
 • output = value, standarddeviation, skewness, kurtosis, minimum, maximum, standarderror, or a list containing several of these quantities -- This option specifies the quantities returned by the ExpectedShortfall command. The output = all option forces the ExpectedShortfall command to return all of the available statistics.

Description

 • The ExpectedShortfall(pathfunction, pathgenerator, opts) calling sequence computes a Monte Carlo estimate of the expected shortfall of a portfolio whose total value is governed by the specified stochastic process. It follows the same procedure as the SamplePath and ExpectedValue commands.
 – Generate a replication of the sample path using the specified path generator and store these values as a Maple Array, for example $A$. In the case of a one-dimensional process, $A$ is a one-dimensional array of size $n$, where $n$ is the number of points in the time grid (the number of time steps plus one). In the case of a multi-dimensional process, $A$ is a two-dimensional array of size $\left[m,n\right]$, where $m$ is the dimension of the underlying stochastic process and $n$ is the same as in the one-dimensional case.
 – Compute the value $\mathrm{pathfunction}\left(A\right)$.
 – Repeat these two steps the specified number of times (see the replications option) and compute the mean average.
 • The ExpectedShortfall command also computes such statistics as standard deviation, skewness, kurtosis, minimum, maximum and standard error (see the output option).
 • The ExpectedShortfall(pathfunction, process, timegrid, opts) and ExpectedShortfall(pathfunction, process, timeinterval, opts) calling sequences first construct the corresponding path generator and then perform the same computations as above.
 • The parameter pathfunction must be a Maple procedure that accepts a one-dimensional array of floating-point numbers (sample path for the underlying process) and returns the corresponding value as a floating-point number. A path function can be used, for example, to compute expected values for some path-dependent payoffs.
 • The timegrid parameter can be used to pass non-homogeneous time grids to the simulation routines. It must be given as a data structure generated by the TimeGrid command.
 • The timeinterval parameter must be of type range ${T}_{0}..{T}_{1}$, where ${T}_{0}$ and ${T}_{1}$ are non-negative constants such that ${T}_{0}<{T}_{1}$. When the $\mathrm{ExpectedValue}\left(\mathrm{pathfunction},\mathrm{process},\mathrm{timeinterval},\mathrm{opts}\right)$ calling sequence is used, the uniform time grid between ${T}_{0}$ and ${T}_{1}$ (with time steps $\mathrm{dt}=\frac{{T}_{1}-{T}_{0}}{\mathrm{timesteps}}$) is generated.
 Note that if $0<{T}_{0}$, the value at ${T}_{0}$ will be simulated using a single step of the default discretization method and hence can suffer from a significant discretization bias. Increasing the number of time steps will refine the grid between ${T}_{0}$ and ${T}_{1}$, but will have no effect on the value at ${T}_{0}$. To reduce the bias, use a time interval of the form $0..{T}_{1}$.
 • The ExpectedShortfall(expression, opts) calling sequence attempts to extract all the stochastic variables involved in expression and generate the corresponding path generator and path function using the specified number of time steps. In particular, ExpectedShortfall will extract all time instances involved in expression and adjust them so that they belong to the grid.
 All stochastic variables involved in expression should be of the form $X\left(t\right)$, where $t$ is some expression. If $X$ is multi-dimensional stochastic, then the individual components of $X$ can be accessed using the notation ${X\left(t\right)}_{i}$.

Examples

 > $\mathrm{with}\left(\mathrm{Finance}\right):$

Here is a simple one-dimensional stochastic process.

 > $X≔\mathrm{WienerProcess}\left(\right)$
 ${X}{≔}{\mathrm{_W}}$ (1)
 > $\mathrm{ExpectedShortfall}\left(X\left(3\right),\mathrm{timesteps}=10\right)$
 ${-0.262747381713126}$ (2)

Here are several replications of the sample path.

 > $\mathrm{ExpectedShortfall}\left(X\left(3\right),\mathrm{timesteps}=10,\mathrm{replications}={10}^{4}\right)$
 ${-4.56635306600560}$ (3)

Here is an example involving a multivariate stochastic process.

 > $\mathrm{\Sigma }≔⟨⟨1.0,0.5⟩|⟨0.5,1.0⟩⟩$
 ${\mathrm{\Sigma }}{≔}\left[\begin{array}{cc}{1.0}& {0.5}\\ {0.5}& {1.0}\end{array}\right]$ (4)
 > $W≔\mathrm{WienerProcess}\left(\mathrm{\Sigma }\right)$
 ${W}{≔}{\mathrm{_W0}}$ (5)
 > $\mathrm{ExpectedShortfall}\left(W\left(3\right)\left[1\right]+W\left(3\right)\left[2\right],\mathrm{replications}={10}^{4}\right)$
 ${-7.99062671598827}$ (6)

Here is an example of a stochastic process that depends on two factors: one is the previously defined Wiener process; the second is a Poisson process.

 > $J≔\mathrm{PoissonProcess}\left(1.0\right)$
 ${J}{≔}{\mathrm{_P}}$ (7)
 > $\mathrm{ExpectedShortfall}\left(5\left(J\left(3\right)-3\right)+W\left(3\right)\left[1\right],\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 ${-17.4924646820118}$ (8)
 > $S≔\mathrm{SampleValues}\left(5\left(J\left(3\right)-3\right)+W\left(3\right)\left[1\right],\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
  (9)
 > $\mathrm{Statistics}\left[\mathrm{Histogram}\right]\left(S,\mathrm{bincount}=50\right)$ > $\mathrm{Statistics}\left[\mathrm{DataSummary}\right]\left(S\right)$
 $\left[\begin{array}{c}{\mathrm{mean}}{=}{0.0279466202849899}\\ {\mathrm{standarddeviation}}{=}{8.91177087788190}\\ {\mathrm{skewness}}{=}{0.549503467646038}\\ {\mathrm{kurtosis}}{=}{3.32242144363525}\\ {\mathrm{minimum}}{=}{-20.8909815277844}\\ {\mathrm{maximum}}{=}{46.2811111672442}\\ {\mathrm{cumulativeweight}}{=}{10000.}\end{array}\right]$ (10)

Here are some expressions involving stochastic variables.

 > $Y≔\mathrm{WienerProcess}\left(\right)$
 ${Y}{≔}{\mathrm{_W1}}$ (11)
 > $Z≔t↦\mathrm{exp}\left(0.05\cdot t+0.3\cdot Y\left(t\right)\right)$
 ${Z}{≔}{t}{↦}{{ⅇ}}^{{0.05}{\cdot }{t}{+}{0.3}{\cdot }{Y}{}\left({t}\right)}$ (12)
 > $U≔t↦\mathrm{maximize}\left(Z\left(u\right),u=0..t\right)$
 ${U}{≔}{t}{↦}{\mathrm{maximize}}{}\left({Z}{}\left({u}\right){,}{u}{=}{0}{..}{t}\right)$ (13)
 > $\mathrm{ExpectedShortfall}\left(U\left(3\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 ${1.}$ (14)
 > $V≔t↦\frac{\mathrm{int}\left(Z\left(u\right),u=0..t\right)}{t}$
 ${V}{≔}{t}{↦}\frac{{{\int }}_{{0}}^{{t}}{Z}{}\left({u}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{u}}{{t}}$ (15)
 > $\mathrm{ExpectedShortfall}\left(V\left(3\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 ${0.513510368540462}$ (16)

This is the use of a path function.

 > testproc := proc(X) exp(X); end proc;
 ${\mathrm{testproc}}{:=}{\mathbf{proc}}\left({X}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{exp}}{}\left({X}{[}{11}{]}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (17)
 > $S≔\mathrm{ExpectedShortfall}\left(\mathrm{testproc},Y,0..3,\mathrm{timesteps}=10,\mathrm{replications}={10}^{4}\right)$
 ${S}{≔}{0.00958278261974139}$ (18)

References

 Glasserman, P., Monte Carlo Methods in Financial Engineering. New York: Springer-Verlag, 2004.
 Hull, J., Options, Futures, and Other Derivatives, 5th. edition. Upper Saddle River, New Jersey: Prentice Hall, 2003.
 Kloeden, P., and Platen, E., Numerical Solution of Stochastic Differential Equations, New York: Springer-Verlag, 1999.

Compatibility

 • The Finance[ExpectedShortfall] command was introduced in Maple 15.