matlab fillts,Fill missing values in time series

fillts

Fill missing values in time series

Syntax

newfts = fillts(oldfts,fill_method)

newfts = fillts(oldfts,fill_method,newdates)

newfts = fillts(oldfts,fill_method,newdates,{'T1','T2',...})

newfts = fillts(oldfts,fill_method,newdates,'SPAN',{'TS','TE'},delta)

newfts = fillts(... sortmode)

Arguments

oldftsFinancial time series object.

fill_method(Optional) Replaces missing values (NaN)

in oldfts using an interpolation process, a

constant, or a zero-order hold.

Valid fill methods

(interpolation methods) are:

linear - 'linear ' -

'l' (default)

linear with extrapolation -'linearExtrap' -

'le'

cubic -

'cubic' -

'c'

cubic with extrapolation -

'cubicExtrap' -

'ce'

spline -

'spline' -

's'

spline with extrapolation -

'splineExtrap'

-'se'

nearest -

'nearest' -

'n'

nearest with extrapolation -

'nearestExtrap'

-'ne'

pchip -

'pchip' -

'p'

pchip with extrapolation -

'pchipExtrap'

-'pe'

(See interp1 for a

discussion of extrapolation.)

To fill with a

constant, enter that constant.

A zero-order hold

('zero') fills a missing value with the

value immediately preceding it. If the first value in the time

series is missing, it remains a

NaN.

newdates(Optional) Column vector of serial dates, a date character

vector, or a column cell array of character vector dates. If

oldfts contains time of day information,

newdates must be accompanied by a time

vector (newtimes). Otherwise,

newdates is assumed to have times of

'00:00'.

T1, T2, TS, TEFirst time, second time, start time, end

time

deltaTime interval in minutes to span between the start time and

end time

sortmode(Optional) Default = 0 (unsorted).

1 = sorted.

Description

newfts = fillts(oldfts,fill_method)

replaces missing values (represented by NaN) in the financial time

series object oldfts with real values, using either a constant or the

interpolation process indicated by fill_method.

newfts =

fillts(oldfts,fill_method,newdates) replaces

all the missing values on the specified dates newdates added to the

financial time series oldfts with new values. The values can be a

single constant or values obtained through the interpolation process designated by

fill_method. If any of the dates in newdates

exists in oldfts, the existing one has precedence.

newfts = fillts(oldfts,fill_method,

newdates,{'T1','T2',...}) additionally allows the designation of specific

times of day for addition or replacement of data.

newfts =

fillts(oldfts,fill_method,newdates,'SPAN',{'TS','TE'},delta)

is similar to the previous format except that you designate only a start time and an end

time. You follow these times with a spanning time interval,

delta.

If you specify only one date for newdates, specifying a start and

end time generates only times for that specific date.

newfts = fillts(... sortmode) additionally denotes whether you want

the order of the dates in the output object to stay the same as in the input object or

to be sorted chronologically.

sortmode = 0 (unsorted) appends any new dates to the end. The

interpolation and zero-order processes that calculate the values for the new dates work

on a sorted object. Upon completion, the existing dates are reordered as they were

originally, and the new dates are appended to the end.

sortmode = 1 sorts the output. After interpolation, no reordering

of the date sequence occurs.

Examples

Example 1. Create a financial time series object with

missing data in the fourth and fifth rows.

dates = ['01-Jan-2001';'01-Jan-2001'; '02-Jan-2001';...

'02-Jan-2001'; '03-Jan-2001';'03-Jan-2001'];

times = ['11:00';'12:00';'11:00';'12:00';'11:00';'12:00'];

dates_times = cellstr([dates, repmat(' ',size(dates,1),1),...

times]);

OpenFts = fints(dates_times,[(1:3)'; nan; nan; 6],{'Data1'},1,...

'Open Financial Time Series')

OpenFts looks like this:

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)

OpenFts =

desc: Open Financial Time Series

freq: Daily (1)

'dates: (6)' 'times: (6)' 'Data1: (6)'

'01-Jan-2001' '11:00' [ 1]

' " ' '12:00' [ 2]

'02-Jan-2001' '11:00' [ 3]

' " ' '12:00' [ NaN]

'03-Jan-2001' '11:00' [ NaN]

' " ' '12:00' [ 6]

Example 2. Fill the missing data in

OpenFts using cubic interpolation.

FilledFts = fillts(OpenFts,'cubic')

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/fillts (line 213)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/display (line 66)

FilledFts =

desc: Filled Open Financial Time Series

freq: Unknown (0)

'dates: (6)' 'times: (6)' 'Data1: (6)'

'01-Jan-2001' '11:00' [ 1]

' " ' '12:00' [ 2]

'02-Jan-2001' '11:00' [ 3]

' " ' '12:00' [ 3.0663]

'03-Jan-2001' '11:00' [ 5.8411]

' " ' '12:00' [ 6.0000]

Example 3. Fill the missing data in

OpenFts with a constant value.

FilledFts = fillts(OpenFts,0.3)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/fillts (line 213)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/display (line 66)

FilledFts =

desc: Filled Open Financial Time Series

freq: Unknown (0)

'dates: (6)' 'times: (6)' 'Data1: (6)'

'01-Jan-2001' '11:00' [ 1]

' " ' '12:00' [ 2]

'02-Jan-2001' '11:00' [ 3]

' " ' '12:00' [ 0.3000]

'03-Jan-2001' '11:00' [ 0.3000]

' " ' '12:00' [ 6]

Example 4. You can use fillts to

identify a specific time on a specific day for the replacement of missing data. This

example shows how to replace missing data at 12:00 on January 2 and 11:00 on January

3.

FilltimeFts = fillts(OpenFts,'c',...

{'02-Jan-2001';'03-Jan-2001'}, {'12:00';'11:00'},0)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/fillts (line 213)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/display (line 66)

FilltimeFts =

desc: Filled Open Financial Time Series

freq: Unknown (0)

'dates: (6)' 'times: (6)' 'Data1: (6)'

'01-Jan-2001' '11:00' [ 1]

' " ' '12:00' [ 2]

'02-Jan-2001' '11:00' [ 3]

' " ' '12:00' [ 3.0663]

'03-Jan-2001' '11:00' [ 5.8411]

' " ' '12:00' [ 6.0000]

Example 5. Use a spanning time interval to add an

additional day to OpenFts.

SpanFts = fillts(OpenFts,'c','04-Jan-2001','span',...

{'11:00';'12:00'},60,0)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/fillts (line 213)

Warning: FINTS will be removed in a future release. Use TIMETABLE instead.

> In fints/display (line 66)

SpanFts =

desc: Filled Open Financial Time Series

freq: Unknown (0)

'dates: (8)' 'times: (8)' 'Data1: (8)'

'01-Jan-2001' '11:00' [ 1]

' " ' '12:00' [ 2]

'02-Jan-2001' '11:00' [ 3]

' " ' '12:00' [ 3.0663]

'03-Jan-2001' '11:00' [ 5.8411]

' " ' '12:00' [ 6.0000]

'04-Jan-2001' '11:00' [ 9.8404]

' " ' '12:00' [ 9.9994]

Introduced before R2006a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值