Financial Time Series Toolbox    

Indexing a Financial Time Series Object

You can also index into the object as with any other MATLAB variable or structure. A financial time series object lets you use a date string, a cell array of date strings, a date string range, or normal integer indexing. You cannot, however, index into the object using serial dates. If you have serial dates, you must first use the MATLAB datestr command to convert them into date strings.

When indexing by date string note that:

Indexing with Date Strings

With date string indexing you get the values in a financial time series object for a specific date using a date string as the index into the object. Similarly, if you want values for multiple dates in the object, you can put those date strings into a cell array and use the cell array as the index to the object. Here are some examples.

This example extracts all values for May 11, 1999 from myfts:

The next example extracts only series2 values for May 11, 1999 from myfts:

The third example extracts all values for three different dates:

The next example extracts only series2 values for the same three dates:

Indexing with Date String Range

A financial time series is unique because it allows you to index into the object using a date string range. A date string range consists of two date strings separated by two colons (::). In MATLAB this separator is called the double-colon operator. An example of a MATLAB date string range is '05/11/99::05/31/99'. The operator gives you all data points available between those dates, including the start and end dates.

Here are some date string range examples:

As with any other MATLAB variable or structure, you can assign the output to another object variable:

nfts is the same as ans in the second example.

If one of the dates does not exist in the object, an error message indicates that one or both date indexes are out of the range of the available dates in the object. You can either display the contents of the object or use the command ftsbound to determine the first and last dates in the object.

Indexing with Integers

Integer indexing is the normal form of indexing in MATLAB. Indexing starts at 1 (not 0); index = 1 corresponds to the first element, index = 2 to the second element, index = 3 to the third element, and so on. Here are some examples with and without data series reference.

Get the first item in series2:

Get the first, third, and fifth items in series2:

Get items 16 through 20 in series2:

Get items 16 through 20 in the financial time series object myfts:

Get the last item in myfts:

This example uses the MATLAB special variable end, which points to the last element of the object when used as an index. The example returns an object whose contents are the values in the object myfts on the last date entry.

Indexing When Time-of-Day Data Is Present

Both integer and date string indexing are permitted when time-of-day information is present in the financial time series object. You can index into the object with both date and time specifications, but not with time of day alone. To show how indexing works with time-of-day data present, create a financial time series object called timeday containing a time specification:

Use integer indexing to extract the second and third data items from timeday:

For date string indexing enclose the date and time string in one pair of quotation marks. If there is one date with multiple times, indexing with only the date returns the data for all the times for that specific date. For example, the command timeday('01-Jan-2001') returns the data for all times on January 1, 2001:

You can also indicate a specific date and time:

Use the double colon operator :: to specify a range of dates and times:

Treat timeday as a MATLAB structure if you want to obtain the contents of a specific field. For example, to find the times of day included in this object, enter


  Object to Matrix Conversion Operations