Financial Time Series Toolbox    

Operations

Several MATLAB functions have been overloaded to work with financial time series objects. The overloaded functions include basic arithmetic functions such as addition, subtraction, multiplication, and division as well as other functions such as arithmetic average, filter, and difference. Also, specific methods have been designed to work with the financial time series object. For a list of functions grouped by type, refer to Functions - By Category or enter

at the MATLAB command prompt.

Basic Arithmetic

Financial time series objects permit you to do addition, subtraction, multiplication, and division, either on the entire object or on specific object fields. This is a feature that MATLAB structures do not allow. You cannot do arithmetic operations on entire MATLAB structures, only on specific fields of a structure.

You can perform arithmetic operations on two financial time series objects as long as they are compatible. (All contents are the same except for the description and the values associated with the data series.)

Here are some examples of arithmetic operations on financial time series objects.

Load a MAT-file that contains some sample financial time series objects:

One of the objects in dji30short is called myfts1:

Create another financial time series object that is identical to myfts1:

Perform an addition operation on both time series objects:

Now, perform a subtraction operation on both time series objects:

Operations with Objects and Matrices

You can also perform operations involving a financial time series object and a matrix or scalar:

For operations with both an object and a matrix, the size of the matrix must match the size of the object. For example, a matrix to be subtracted from myfts1 must be 20-by-4, since myfts1 has 20 dates and four data series:

Arithmetic Operations with Differing Data Series Names

Arithmetic operations on two objects that have the same size but contain different data series names require the function fts2mtx. This function extracts the values in an object and puts them into a matrix or vector, whichever is appropriate.

To see an example, create another financial time series object the same size as myfts1 but with different values and data series names:

If you attempt to add (or subtract, etc.) this new object to myfts1, an error indicates that the objects are not identical. Although they contain the same dates, number of dates, number of data series, and frequency, the two time series objects do not have the same data series names. Use fts2mtx to bypass this problem:

This operation adds the matrix that contains the contents of the data series in the object newfts2 to myfts1. You should carefully consider the effects on your data before deciding to combine financial time series objects in this manner.

Other Arithmetic Operations

In addition to the basic arithmetic operations, several other mathematical functions operate directly on financial time series objects. These functions include exponential (exp), natural logarithm (log), common logarithm (log10), and many more. See the Function Reference chapter for more details.


  Indexing a Financial Time Series Object Data Transformation and Frequency Conversion