Finance - Maple Programming Help

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

Finance

 DynamicPortfolio
 create new dynamic portfolio

 Calling Sequence DynamicPortfolio(update, weights, components, updates)

Parameters

 update - procedure; procedure for determining how the weights should be updated weights - list or Vector; initial weights components - stochastic process, list or Vector of stochastic processes; components of the portfolio updates - (optional) continuous or positive integer; indicates how often the portfolio should be updated

Description

 • The DynamicPortfolio command creates new dynamically updated portfolio.
 • The parameter update is a procedure used for calculating the updated weights of the portfolio. This procedure will be called every time the portfolio is rebalanced. The following five arguments will be passed to the procedure: $W$, ${W}_{0}$, $X$, ${X}_{0}$ and $t$, where $W$ is the vector of new weights, $X$ is the vector of new values, ${W}_{0}$ is the vector of old weights, ${X}_{0}$ is the vector old values and $t$ is the current time.
 • The parameter weights is the vector of initial weights.
 • The parameter components is either a multi-dimensional stochastic process or a vector of one-dimensional stochastic processes.
 • Finally, the (optional) parameter updates controls how often the portfolio should be updated. Possible values are continuous or any positive integer. This integer value will specify the number of updates per year. If the value of this parameter is continuous, then the portfolio will be updated at every point in the discretization time grid.

Examples

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

Consider two processes. The first process is a geometric Brownian motion. The second process is a deterministic process with constant value 1.0.

 > $\mathrm{X1}≔\mathrm{GeometricBrownianMotion}\left(1,0.05,0.3\right):$
 > $\mathrm{X2}≔\mathrm{DeterministicProcess}\left(1.0\right):$
 > $\mathrm{Value}≔t→{t}_{1}{t}_{3}+{t}_{2}{t}_{4}$
 ${\mathrm{Value}}{≔}{t}{→}{{t}}_{{1}}{}{{t}}_{{3}}{+}{{t}}_{{2}}{}{{t}}_{{4}}$ (1)
 > U := proc(w, w0, x, x0, t) if x[1] < 1.05 then w[1] := 0; w[2] := 1; else w[1] := 1; w[2] := 0; end if; end proc;
 ${U}{≔}{\mathbf{proc}}\left({w}{,}{\mathrm{w0}}{,}{x}{,}{\mathrm{x0}}{,}{t}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{[}{1}{]}{<}{1.05}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{w}{[}{1}{]}{≔}{0}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{w}{[}{2}{]}{≔}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{w}{[}{1}{]}{≔}{1}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{w}{[}{2}{]}{≔}{0}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $W≔⟨1.0,0.0⟩$
 ${W}{≔}\left[\begin{array}{c}{1.0}\\ {0.}\end{array}\right]$ (3)
 > $X≔⟨\mathrm{X1},\mathrm{X2}⟩$
 ${X}{≔}\left[\begin{array}{c}{\mathrm{_X}}\\ {\mathrm{_P}}\end{array}\right]$ (4)
 > $P≔\mathrm{DynamicPortfolio}\left(U,W,X\right):$
 > $\mathrm{AP}≔\mathrm{SamplePath}\left(P\left(t\right),t=0..1,\mathrm{timesteps}=50,\mathrm{replications}=10\right)$
 ${\mathrm{AP}}{≔}\left[\begin{array}{c}{\mathrm{1..10 x 1..4 x 1..51}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (5)
 > $\mathrm{PathPlot}\left(\mathrm{AP},1,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{AP},2,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{Value}\left(P\left(t\right)\right),t=0..1,\mathrm{thickness}=3,\mathrm{markers}=\mathrm{false},\mathrm{timesteps}=50,\mathrm{replications}=10,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > Q := DynamicPortfolio(proc() end, W, X):
 > $\mathrm{AQ}≔\mathrm{SamplePath}\left(Q\left(t\right),t=0..1,\mathrm{timesteps}=50,\mathrm{replications}=10\right)$
 ${\mathrm{AQ}}{≔}\left[\begin{array}{c}{\mathrm{1..10 x 1..4 x 1..51}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (6)
 > $\mathrm{PathPlot}\left(\mathrm{AQ},1,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{AQ},2,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{Value}\left(Q\left(t\right)\right),t=0..1,\mathrm{thickness}=3,\mathrm{markers}=\mathrm{false},\mathrm{timesteps}=50,\mathrm{replications}=10,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > R := DynamicPortfolio(proc() end, <0.0, 1.0>, X):
 > $\mathrm{AR}≔\mathrm{SamplePath}\left(R\left(t\right),t=0..1,\mathrm{timesteps}=50,\mathrm{replications}=10\right)$
 ${\mathrm{AR}}{≔}\left[\begin{array}{c}{\mathrm{1..10 x 1..4 x 1..51}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (7)
 > $\mathrm{PathPlot}\left(\mathrm{AR},1,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{AR},2,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{PathPlot}\left(\mathrm{Value}\left(R\left(t\right)\right),t=0..1,\mathrm{thickness}=3,\mathrm{markers}=\mathrm{false},\mathrm{timesteps}=50,\mathrm{replications}=10,\mathrm{color}=\mathrm{red}..\mathrm{blue},\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true}\right)$
 > $\mathrm{Value}≔\left(t,u\right)→{t}_{1}{t}_{3}+{t}_{2}{t}_{4}-\mathrm{max}\left(u,0\right)$
 ${\mathrm{Value}}{≔}\left({t}{,}{u}\right){→}{{t}}_{{1}}{}{{t}}_{{3}}{+}{{t}}_{{2}}{}{{t}}_{{4}}{-}{\mathrm{max}}{}\left({u}{,}{0}\right)$ (8)
 > $\mathrm{ExpectedValue}\left(\mathrm{Value}\left(P\left(1\right),\mathrm{X1}\left(1\right)-1.05\right),\mathrm{timesteps}=50,\mathrm{replications}={10}^{4},\mathrm{output}=\left[\mathrm{value},\mathrm{standarddeviation}\right]\right)$
 $\left[{\mathrm{value}}{=}{1.021297741}{,}{\mathrm{standarddeviation}}{=}{0.3242635701}\right]$ (9)
 > $\mathrm{ExpectedValue}\left(\mathrm{Value}\left(Q\left(1\right),\mathrm{X1}\left(1\right)-1.05\right),\mathrm{timesteps}=50,\mathrm{replications}={10}^{4},\mathrm{output}=\left[\mathrm{value},\mathrm{standarddeviation}\right]\right)$
 $\left[{\mathrm{value}}{=}{0.9307660907}{,}{\mathrm{standarddeviation}}{=}{0.3878610911}\right]$ (10)
 > $\mathrm{ExpectedValue}\left(\mathrm{Value}\left(R\left(1\right),\mathrm{X1}\left(1\right)-1.05\right),\mathrm{timesteps}=50,\mathrm{replications}={10}^{4},\mathrm{output}=\left[\mathrm{value},\mathrm{standarddeviation}\right]\right)$
 $\left[{\mathrm{value}}{=}{0.8736073177}{,}{\mathrm{standarddeviation}}{=}{0.2214176439}\right]$ (11)
 > $\mathrm{ExpectedValue}\left(\mathrm{max}\left(\mathrm{X1}\left(1\right)-1.05,0\right),\mathrm{timesteps}=50,\mathrm{replications}={10}^{4},\mathrm{output}=\left[\mathrm{value},\mathrm{standarddeviation}\right]\right)$
 $\left[{\mathrm{value}}{=}{0.1246581605}{,}{\mathrm{standarddeviation}}{=}{0.2178360124}\right]$ (12)

Compatibility

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