Documentation

Working with Financial Time Series Objects

Introduction

A financial time series object is used as if it were a MATLAB® structure. (See the MATLAB documentation for a description of MATLAB structures or how to use MATLAB in general.)

This part of the tutorial assumes that you know how to use MATLAB and are familiar with MATLAB structures. The terminology is similar to that of a MATLAB structure. The financial time series object term component is interchangeable with the MATLAB structure term field.

Financial Time Series Object Structure

A financial time series object always contains three component names: desc (description field), freq (frequency indicator field), and dates (date vector). If you build the object using the constructor fints, the default value for the description field is a blank character vector (''). If you build the object from a text data file using ascii2fts, the default is the name of the text data file. The default for the frequency indicator field is 0 (Unknown frequency). Objects created from operations can default the setting to 0. For example, if you decide to pick out values selectively from an object, the frequency of the new object might not be the same as that of the object from which it came.

The date vector dates does not have a default set of values. When you create an object, you have to supply the date vector. You can change the date vector afterward but, at object creation time, you must provide a set of dates.

The final component of a financial time series object is one or more data series vectors. If you do not supply a name for the data series, the default name is series1. If you have multiple data series in an object and do not supply the names, the default is the name series followed by a number, for example, series1, series2, and series3.

Data Extraction

Here is an exercise on how to extract data from a financial time series object. As mentioned before, you can think of the object as a MATLAB structure. Highlight each line in the exercise in the MATLAB Help browser, press the right mouse button, and select Evaluate Selection to execute it.

To begin, create a financial time series object called myfts:

dates = (datenum('05/11/99'):datenum('05/11/99')+100)';
data_series1 = exp(randn(1, 101))';
data_series2 = exp(randn(1, 101))';
data = [data_series1 data_series2];
myfts = fints(dates, data);

The myfts object looks like this:

myfts = 

    desc:  (none)
    freq:  Unknown (0)

    'dates:  (101)'    'series1:  (101)'    'series2:  (101)'
    '11-May-1999'      [         2.8108]    [         0.9323]
    '12-May-1999'      [         0.2454]    [         0.5608]
    '13-May-1999'      [         0.3568]    [         1.5989]
    '14-May-1999'      [         0.5255]    [         3.6682]
    '15-May-1999'      [         1.1862]    [         5.1284]
    '16-May-1999'      [         3.8376]    [         0.4952]
    '17-May-1999'      [         6.9329]    [         2.2417]
    '18-May-1999'      [         2.0987]    [         0.3579]
    '19-May-1999'      [         2.2524]    [         3.6492]
    '20-May-1999'      [         0.8669]    [         1.0150]
    '21-May-1999'      [         0.9050]    [         1.2445]
    '22-May-1999'      [         0.4493]    [         5.5466]
    '23-May-1999'      [         1.6376]    [         0.1251]
    '24-May-1999'      [         3.4472]    [         1.1195]
    '25-May-1999'      [         3.6545]    [         0.3374]...

There are more dates in the object; only the first few lines are shown here.

    Note   The actual data in your series1 and series2 differs from the above because of the use of random numbers.

Now create another object with only the values for series2:

srs2 = myfts.series2
srs2 = 

    desc:  (none)
    freq:  Unknown (0)

    'dates:  (101)'    'series2:  (101)'
    '11-May-1999'      [         0.9323]
    '12-May-1999'      [         0.5608]
    '13-May-1999'      [         1.5989]
    '14-May-1999'      [         3.6682]
    '15-May-1999'      [         5.1284]
    '16-May-1999'      [         0.4952]
    '17-May-1999'      [         2.2417]
    '18-May-1999'      [         0.3579]
    '19-May-1999'      [         3.6492]
    '20-May-1999'      [         1.0150]
    '21-May-1999'      [         1.2445]
    '22-May-1999'      [         5.5466]
    '23-May-1999'      [         0.1251]
    '24-May-1999'      [         1.1195]
    '25-May-1999'      [         0.3374]...

The new object srs2 contains all the dates in myfts, but the only data series is series2. The name of the data series retains its name from the original object, myfts.

    Note   The output from referencing a data series field or indexing a financial time series object is always another financial time series object. The exceptions are referencing the description, frequency indicator, and dates fields, and indexing into the dates field.

Object-to-Matrix Conversion

The function fts2mat extracts the dates and/or the data series values from an object and places them into a vector or a matrix. The default behavior extracts just the values into a vector or a matrix. Look at the next example:

srs2_vec = fts2mat(myfts.series2)
srs2_vec =

    0.9323
    0.5608
    1.5989
    3.6682
    5.1284
    0.4952
    2.2417
    0.3579
    3.6492
    1.0150
    1.2445
    5.5466
    0.1251
    1.1195
    0.3374...

If you want to include the dates in the output matrix, provide a second input argument and set it to 1. This results in a matrix whose first column is a vector of serial date numbers:

format long g

srs2_mtx = fts2mat(myfts.series2, 1)
srs2_mtx =

            730251      0.932251754559576
            730252      0.560845677519876
            730253      1.59888712183914
            730254      3.6681500883527
            730255      5.12842215360269
            730256      0.49519254119977
            730257      2.24174134286213
            730258      0.357918065917634
            730259      3.64915665824198
            730260      1.01504236943148
            730261      1.24446420606078
            730262      5.54661849025711
            730263      0.12507959735904
            730264      1.11953883096805
            730265      0.337398214166607

The vector srs2_vec contains series2 values. The matrix srs2_mtx contains dates in the first column and the values of the series2 data series in the second. Dates in the first column are in serial date format. Serial date format is a representation of the date character vector format (for example, serial date = 1 is equivalent to 01-Jan-0000). (The serial date vector can include time-of-day information.)

The long g display format displays the numbers without exponentiation. (To revert to the default display format, use format short. (See the format command in the MATLAB documentation for a description of MATLAB display formats.) Remember that both the vector and the matrix have 101 rows of data as in the original object myfts but are shown truncated here.

See Also

| | | | | | | | | | | | | | | | | | | | |

Related Examples

Was this topic helpful?