financial time series object - how to delete a column?

1 view (last 30 days)
One might have:
dt =
desc: (none)
freq: Daily (1)
'dates: (2715)' 'times: (2715)' 'Open: (2715)' 'High: (2715)' 'Low: (2715)' 'Close: (2715)' 'Vol: (2715)' 'OI: (2715)'
'19-Mar-2006' '22:00' [ 1164.25] [ 1186.5] [ 1160.5] [ 1183.75] [ 1149131] [ 1064369]
With both a dates and a times column ... to remove the times column one could think of:
dt_Close = fints(dt.dates, fts2mat(dt.Close))
This removes the times but gives only one column back ... I'd like to keep all columns and remove only the "times" column. So:
Is column indexing by column position (instead of column name) possible? This can be done for rows as:
dt([1 2 3]) % get only first 3 rows
dt([1 3:end]) % skip row 2
as described in another post here .... how can this be done for columns?

Accepted Answer

dpb
dpb on 17 Mar 2017
Edited: dpb on 18 Mar 2017
It's essentially just a structure so rmfield is implemented as is for a struct object. Ain't the easiest thing to find that out in the documentation, but if you go to the root page and then the 'Functions' link you'll find it...
You can, of course, address the column as
dt.times=[];
to remove the data but there's still an empty field that way.
ADDENDUM
Per the doc, it appears the only way to not have the times series is to pass only a date vector containing no time values...with a series of integer datenum, the first example for fints shows only a dates series.
NB: however, if the data are lacking time information and there are multiple elements for a given day, the internal logic will remove all except the first instance of each day from the resultant time series created--iow, a time series by definition can contain only a single observation at a given time.
So the answer to the question is "you can't" but you can avoid creating the times series initially (in which case you won't have any need to remove it. :) )
  3 Comments
dpb
dpb on 17 Mar 2017
OK, the times field is an unremovable property of the object...the date field was listed in the doc as always present but didn't see that the time was. Clearly, the error tells you it is.
The behavior is like a structure in many ways re: its syntax but it is not a user-definable structure wherein you can put whatever fields in you wish but a compiled class for which you have some flexibility but not unlimited. Looks like you just have to live with a time field; you can zero it out or perhaps you can even have an empty content, but the name is required.
Andy
Andy on 18 Mar 2017
yeah, but if you have it, it messes up when merging w/ other fints objects that don't have it ... better not to have it in certain circumstances. thx

Sign in to comment.

More Answers (1)

Andy
Andy on 18 Mar 2017
This was a funny one ... managed to understand why Time appears in the structure in the first place. Quote from fints definition:
" ... Dates can be date character vectors or serial date numbers and can include time of day information. If the input serial date numbers encode time-of-day information, the output object contains a column labeled 'dates' containing the date information and another labeled 'times' containing the time information. ... ".
So, although it cannot be removed, it can be avoided in the first place by:
... tsa =>
>> tsa(1:4,:)
ans =
732756.916666667 138.63 139.44 138.4 139.31 11992 219881
732757.916666667 140.59 140.73 139.85 140.24 15357 214085
It looks like tsa(:,1) has both date and time information. Hence, when creating the fints object w/:
dataTable = fints(tsa(:,1), tsa(:,2:end), colNames, freq);
we get both the Date and Time columns. To avoid this, do:
dataTable = fints( floor(tsa(:,1)), tsa(:,2:end), colNames, freq);
This way we remove the time info and Time column won't show up ... nice.

Community Treasure Hunt

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

Start Hunting!