-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathfillMissingData.m
36 lines (31 loc) · 1.11 KB
/
fillMissingData.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
function my_prices=fillMissingData(prices, varargin)
% my_prices=fillMissingData(prices) fills missing price with previous
% day's price
% my_prices=fillMissingData(prices, tday, cday) fills missing prices with previous day's price including non-trading days
% as specified in cday
if (nargin == 1)
my_prices=prices;
for t=2:size(my_prices, 1)
missData=~isfinite(my_prices(t, :, :));
my_prices(t, missData)=my_prices(t-1, missData);
end
else
% We deal only with 2 dim prices array here.
tday=varargin{1};
cday=varargin{2};
my_prices=NaN*zeros(size(cday, 1), size(prices, 2));
tdayIdx=find(tday==cday(1));
if (~isempty(tdayIdx))
my_prices(1, :)=prices(tdayIdx, :);
end
for t=2:size(my_prices, 1)
tdayIdx=find(tday==cday(t));
if (~isempty(tdayIdx))
my_prices(t, :)=prices(tdayIdx, :);
missData=find(~isfinite(my_prices(t, :)));
my_prices(t, missData)=my_prices(t-1, missData);
else
my_prices(t, :)=my_prices(t-1, :);
end
end
end