Problem with retime function

조회 수: 8 (최근 30일)
Sonima
Sonima 2019년 8월 26일
편집: Cris LaPierre 2019년 8월 27일
Hello all.
I want to use retime to convert a M15 time table to for example a H1 table.
DateTime Open High Low Close Volume
____________________ _______ _______ _______ _______ ______
26-Aug-2019 00:00:00 0.89545 0.89638 0.89529 0.89638 199
26-Aug-2019 00:15:00 0.89638 0.89641 0.89589 0.896 187
26-Aug-2019 00:30:00 0.8962 0.89632 0.89574 0.89603 139
26-Aug-2019 00:45:00 0.89569 0.89594 0.89542 0.89546 157
In this case, I should get the followings:
Open = open@26-Aug-2019 00:00:00
Close = close@26-Aug-2019 00:45:00
High = (max(High))
Low = (min(Low))
resulting the below table.
DateTime Open High Low Close Volume
____________________ _______ _______ _______ _______ ______
26-Aug-2019 01:00:00 0.89545 0.89641 0.89529 0.89546 682
However whatever method I used within the retime function, it won't return what I described above.
Any solution to this?!

채택된 답변

Cris LaPierre
Cris LaPierre 2019년 8월 27일
편집: Cris LaPierre 2019년 8월 27일
It can be done in pieces. retime applies the same method to all timetable variables. You'll need to create new timetables (only containing the variables you need for each method) and call retime for each method you want to use (first value, max, min, last value, sum) . At the end, combine the smaller time tables together. See this example from the documentation.
If I were to do this with the table you show above, I'd do something like this.
% Create a timetable for each method only containing the variables that method is applied to
M15_open = M15(:,"Open");
M15_high = M15(:,"High");
M15_low = M15(:,"Low");
M15_close = M15(:,"Close");
M15_vol = M15(:,"Volume");
% Retime each timetable
H1_open = retime(M15_open,'hourly','firstvalue');
H1_high = retime(M15_high,'hourly','max');
H1_low = retime(M15_low,'hourly','min');
H1_close = retime(M15_close,'hourly','lastvalue');
H1_vol = retime(M15_vol,'hourly','sum');
% Combine the individual timetables back into a single time table
H1 = [H1_open H1_high H1_low H1_close H1_vol]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by