-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_trade_periods.m
41 lines (34 loc) · 1.41 KB
/
ts_trade_periods.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function [ dataH, datetimesH ] = ts_trade_periods( nTradePeriods, data, datetimes)
%TS_TRADE_PERIODS Summary of this function goes here
% Detailed explanation goes here
% if(nargin < 2 || isempty(data) || isempty(datetimes) || nnz(size(data) ~= size(datetimes)))
% error('Data and datetimes must be non empty matrixes or vectors with the equal number of rows and columns');
% end
if(nargin < 3)
datetimes = [];
end
[nObs, nHours] = size(data);
if(nTradePeriods == nHours)
dataH = data;
if(~isempty(datetimes))
datetimesH = datetimes;
end
else
nDays = floor(nObs/nTradePeriods);
if(nDays < 1)
error(['Number of observations is smaller then ', num2str(nTradePeriods)]);
end
nBalance = nObs - nDays*nTradePeriods;
if(nBalance > 0)
warning(['Number of observations does not consist of an integer number of days, the last ', num2str(nBalance), ' observations are ignored']);
end
dataH = data(1:nDays*nTradePeriods);
if(~isempty(datetimes))
datetimesH = datetimes(1:nDays*nTradePeriods);
end
dataH = (reshape(dataH, nTradePeriods, nDays))';
if(~isempty(datetimes))
datetimesH = (reshape(datetimesH, nTradePeriods, nDays))';
end
end
end