[transdat,lambda] = boxcox(data) [transfts,lambda] = boxcox(tsobj) transdat = boxcox(lambda,data) transfts = boxcox(lambda,tsobj)
Data vector. Must be positive and specified as a column data vector.
Financial time series object.
boxcox transforms nonnormally distributed
data to a set of data that has approximately normal distribution.
The Box-Cox transformation is a family of power transformations.
If λ is not =
If λ is =
The logarithm is the natural logarithm (log base e). The algorithm
calls for finding the λ value that maximizes the Log-Likelihood
Function (LLF). The search is conducted using
[transdat,lambda] = boxcox(data) transforms
the data vector
data using the Box-Cox transformation
transdat. It also estimates the transformation
[transfts,lambda] = boxcox(tsojb) transforms
the financial time series object
tsobj using the
Box-Cox transformation method into
also estimates the transformation parameter λ.
If the input data is a vector,
a scalar. If the input is a financial time series object,
a structure with fields similar to the components of the object; for
example, if the object contains series names
transdat = boxcox(lambda, data) and
= boxcox(lambda, tsobj) transform the data using a certain
specified λ for the Box-Cox transformation. This syntax does
not find the optimum λ that maximizes the LLF.
boxcox to transform the data series contained in a financial time series object into another set of data series with relatively normal distributions.
Create a financial time series object from the supplied
whirlpool.dat data file.
whrl = ascii2fts('whirlpool.dat', 1, 2, );
Fill any missing values denoted with
NaN's in whrl with values calculated using the linear method.
f_whrl = fillts(whrl);
Transform the nonnormally distributed filled data series
f_whrl into a normally distributed one using Box-Cox transformation.
bc_whrl = boxcox(f_whrl);
Compare the result of the
Close data series with a normal (Gaussian) probability distribution function and the nonnormally distributed
subplot(2, 1, 1); hist(f_whrl.Close); grid; title('Nonnormally Distributed Data'); subplot(2, 1, 2); hist(bc_whrl.Close); grid; title('Box-Cox Transformed Data');
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 toward 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.