Finding peak (highest price), trough (lowest price), and average distance between peak and trough for a series of prices
1 回表示 (過去 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.
current price
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
Pnow =cell2mat(New_datax(end-18:end,i));
whereInRng = ((Pnow(end,1)-abs(minVal))./Rng)*100;
store(i) = whereInRng;
storelow(i) = minVal;
storehigh(i) = maxVal;
end
colheadminmax = New_datax(1,:);
col_head_minmax={'Pair','MinMaxPosition','pdi','mdi','adx','adxr'};
col_head_minmax2={'Pair','MinMaxPosition','Price','High_Price(14)' ,'Low_Price(14)'};
Table_minmax = ([colheadminmax; num2cell(store)])';
Table_minmax_all=[col_head_minmax;Table_minmax];
Table_minmax2 = horzcat(Table_minmax,New_datax(end,:)',num2cell(storehigh)', num2cell(storelow)');
Table_minmax2_all =[col_head_minmax2;Table_minmax2];
xlwrite('myminmaxrng',Table_minmax2_all);
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!