Problem with retime function

4 次查看(过去 30 天)
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