Financial Time Series Toolbox    

Data Transformation and Frequency Conversion

The data transformation and the frequency conversion functions convert a data series into a different format.

Table 2-1: Data Transformation Functions 
Function
Purpose
boxcox
Box-Cox transformation
diff
Differencing
fillts
Fill missing values
filter
Filter
lagts
Lag time series object
leadts
Lead time series object
peravg
Periodic average
smoothts
Smooth data
tsmovavg
Moving average
Table 2-2: Frequency Conversion Functions 
Function
New Frequency
convertto
As specified
resamplets
As specified
toannual
Annual
todaily
Daily
tomonthly
Monthly
toquarterly
Quarterly
tosemi
Semiannually
toweekly
Weekly

As an example look at boxcox, the Box-Cox transformation function. This function transforms the data series contained in a financial time series object into another set of data series with relatively normal distributions.

First create a financial time series object from the supplied whirlpool.dat data file.

Fill any missing values denoted with NaNs in whrl with values calculated using the linear method:

Transform the nonnormally distributed filled data series f_whrl into a normally distributed one using Box-Cox transformation:

Compare the result of the Close data series with a normal (Gaussian) probability distribution function as well as the nonnormally distributed f_whrl:

Figure 2-1: Box-Cox Transformation

The bar chart on the top represents the probability distribution function of the filled data series, f_whrl, which is the original data series whrl with the missing values interpolated using the linear method. The distribution is skewed towards the left (not normally distributed). The bar chart on the bottom is less skewed to the left. If you plot a Gaussian probability distribution function (PDF) with similar mean and standard deviation, the distribution of the transformed data is very close to normal (Gaussian).

When you examine the contents of the resulting object bc_whrl, you find an identical object to the original object whrl but the contents are the transformed data series. If you have the Statistics Toolbox, you can generate a Gaussian PDF with mean and standard deviation equal to those of the transformed data series and plot it as an overlay to the second bar chart. In the next figure you can see that it is an approximately normal distribution.

Figure 2-2: Overlay of Gaussian PDF

The next example uses the smoothts function to smooth a time series.

To begin, transform ibm9599.dat, a supplied data file, into a financial time series object:

Fill the missing data for holidays with data interpolated using the fillts function and the Spline fill method:

Smooth the filled data series using the default Box (rectangular window) method:

Now, plot the original and smoothed closing price series for IBM:

Figure 2-3: Smoothed Data Series

These examples give you an idea of what you can do with a financial time series object. This toolbox provides some MATLAB functions that have been overloaded to work directly with the these objects. The overloaded functions are those most commonly needed to work with time series data.


  Operations Demonstration Program