Finding peak (highest price), trough (lowest price), and average distance between peak and trough for a series of prices
2 ビュー (過去 30 日間)
I have a n x m cell array of prices. I use the code below to find the highest price, the lowest price, and the percentile range of the current price in between the highest and lowest price range over an arbitrary period of n = 20.
Its rather crude.
What I want is to store the following variables for each instrument for each period, perhaps in a 3D array.
percentile of current price
high price over n periods
low price over n periods
n periods (minpeakdistance)
I want however to calculate the true n period that is the "minpeakdistance" (distance between average peak (high) price and average trough (low price) as it is called in the "findpeaks" literature on Matlab.
%% Here we find the min min max range over 60 days, and locate the percentile rank of current price within that range
storehigh =zeros(1, size(New_datahighbidx,2));
storelow = zeros(1, size(New_datahighbidx,2));
store = zeros(1, size(New_datahighbidx,2)); % Preallocation
% for i = 1 : size((New_datax),2)
for i = 1 : size((New_datahighbidx),2);
A = cell2mat(New_datahighbidx(end-18:end,i));
Alow = cell2mat(New_datalowbidx(end-18:end,i));
[maxVal maxInd] = max(A); % find the max value and max Index in B
[minVal minInd] = min(Alow); % find the min value and min Index in B
Rng = abs(maxVal)-abs(minVal);
% where is the last price in the range of minumimn to maximum
whereInRng = ((Pnow(end,1)-abs(minVal))./Rng)*100;
store(i) = whereInRng;
storelow(i) = minVal;
storehigh(i) = maxVal;
colheadminmax = New_datax(1,:);
Table_minmax = ([colheadminmax; num2cell(store)])';
Table_minmax2 = horzcat(Table_minmax,New_datax(end,:)',num2cell(storehigh)', num2cell(storelow)');