explain the logic please

2 ビュー (過去 30 日間)
Bob Matthews
Bob Matthews 2021 年 10 月 30 日
編集済み: Bob Matthews 2021 年 10 月 30 日
Hi
Here is a small piece of code (3rd party)
*************************************************
function A = TR1_4_CountTime(DCA,Time)
% calculate time differences between each row
for i=1:length(DCA)-1
A(i) = 0 ;
for j=DCA(i)+1:DCA(i+1)
A(i) = A(i) + Count(Time{j},Time{j-1}) ;
end
end
end
function s = Count(time1,time2)
if ~isequal(time1(1:2),time2(1:2)) % if data are not in the same day,
% set default time gap as 1 millisecond
t1=datenum(time1(find(time1==',')+1:end),'HH:MM:SS')+1;
t2=datenum(time2(find(time2==',')+1:end),'HH:MM:SS');
s=round((t1-t2)*24*60); % for minute data
return ;
else % if data are in the same day, calculate time difference
t1=datenum(time1(find(time1==',')+1:end),'HH:MM:SS');
t2=datenum(time2(find(time2==',')+1:end),'HH:MM:SS');
s=round((t1-t2)*24*60); % for minute data
end
end
************************************************************
please can somebody explain what the author is trying to do ?
Bob M

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 30 日
編集済み: Walter Roberson 2021 年 10 月 30 日
time1 and time2 are character vectors in which day number are represented as the first two characters . At some point in the character vectors, there is a comma, which is immediately followed by characters representing hours (24 hour), minutes, and seconds.
The code extracts the hours, minutes, and seconds of the two times, and finds the difference and converts it to minutes. If the two times were on different day numbers, then then 1 day is added -- even if the dates were multiple days apart.
I would recommend replacing the whole thing with converting to datetime objects and taking round(minutes()) of the difference of the datetime objects.

その他の回答 (1 件)

Bob Matthews
Bob Matthews 2021 年 10 月 30 日
編集済み: Bob Matthews 2021 年 10 月 30 日
Thanks Walter...............
My problem is with the output I see - for example
*****************************
T_EXT PEXT T_DCC PDCC PDCC* OSVEXT TMVEXT T R_DC sub_NDC USV
01/07/2016,00:32:0 102.924 04/07/2016,21:26:0 102.146 102.1521 -2.5153 -3.49643 13 0
06/07/2016,06:34:0 100.225 06/07/2016,10:02:0 101.023 100.9767 0.634222 1.638979 390 16.33936 9 0.400092
06/07/2016,13:04:0 101.457 07/07/2016,01:53:0 100.695 100.6961 -0.60257 -1.59805 12 0.229072
08/07/2016,08:30:0 100.241 08/07/2016,08:31:0 101.184 100.9928 0.252417 1.25431 1 4876.759 3 0.382866
08/07/2016,08:31:0 101.184 08/07/2016,09:10:0 100.395 100.4251 -0.52061 -1.51671 44 134.0219 1 0.010622
*******************************
In the 4th row, T = 1 which is correct [8:30 -> 8:31] - same day
but in the 5th row T = 44 which is incorrect, T should be 39 [8:31 -> 9:10] ??????
Most of the T values are completely wrong................
The whole exercise of calculating time differences is wrong due to the real life situation in the forex market
for example:- One price can be at 14:59 on a certain day whereas the very next price can be at 03:00 on the following day
Here the value of T is 1 ! because the prices are next to each other - forget subtracting dates and time
IMHO, the correct way is to look at the array of prices - which is the initial and only input to this exercise
By subtracting the index of the T_DCC Price from the index of the T_EXT Price - you get the correct 'time difference'
Bob M
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 30 日
In the extract you posted, as outside observers we do not have enough information to know what order the date/times were extacted from the file and stored into the Time array, and we also do not know what DCA is about.
Bob Matthews
Bob Matthews 2021 年 10 月 30 日
編集済み: Bob Matthews 2021 年 10 月 30 日
Here is a snippet of the minute data input ( in chronological order)
****************************************
01/07/2016 00:00:00 102.827
01/07/2016 00:01:00 102.842
01/07/2016 00:02:00 102.843
01/07/2016 00:03:00 102.86
01/07/2016 00:04:00 102.865
01/07/2016 00:05:00 102.871
01/07/2016 00:06:00 102.881
01/07/2016 00:07:00 102.882
01/07/2016 00:08:00 102.875
01/07/2016 00:09:00 102.876
01/07/2016 00:10:00 102.869
*******************************************
I think DCA is the number of DC events (Directional Change Events)
where DC Events are Upturn, Downturn, Upturn, Downturn etc. (at a certain threshold)
Bob M

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by