How do you count points above the horizontal line?

Hello everyone. Could you please help me write code to count points above the horizontal red line. Thanks.

 Accepted Answer

% Data array
Data = [....]
% Treshold
Limit = 0;
% Count
AboveLimit = sum(Data > Limit)

7 Comments

okay thanks but mr Arthur what if the code is as 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 = t(:,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) = [];
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,:);
[RAW, REW] = mcd(matrix_logdiff, 'bdp', 0.5);
% mean_vec = mean(matrix_logdiff_nsample); %finding the mean.
%
% mean_vec = mean_vec';
%
% cov_matrix = cov(matrix_logdiff_nsample); %the covariance
mean_vec= REW.loc;
cov_matrix=REW.cov;
dt=1;
%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';
chi2quantile = chi2inv(0.99,p);
plot(REW.md,'b.')
line([0 3.5e+04],[chi2quantile, chi2quantile], 'color', 'r')
xlabel('observation indices')
ylabel('square Mahalanobis Distance')
In your case, it should be
sum(REW.md > chi2quantile)
Thanks so much mr Arthur .. Please can i ask you a different question
The thing is im working on this stock prices and im suppose to write a code to read only stocks(close prices) from the different LSEs whose index are not more than 60 seconds
%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
dt=1;
%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';
I require some time to analyze your issue, can you create another MATLAB question ? This way, maybe me or another user will help you

Sign in to comment.

More Answers (0)

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!