Managing Memory, Performance, and Solution Accuracy

Managing Memory

There are two general approaches for managing memory when solving most problems supported by the SDE engine:

Enhancing Performance

The following approaches improve performance when solving SDE problems:

Optimizing Accuracy of Solutions

About Precision and Error

The simulation architecture does not, in general, simulate exact solutions to any SDE. Instead, the simulation architecture provides a discrete-time approximation of the underlying continuous-time process, a simulation technique often known as an Euler approximation.

In the most general case, a given simulation derives directly from an SDE. Therefore, the simulated discrete-time process approaches the underlying continuous-time process only in the limit as the time increment dt approaches zero. In other words, the simulation architecture places more importance on ensuring that the probability distributions of the discrete-time and continuous-time processes are close, than on the pathwise proximity of the processes.

Before illustrating techniques to improve the approximation of solutions, it is helpful to understand the source of error. Throughout this architecture, all simulation methods assume that model parameters are piece-wise constant over any time interval of length dt. In fact, the methods even evaluate dynamic parameters at the beginning of each time interval and hold them fixed for the duration of the interval. This sampling approach introduces discretization error.

However, there are certain models for which the piece-wise constant approach provides exact solutions:

More generally, you can simulate the exact solutions for these models even if the parameters vary with time, if they vary in a piece-wise constant way such that parameter changes coincide with the specified sampling times. However, such exact coincidence is unlikely; therefore, the previously discussed constant parameter condition is commonly used in practice.

One obvious way to improve accuracy involves sampling the discrete-time process more frequently. This decreases the time increment (dt), causing the sampled process to more closely approximate the underlying continuous-time process. Although decreasing the time increment is universally applicable, however, there is a tradeoff among accuracy, run-time performance, and memory usage.

To manage this tradeoff, specify an optional input argument, NSTEPS, for all simulation methods. NSTEPS indicates the number of intermediate time steps within each time increment dt, at which the process is sampled but not reported.

It is important and convenient at this point to emphasize the relationship of the inputs NSTEPS, NPERIODS, and DeltaTime to the output vector Times, which represents the actual observation times at which the simulated paths are reported.

The following example illustrates this intermediate sampling by comparing the difference between a closed-form solution and a sequence of Euler approximations derived from various values of NSTEPS.

Example: Improving SDE Solution Accuracy by Increasing Sampling of the Discrete-Time Process

Consider a univariate geometric Brownian motion (GBM) model with constant parameters:

Assume that the expected rate of return and volatility parameters are annualized, and that a calendar year comprises 250 trading days.

  1. Simulate approximately four years of univariate prices for both the exact solution and the Euler approximation for various values of NSTEPS:

    nPeriods 	= 1000;    
    dt       	= 1 / 250; 	
    obj 		= gbm(0.1, 0.4, 'StartState', 100);
    randn('state', 25)
    [X,T]	 	= obj.simBySolution(nPeriods, 'DeltaTime', dt);
    randn('state', 25)
    [Y,T] 		= obj.simByEuler(nPeriods, 'DeltaTime', dt);
    clf, plot(T, X - Y, 'red'), hold('on')
    randn('state', 25)
    [X,T] 		= obj.simBySolution(nPeriods, 'DeltaTime',... 
    				dt, 'nSteps', 2);
    randn('state', 25)
    [Y,T] 		= obj.simByEuler(nPeriods, 'DeltaTime', ...
    				dt, 'nSteps', 2);
    plot(T, X - Y, 'blue')
    randn('state', 25)
    [X,T] 		= obj.simBySolution(nPeriods, 'DeltaTime', ... 
    				dt, 'nSteps', 10);
    randn('state', 25)
    [Y,T] 		= obj.simByEuler(nPeriods, 'DeltaTime', ... 
    				dt, 'nSteps', 10);
    plot(T, X - Y, 'green')
    randn('state', 25)
    [X,T] 		= obj.simBySolution(nPeriods, 'DeltaTime', ... 
    				dt, 'nSteps', 100);
    randn('state', 25)
    [Y,T] 		= obj.simByEuler(nPeriods, 'DeltaTime', ... 
    				dt, 'nSteps', 100);
    plot(T, X - Y, 'black'), hold('off')
  2. Compare the error (the difference between the exact solution and the Euler approximation) graphically:

    xlabel('Time (Years)'), ylabel('Price Difference')
    title('Exact Solution Minus Euler Approximation: ...
      Constant Parameter GBM')
    legend({'# of Steps = 1'  '# of Steps = 2'    ...
           '# of Steps = 10' '# of Steps = 100'}, ...
      'Location', 'Best')
    hold('off')

As expected, the simulation error decreases as the number of intermediate time steps increases. Because the intermediate states are not reported, all simulated time series have the same number of observations regardless of the actual value of NSTEPS:

whos T X Y
  Name       Size       Bytes  Class   Attributes

  T         1001x1      8008  double             
  X         1001x1      8008  double             
  Y         1001x1      8008  double             

Furthermore, since the previously simulated exact solutions are correct for any number of intermediate time steps, additional computations are not needed for this example. In fact, this assessment is generally correct. The exact solutions are sampled at intermediate times to ensure that the simulation uses the same sequence of Gaussian random variates in the same order. Without this assurance, there is no way to compare simulated prices on a pathwise basis. However, there might be valid reasons for sampling exact solutions at closely spaced intervals, such as pricing path-dependent options.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS