Financial Time Series Toolbox    

Using the Constructor

The object constructor function fints has five different syntaxes. These forms exist to simplify object construction. The syntaxes vary according to the types of input arguments presented to the constructor. The syntaxes are

Single Matrix Input

The date information provided with this syntax must be in serial date number format. The date number may or may not include time-of-day information.

Time-of-Day Information Excluded.   

In this simplest form of syntax, the input must be at least a two-column matrix. The first column contains the dates in serial date format; the second column is the data series. The input matrix can have more than two columns, each additional column representing a different data series or set of observations.

If the input is a two-column matrix, the output object contains four fields: desc, freq, dates, and series1. The description field, desc, defaults to blanks '', and the frequency indicator field, freq, defaults to 0. The dates field, dates, contains the serial dates from the first column of the input matrix, while the data series field, series1, has the data from the second column of the input matrix.

The first example makes two financial time series objects. The first one has only one data series, while the other has more than one. A random vector provides the values for the data series. The range of dates is arbitrarily chosen using the today function:

Examine the contents of the object fts1 just created. The actual date series you observe will vary according to the day when you run the example (the value of today). Also, your values in series1 will differ from those shown, depending upon the sequence of random numbers generated:

The output is truncated for brevity. There are actually 101 data points in the object.

Note that the desc field displays as (none) instead of '', and that the contents of the object display as cell array elements. Although the object displays as such, it should be thought of as a MATLAB structure containing the default field names for a single data series object: desc, freq, dates, and series1.

Now create an object with more than one data series in it:

Now look at the object created (again in abbreviated form):

The second data series name defaults to series2, as expected.

Before you can perform any operations on the object, you must set the frequency indicator field freq to the valid frequency of the data series contained in the object. You may leave the description field desc blank.

To set the frequency indicator field to a daily frequency, enter

fts2.freq = 1, or

fts2.freq = 'daily'

See the fints function description in the Function Reference for a list of frequency indicators.

Time-of-Day Information Included.   

The serial date number used with this form of the fints function can incorporate time-of-day information. When time-of-day information is present, the output of the function contains a field times that indicates the time of day.

If you recode a previous example to include time-of-day information, you can see the additional column present in the output object:

Separate Vector Input

The date information provided with this syntax may be in serial date number or date string format. The date information may or may not include time-of-day information.

Time-of-Day Information Excluded.   

In this second syntax the dates and data series are entered as separate vectors to fints, the financial time series object constructor function. The dates vector must be a column vector, while the data series data can be a column vector (if there is only one data series) or a column-oriented matrix (for multiple data series). A column-oriented matrix, in this context, indicates that each column is a set of observations. Different columns are different sets of data series.

Here is an example:

The result is exactly the same as the first syntax. The only difference between the first and second syntax is the way the inputs are entered into the constructor function.

Time-of-Day Information Included.   

With this form of the function you can enter the time-of-day information either as a serial date number or as a date string. If more than one serial date and time is present, the entry must be in the form of a column-oriented matrix. If more than one string date and time is present, the entry must be a column-oriented cell array of dates and times.

With date string input the dates and times can initially be separate column-oriented date and time series, but you must concatenate them into a single column-oriented cell array before entering them as the first input to fints.

For date string input the allowable formats are:

The next example shows time-of-day information input as serial date numbers in a column-oriented matrix:

If the time-of-day information is in date string format, you must provide it to fints as a column-oriented cell array:

If the dates and times are in date string format and contained in separate matrices, you must concatenate them before using the date and time information as input to fints:

Data Name Input

The third syntax lets you specify the names for the data series with the argument datanames. The datanames argument may be a MATLAB string for a single data series. For multiple data series names, it must be a cell array of string(s).

Look at two examples, one with a single data series and a second with two. The first example sets the data series name to the specified name First:

The second example provides two data series named First and Second:

Because freq for fts2 has not been explicitly indicated, the frequency indicator for fts2 is set to Unknown. Set the frequency indicator field freq before you attempt any operations on the object. You will not be able to use the object until the frequency indicator field is set to a valid indicator.

Frequency Indicator Input

With the fourth syntax you can set the frequency indicator field when you create the financial time series object. The frequency indicator field freq is set as the fourth input argument. You will not be able to use the financial time series object until freq is set to a valid indicator. Valid frequency indicators are

The previous example contained sets of daily data. The freq field displayed as Unknown (0) because the frequency indicator was not explicitly set. The command

sets the freq indicator to Daily(1) when creating the financial time series object:

When you create the object using this syntax, you can use the other valid frequency indicators for a particular frequency. For a daily data set you can use DAILY, Daily, daily, D, or d. Similarly, with the other frequencies, you can use the valid string indicators or their numeric counterparts.

Description Field Input

With the fifth syntax you can explicitly set the description field as the fifth input argument. The description can be anything you want. It is not used in any operations performed on the object.

This example sets the desc field to 'Test TS'.

Now the description field is filled with the specified string 'Test TS' when the constructor is called.


  Creating Financial Time Series Objects Transforming a Text File