| Financial Time Series | ![]() |
Using the Constructor
The object constructor function fints has five different syntaxes. These forms exist to simplify object construction. The syntaxes are:
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.
date_series = (today:today+100)'; data_series = exp(randn(1, 101))'; dates_and_data = [date_series data_series]; fts1 = fints(dates_and_data);
Display the contents of the object fts1 just created. The actual dates 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.
fts1 = desc: (none) freq: Unknown (0) 'dates: (101)' 'series1: (101)' '12-Jul-1999' [ 0.3124] '13-Jul-1999' [ 3.2665] '14-Jul-1999' [ 0.9847] '15-Jul-1999' [ 1.7095] '16-Jul-1999' [ 0.4885] '17-Jul-1999' [ 0.5192] '18-Jul-1999' [ 1.3694] '19-Jul-1999' [ 1.1127] '20-Jul-1999' [ 6.3485] '21-Jul-1999' [ 0.7595] '22-Jul-1999' [ 9.1390] '23-Jul-1999' [ 4.5201] '24-Jul-1999' [ 0.1430] '25-Jul-1999' [ 0.1863] '26-Jul-1999' [ 0.5635] '27-Jul-1999' [ 0.8304] '28-Jul-1999' [ 1.0090]...
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.
date_series = (today:today+100)'; data_series1 = exp(randn(1, 101))'; data_series2 = exp(randn(1, 101))'; dates_and_data = [date_series data_series1 data_series2]; fts2 = fints(dates_and_data);
Now look at the object created (again in abbreviated form).
fts2 = desc: (none) freq: Unknown (0) 'dates: (101)' 'series1: (101)' 'series2: (101)' '12-Jul-1999' [ 0.5816] [ 1.2816] '13-Jul-1999' [ 5.1253] [ 0.9262] '14-Jul-1999' [ 2.2824] [ 5.6869] '15-Jul-1999' [ 1.2596] [ 5.0631] '16-Jul-1999' [ 1.9574] [ 1.8709] '17-Jul-1999' [ 0.6017] [ 1.0962] '18-Jul-1999' [ 2.3546] [ 0.4459] '19-Jul-1999' [ 1.3080] [ 0.6304] '20-Jul-1999' [ 1.8682] [ 0.2451] '21-Jul-1999' [ 0.3509] [ 0.6876] '22-Jul-1999' [ 4.6444] [ 0.6244] '23-Jul-1999' [ 1.5441] [ 5.7621] '24-Jul-1999' [ 0.1470] [ 2.1238] '25-Jul-1999' [ 1.5999] [ 1.0671] '26-Jul-1999' [ 3.5764] [ 0.7462] '27-Jul-1999' [ 1.8937] [ 1.0863] '28-Jul-1999' [ 3.9780] [ 2.1516]...
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
See the fints function description in the Function Reference for a list of frequency indicators.
In the 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.
dates = (today:today+100)'; data_series1 = exp(randn(1, 101))'; data_series2 = exp(randn(1, 101))'; data = [data_series1 data_series2]; fts = fints(dates, data) fts = desc: (none) freq: Unknown (0) 'dates: (101)' 'series1: (101)' 'series2: (101)' '12-Jul-1999' [ 0.5816] [ 1.2816] '13-Jul-1999' [ 5.1253] [ 0.9262] '14-Jul-1999' [ 2.2824] [ 5.6869] '15-Jul-1999' [ 1.2596] [ 5.0631] '16-Jul-1999' [ 1.9574] [ 1.8709] '17-Jul-1999' [ 0.6017] [ 1.0962] '18-Jul-1999' [ 2.3546] [ 0.4459] '19-Jul-1999' [ 1.3080] [ 0.6304] '20-Jul-1999' [ 1.8682] [ 0.2451] '21-Jul-1999' [ 0.3509] [ 0.6876] '22-Jul-1999' [ 4.6444] [ 0.6244] '23-Jul-1999' [ 1.5441] [ 5.7621] '24-Jul-1999' [ 0.1470] [ 2.1238] '25-Jul-1999' [ 1.5999] [ 1.0671] '26-Jul-1999' [ 3.5764] [ 0.7462] '27-Jul-1999' [ 1.8937] [ 1.0863] '28-Jul-1999' [ 3.9780] [ 2.1516]...
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.
The third syntax lets you specify the names for the data series with the argument datanames. datanames 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.
dates = (today:today+100)'; data = exp(randn(1, 101))'; fts1 = fints(dates, data, 'First') fts1 = desc: (none) freq: Unknown (0) 'dates: (101)' 'First: (101)' '12-Jul-1999' [ 0.4615] '13-Jul-1999' [ 1.1640] '14-Jul-1999' [ 0.7140] '15-Jul-1999' [ 2.6400] '16-Jul-1999' [ 0.8983] '17-Jul-1999' [ 2.7552] '18-Jul-1999' [ 0.6217] '19-Jul-1999' [ 1.0714] '20-Jul-1999' [ 1.4897] '21-Jul-1999' [ 3.0536] '22-Jul-1999' [ 1.8598] '23-Jul-1999' [ 0.7500] '24-Jul-1999' [ 0.2537] '25-Jul-1999' [ 0.5037] '26-Jul-1999' [ 1.3933] '27-Jul-1999' [ 0.3687]...
The second example provides two data series named First and Second.
dates = (today:today+100)';
data_series1 = exp(randn(1, 101))';
data_series2 = exp(randn(1, 101))';
data = [data_series1 data_series2];
fts2 = fints(dates, data, {'First', 'Second'})
fts2 =
desc: (none)
freq: Unknown (0)
'dates: (101)' 'First: (101)' 'Second: (101)'
'12-Jul-1999' [ 1.2305] [ 0.7396]
'13-Jul-1999' [ 1.2473] [ 2.6038]
'14-Jul-1999' [ 0.3657] [ 0.5866]
'15-Jul-1999' [ 0.6357] [ 0.4061]
'16-Jul-1999' [ 4.0530] [ 0.4096]
'17-Jul-1999' [ 0.6300] [ 1.3214]
'18-Jul-1999' [ 1.0333] [ 0.4744]
'19-Jul-1999' [ 2.2228] [ 4.9702]
'20-Jul-1999' [ 2.4518] [ 1.7758]
'21-Jul-1999' [ 1.1479] [ 1.3780]
'22-Jul-1999' [ 0.1981] [ 0.8595]
'23-Jul-1999' [ 0.1927] [ 1.3713]
'24-Jul-1999' [ 1.5353] [ 3.8332]
'25-Jul-1999' [ 0.4784] [ 0.1067]
'26-Jul-1999' [ 1.7593] [ 3.6434]
'27-Jul-1999' [ 0.2505] [ 0.6849]
'28-Jul-1999' [ 1.5845] [ 1.0025]...
Note
Data series names must be valid MATLAB variable names. The only allowed nonalphanumeric character is the underscore (_) character. |
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.
With this 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
UNKNOWN,Unknown,unknown,U,u,0DAILY,Daily,daily,D,d,1WEEKLY,Weekly,weekly,W,w,2MONTHLY,Monthly,monthly,M,m,3QUARTERLY,Quarterly,quarterly,Q,q,4SEMIANNUAL,Semiannual,semiannual,S,s,5ANNUAL,Annual, annual,A,a,6
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
fts = fints(dates, data, {'First', 'Second'}, 1);
sets the freq indicator to Daily(1) when creating the financial time series object.
fts = desc: (none) freq: Daily (1) 'dates: (101)' 'First: (101)' 'Second: (101)' '12-Jul-1999' [ 1.2305] [ 0.7396] '13-Jul-1999' [ 1.2473] [ 2.6038] '14-Jul-1999' [ 0.3657] [ 0.5866] '15-Jul-1999' [ 0.6357] [ 0.4061] '16-Jul-1999' [ 4.0530] [ 0.4096] '17-Jul-1999' [ 0.6300] [ 1.3214] '18-Jul-1999' [ 1.0333] [ 0.4744]...
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.
With this 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'.
dates = (today:today+100)';
data_series1 = exp(randn(1, 101))';
data_series2 = exp(randn(1, 101))';
data = [data_series1 data_series2];
fts = fints(dates, data, {'First', 'Second'}, 1, 'Test TS')
fts =
desc: Test TS
freq: Daily (1)
'dates: (101)' 'First: (101)' 'Second: (101)'
'12-Jul-1999' [ 0.5428] [ 1.2491]
'13-Jul-1999' [ 0.6649] [ 6.4969]
'14-Jul-1999' [ 0.2428] [ 1.1163]
'15-Jul-1999' [ 1.2550] [ 0.6628]
'16-Jul-1999' [ 1.2312] [ 1.6674]
'17-Jul-1999' [ 0.4869] [ 0.3015]
'18-Jul-1999' [ 2.1335] [ 0.9081]...
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 | ![]() |