## Financial Time Series 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 and 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, enter

```help ftseries ```

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.)

Note

Compatible time series are not the same as equal time series. Two time series objects are equal when everything but the description fields are the same.

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

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

```load dji30short ```

One of the objects in `dji30short` is called `myfts1`:

```myfts1 = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 3830.90] [ 3868.04] [ 3800.50] [ 3832.30] '07-Mar-1994' [ 3851.72] [ 3882.40] [ 3824.71] [ 3856.22] '08-Mar-1994' [ 3858.48] [ 3881.55] [ 3822.45] [ 3851.72] '09-Mar-1994' [ 3853.97] [ 3874.52] [ 3817.95] [ 3853.41] '10-Mar-1994' [ 3852.57] [ 3865.51] [ 3801.63] [ 3830.62]... ```

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

```newfts = fints(myfts1.dates, fts2mat(myfts1)/100,... {'Open','High','Low', 'Close'}, 1, 'New FTS')```
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/fts2mat (line 29) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints (line 165) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) newfts = desc: New FTS freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close:(20)' '04-Mar-1994' [ 38.31] [ 38.68] [ 38.01] [ 38.32] '07-Mar-1994' [ 38.52] [ 38.82] [ 38.25] [ 38.56] '08-Mar-1994' [ 38.58] [ 38.82] [ 38.22] [ 38.52] '09-Mar-1994' [ 38.54] [ 38.75] [ 38.18] [ 38.53] '10-Mar-1994' [ 38.53] [ 38.66] [ 38.02] [ 38.31]... ```

Perform an addition operation on both time series objects:

`addup = myfts1 + newfts`
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In + (line 22) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) addup = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 3869.21] [ 3906.72] [ 3838.51] [ 3870.62] '07-Mar-1994' [ 3890.24] [ 3921.22] [ 3862.96] [ 3894.78] '08-Mar-1994' [ 3897.06] [ 3920.37] [ 3860.67] [ 3890.24] '09-Mar-1994' [ 3892.51] [ 3913.27] [ 3856.13] [ 3891.94] '10-Mar-1994' [ 3891.10] [ 3904.17] [ 3839.65] [ 3868.93]... ```

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

`subout = myfts1 - newfts`
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In - (line 23) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) subout = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 3792.59] [ 3829.36] [ 3762.49] [ 3793.98] '07-Mar-1994' [ 3813.20] [ 3843.58] [ 3786.46] [ 3817.66] '08-Mar-1994' [ 3819.90] [ 3842.73] [ 3784.23] [ 3813.20] '09-Mar-1994' [ 3815.43] [ 3835.77] [ 3779.77] [ 3814.88] '10-Mar-1994' [ 3814.04] [ 3826.85] [ 3763.61] [ 3792.31]... ```

### Operations with Objects and Matrices

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

`addscalar = myfts1 + 10000`
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In + (line 22) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) addscalar = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 13830.90] [ 13868.04] [ 13800.50] [ 13832.30] '07-Mar-1994' [ 13851.72] [ 13882.40] [ 13824.71] [ 13856.22] '08-Mar-1994' [ 13858.48] [ 13881.55] [ 13822.45] [ 13851.72] '09-Mar-1994' [ 13853.97] [ 13874.52] [ 13817.95] [ 13853.41] '10-Mar-1994' [ 13852.57] [ 13865.51] [ 13801.63] [ 13862.70]... ```

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 4 data series:

`submtx = myfts1 - randn(20, 4)`
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In - (line 23) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) submtx = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 3831.33] [ 3867.75] [ 3802.10] [ 3832.63] '07-Mar-1994' [ 3853.39] [ 3883.74] [ 3824.45] [ 3857.06] '08-Mar-1994' [ 3858.35] [ 3880.84] [ 3823.51] [ 3851.22] '09-Mar-1994' [ 3853.68] [ 3872.90] [ 3816.53] [ 3851.92] '10-Mar-1994' [ 3853.72] [ 3866.20] [ 3802.44] [ 3831.17]...```

### 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 `fts2mat`. 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:

```newfts2 = fints(myfts1.dates, fts2mat(myfts1/10000),... {'Rat1','Rat2', 'Rat3','Rat4'}, 1, 'New FTS') ```
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In / (line 25) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/fts2mat (line 29) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints (line 165) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) newfts2 = desc: New FTS freq: Daily (1) 'dates: (20)' 'Rat1: (20)' 'Rat2: (20)' 'Rat3: (20)' 'Rat4: (20)' '04-Mar-1994' [ 0.38] [ 0.39] [ 0.38] [ 0.38] '07-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '08-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '09-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '10-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.38] '11-Mar-1994' [ 0.38] [ 0.39] [ 0.38] [ 0.39] '14-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '15-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.38] '16-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.38] '17-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '18-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '21-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '22-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '23-Mar-1994' [ 0.39] [ 0.39] [ 0.38] [ 0.39] '24-Mar-1994' [ 0.38] [ 0.39] [ 0.38] [ 0.38]...```

If you attempt to add (or subtract, and so on) 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 `fts2mat` to bypass this problem:

```addother = myfts1 + fts2mat(newfts2) ```
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/fts2mat (line 29) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In + (line 22) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) addother = desc: DJI30MAR94.dat freq: Daily (1) 'dates: (20)' 'Open: (20)' 'High: (20)' 'Low: (20)' 'Close: (20)' '04-Mar-1994' [ 3831.28] [ 3868.43] [ 3800.88] [ 3832.68] '07-Mar-1994' [ 3852.11] [ 3882.79] [ 3825.09] [ 3856.61] '08-Mar-1994' [ 3858.87] [ 3881.94] [ 3822.83] [ 3852.11] '09-Mar-1994' [ 3854.36] [ 3874.91] [ 3818.33] [ 3853.80] '10-Mar-1994' [ 3852.96] [ 3865.90] [ 3802.01] [ 3831.00] '11-Mar-1994' [ 3832.96] [ 3873.22] [ 3807.07] [ 3863.09] '14-Mar-1994' [ 3870.68] [ 3894.60] [ 3836.34] [ 3863.37] '15-Mar-1994' [ 3863.80] [ 3888.85] [ 3827.23] [ 3849.97] '16-Mar-1994' [ 3851.42] [ 3879.92] [ 3820.32] [ 3848.53] '17-Mar-1994' [ 3854.01] [ 3891.73] [ 3822.04] [ 3865.53] '18-Mar-1994' [ 3865.81] [ 3912.17] [ 3839.03] [ 3896.04] '21-Mar-1994' [ 3878.77] [ 3898.64] [ 3839.03] [ 3865.24] '22-Mar-1994' [ 3866.10] [ 3896.62] [ 3841.04] [ 3862.94]...```

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.