Clear Filters
Clear Filters

Stock Prices simulation and statistics

3 views (last 30 days)
Afua Amoako Dadey
Afua Amoako Dadey on 20 Jul 2020
Hello, Please can someone help me with how to write a code to use the indices whose time are not more than 60 seconds from the attached different LSEs. Specifically, i am considering the different close prices from the different LSEs below.
%close prices in matrix
nstock_val=[Close(1:30928,1) Close1(1:30928,1) Close2(1:30928,1) Close3(1:30928,1) Close4(1:30928,1)]; % reading the data
t = (Gmttime); % reading the data
time = datetime(t,'inputformat','dd.MM.yyyy HH:mm:ss.SSS');
LSE_matrix =log(nstock_val); %log of the datanstock_val=[Close(1:30928,1) Close1(1:30928,1) Close2(1:30928,1) Close3(1:30928,1) Close4(1:30928,1)]; % reading the data
I=1:(size(LSE_matrix,1)-1); % selecting the indices of all prices but the last time when stock was opened
% data = time(:,1);
% id = [false; diff(time(:,1))> seconds(60)];%finds all row indices where the previous row
% %differs by more than 60 seconds
% data(id,:) = [];% deletes all data in those rows.
% time(id) = [];
I= I(diff(time(:,1)) <= seconds(60));
dLSE_col1 = LSE_matrix(I+1,1) - LSE_matrix(I,1);% log difference
dLSE_col2 = LSE_matrix(I+1,2) - LSE_matrix(I,2);
dLSE_col3 = LSE_matrix(I+1,3) - LSE_matrix(I,3);
dLSE_col4 = LSE_matrix(I+1,4) - LSE_matrix(I,4);
dLSE_col5 = LSE_matrix(I+1,5) - LSE_matrix(I,5);
matrix_logdiff=[dLSE_col1 dLSE_col2 dLSE_col3 dLSE_col4 dLSE_col5];
nsample = floor((2/3)* length(matrix_logdiff)); %two thirds of the log
% difference of the data
matrix_logdiff_nsample = matrix_logdiff(1:nsample,:);
mean_vec = mean(matrix_logdiff_nsample); %finding the mean.
mean_vec = mean_vec';
cov_matrix = cov(matrix_logdiff_nsample); %the covariance
%GBM parameter estimate
capbhat = sqrtm(cov_matrix./dt);
ahat_vec = (mean_vec/dt)+ diag((capbhat).^2)/2;
s0_vector =[nstock_val(nsample,1) nstock_val(nsample,2) nstock_val(nsample,3) nstock_val(nsample,4) nstock_val(nsample,5)];
s0_vector = s0_vector';

Answers (0)


Find more on Stochastic Differential Equation (SDE) Models in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!