%% Induce Dependence Between States
%% Load the data set

load Data_GlobalIdx2
prices  = [Dataset.TSX Dataset.CAC Dataset.DAX ...
    Dataset.NIK Dataset.FTSE Dataset.SP];

%
%% Convert prices to returns

returns =  tick2ret(prices);

%
%% Specify sigma and corelation using technique 1 Sigma

expReturn   = diag(mean(returns));  % expected return vector
sigma       = diag(std(returns));   % volatility of returns

%
%% Specify sigma and corelation using technique 1 Correlation

correlation = corrcoef(returns);    
GBM1        = gbm(expReturn,sigma,'Correlation',...
                  correlation);

%
%% Specify sigma and correlation using technique 2 Sigma

covariance = cov(returns);
sigma      = cholcov(covariance)';

%
%% Specify sigma and correlation using technique 2 Correlation

GBM2       = gbm(expReturn,sigma);

%
%% Simulate using both specifications Math

rng(22814,'twister')
[X1,T] = simByEuler(GBM1,1000);  % correlated Brownian motion
rng(22814,'twister')
[X2,T] = simByEuler(GBM2,1000);  % standard Brownian motion

%
%% Simulate using both specifications Plot

subplot(2,1,1)
plot(T, X1)
title('Sample Paths from Correlated Brownian Motion')
ylabel('Asset Price')
subplot(2,1,2)
plot(T, X2)
title('Sample Paths from Standard Brownian Motion')
xlabel('Trading Day')
ylabel('Asset Price')

% Copyright 2015 The MathWorks, Inc.