Main Content

Convert Financial Time Series Objects弗林特to Timetables

In R2018a, financial time series (弗林特), and its associated methods have been replaced with a MATLAB®timetablefunction. If you use弗林特or the associated methods, you receive a warning. You can usefts2timetableto convert a弗林特object to atimetableobject. To help you convert from the older弗林特to the newertimetablefunctionality, use the following information.

Create Time Series

I/O Related Operations

Task Old Functionality New Functionality
Construct by passing in data and dates 弗林特(日期、数据datanames)

timetable(rowTimes,var1,...,varN,'VariableNames',{'a','b',...})

Construct by conversion of files ascii2fts(filename,descrow,colheadrow,skiprows)

T = readtable(filename,opts,Name,Value)

TT = table2timetable(T,'RowTimes',timeVarName)

Construct by using App with user interface Using the Financial Time Series app with user interface UsingImportDatafromHOMEtab
Write files fts2ascii(filename,tsobj,exttext) writetable(TT,filename)
Convert to matrix fts2mat(tsobj)

S = vartype('numeric');

TT2 = TT(:,S)

TT2.Variables

Index an Object

Indexing an Object

Task Old Functionality New Functionality
Indexing with a date myfts('05/11/99')

TT({'1999-05-11'},:)

Indexing with a date range myfts ('05/11/99::05/15/99')

S = timerange('1999-05-11','1999-05-15');

TT2 = TT(S,:)

Indexing with integers for rows

myfts.series2(1)

myfts.series2([1, 3, 5])

myfts.series2(16:20)

TT({'台series2 '})

TT([1, 3, 5],{'series2'})

TT(16:20,{'series2'})

Contents of a specific time field myfts.times timeofday(TT.Properties.RowTimes)
Contents for a specific field in a matrix fts2mat(myfts.series2)

TT.series2

Transform Time Series

Assume that all variables are numeric within a timetable, or the operations can be applied onTT2:

S = vartype('numeric');

TT2 = TT(:,S)

Filter Time Series

Task Old Functionality New Functionality
Boxcox transformation newfts = boxcox(oldfts)

TT.Variables = boxcox(TT.Variables)

Differencing diff(myfts)

TT{2:end,:} = diff(TT.Variables)

TT(1,:) = []

Indexing with integers for rows

fillts(oldfts,fill_method)

fillmissing(TT,method)

(Assumes no missing dates)

Linear filtering filter(B,A, myfts)

TT.Variables = filter(b,a,TT.Variables)

Lag or lead time series object

lagts(myfts,lagperiod)

leadts(myfts,leadperiod)

lag(TT,lagperiod)

lag(TT,-leadperiod)

(Assumes a regularly spaced timetable)

Periodic average peravg(myfts)

retime(TT,newTimes,'mean')

Downsample data resamplets(oldfts,samplestep)

retime(TT,newTimeStep,method)

Smooth data smoothts(input)

smoothdata(TT)

Moving average tsmovavg(tsobj,method,lag)

movavg(TT,type,windowSize)

Convert Time Series

Assume that all variables are numeric within a timetable, or the operations can be applied onTT2:

S = vartype('numeric');

TT2 = TT(:,S)

Conversion Operations

Task Old Functionality New Functionality
Convert to specified frequency convertto(oldfts,newfreq)

retime(TT,newTimeStep,method)

Convert to annual toannual(oldfts,...)

convert2annual(TT,…)

Convert to daily todaily(oldfts,...) convert2daily(TT,…)
Convert to monthly tomonthly(oldfts,...) convert2monthly(TT,…)
Convert to quarterly toquarterly(oldfts,...)

convert2quarterly(TT,…)

Convert to semiannual tosemi(oldfts,...)

convert2semiannual(TT,…)

Convert to weekly toweekly(oldfts,...)

convert2weekly(TT,…)

Merge Time Series

Merge Operations

Task Old Functionality New Functionality
Merge multiple time series objects merge(fts1,fts2)

[TT1;TT2](requires variable name to be the same)

unique(TT)

Concatenate financial time series objects horizontally horzcat(fts1,fts2)or[fts1,fts2]

horzcat[TT1,TT2](requires variable name to be the same) or

synchronize(TT1,TT2)

Concatenate financial time series objects vertically vertcat(fts1,fts2)or[fts1;fts2] vertcat[TT1;TT2]

Analyze Time Series

Due to flexibility of a timetable that can hold heterogeneous variables, a timetable does not support math operations or descriptive statistical calculations. If you would like to apply any numeric calculations on a timetable, use the following guidelines.

Assume that all variables are numeric within a timetable, or the operations can be applied onTT2:

S = vartype('numeric');

TT2 = TT(:,S)

Descriptive Statistics and Arithmetic and Math Operations

Task Old Functionality New Functionality
Extract out numerical data srs2 = myfts.series2

TT.Variables

Apply some options (statistics) For example:min,max,mean,median,cov,std, andvar

cov(TT.Variables)

Apply some options (operations) For example:sumandcumsum

TT.Variables = cumsum(TT.Variables)

Data Extraction

Refer totimetabledocumentation for data extraction methods and examples.

See Also

|||||||||||||||||||

Related Topics