Filling in secondly intervals between 15:30:00 to 22:00:00 (require more efficient method)

1 次查看(过去 30 天)
I have data in the form of
Hi all I have prices which change every 15 seconds throughout the whole day.
I want to make the the price secondly rather than every 15 seconds. This is so that I can compare it to another second-second data.
Here is a sample of my data:
'26/01/2012 15:29:39' 168.008200000000
'26/01/2012 15:29:54' 168.042200000000
'26/01/2012 15:30:09' 168.022300000000
'26/01/2012 15:30:24' 167.964000000000
'26/01/2012 15:30:39' 167.968800000000
'26/01/2012 15:30:54' 167.964000000000
'26/01/2012 15:31:09' 167.973700000000
'26/01/2012 15:31:24' 167.954700000000
Like I said I want the data to be second-second from 15:30:00 to 22:00:00. So for example:
From the period of 15:30:00 - 15:30:09 we would maintain a price of 168.0422
Then from the period of 15:30:09 to 15:30:24 we would maintain a price of 168.0223 secondly.
I hope I have explained this well and I look forward to all replies.
The "raw" data is calculated 15 seconds and even go beyond 22:00 and is irregular.
"" The program would need to take any data in the form of below and then just give secondly prices from 15:30:00 - 22:00:00.
Thanks
  6 个评论
Thomas
Thomas 2012-4-4
Another thought: why do you just reduce the other value you are comparing this data set to, to be every 15 seconds..
Mate 2u
Mate 2u 2012-4-4
Hi Jonathan, Yes I do understand I wont make that mistake again.
Thomas. I have two time series which have the same date formats. One is prices of a particular asset which change many times in a second. I am comparing it to another asset which is "priced" every 15 seconds. I need it every second so that I can decide "trade" decisions every second.
Thanks.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2012-4-4
I try it again. I have no access to Matlab currently. Please test this an post, where it fails together with the error message or an explanation of the difference between your expectations and the results.
C = {'26/01/2012 15:29:39', 168.008200000000; ...
'26/01/2012 15:29:54', 168.042200000000; ...
'26/01/2012 15:30:09', 168.022300000000; ...
'26/01/2012 15:30:24', 167.964000000000; ...
'26/01/2012 15:30:39', 167.968800000000; ...
'26/01/2012 15:30:54', 167.964000000000; ...
'26/01/2012 15:31:09', 167.973700000000; ...
'26/01/2012 15:31:24', 167.954700000000};
Time = round(datenum(C(:, 1), 'dd/mm/yyyy HH:MM:SS') * 86400)
allTime = Time(1):Time(end);
index = cumsum(ismember(allTime, Time));
Value = cat(1, C{:, 2});
allValue = Value(index);
  3 个评论
Matt Tearle
Matt Tearle 2012-4-4
@Jan: beautiful!
@Mate 2u: Note that Jan just used the first and last points of Time to make the fine-grain time vector. If you want specific values (15:30:00 to 22:00:00) you could just hard-code those in. But also note that Jan's solution is using date numbers scaled up by 86400 (= the number of seconds in a day) so each integer value is a second. Hence:
startTime = datenum('26/02/2012 15:30:00' 'dd/mm/yyyy HH:MM:SS')*86400;
endTime = datenum('26/02/2012 22:00:00' 'dd/mm/yyyy HH:MM:SS')*86400;
allTime = startTime:endTime;
You could even figure out the start and end times automatically, if you had some rationale behind how you chose them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by