function stint ( )

%*****************************************************************************80
%
%% stint() approximates a stochastic integral.
%
%  Discussion:
%
%    This function estimates both the Ito and Stratonovich 
%    integrals of W(t) dW over the interval [0,1].
%
%    Both estimates are made by taking N steps.  Increasing
%    N will improve the approximation of the integrals by
%    the sums.  However, the Ito and Stratonovich integrals
%    are not equal, and therefore the sums that approximate
%    them will also not tend to the same value. 
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 September 2006
%
%  Author:
%
%    Desmond Higham
%
%  Reference:
%
%    Desmond Higham,
%    An Algorithmic Introduction to Numerical Simulation of
%    Stochastic Differential Equations,
%    SIAM Review,
%    Volume 43, Number 3, September 2001, pages 525-546.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'strint() approximates a stochastic integral.\n' );

% rng ( 'shuffle' );

  T = 1;
  N = 100000;
  dt = T / N;
%
%  Set the increments and the cumulative sums.
%
  dw = sqrt ( dt ) * randn ( 1, N );
  w = cumsum ( dw );
%
%  Form the sums that approximates the Ito and Stratonovich integrals.
%
  ito_exact = 0.5 * ( w(end)^2 - T )
  ito_estimate = sum ( [0,w(1:end-1)] .* dw )
  ito_error = abs ( ito_estimate -  ito_exact )

  strat_exact = 0.5 * w(end)^2
  strat_estimate = sum ( ( 0.5 * ( [0,w(1:end-1)] + w ) ...
                + 0.5 * sqrt ( dt ) * randn ( 1, N ) ) .* dw )
  strat_error = abs ( strat_estimate - strat_exact )

  return
end
