% Make data for Challenge 3 of stochastic differential
% equation case study.
%
% To create a datafile, change the initial state of
% the random number generator and the specified values
% of alpha, beta, and Xzero.
%
% The data satisfy
%
%      dX = alpha*X dt + beta*X dW,  X(0) = Xzero.
%
% The discretized Brownian path over [0,1] has dt = 2^(-9).
% 
% Dianne P. O'Leary 11/2008

% Initialize the random number generator.

randn('state',238516)

% Specify the problem parameters.

alpha = 4.25; beta = .875; Xzero = 0.5;

% The problem will be solved for 0 <= t <= T with N timesteps,
% each of length dt.  This gives values at the times specified
% in Times.

T = .5; N = 2^9; dt = T/N;
Times=((0:N)*dt)';

% Precompute the Brownian increments.

dW = [0; sqrt(dt)*randn(N,1)];     
W = cumsum(dW);

% Compute the true solution to the Black-Scholes equation.

a1 = alpha - .5*beta*beta;
X = Xzero*exp(a1*Times) + beta*W;

plot(Times,X,'*')
xlabel('time t')
ylabel('X(t)')
title('The data')

save mydata Times X
                       
