fillts
Fill missing values in time series
fillts
is not recommended. Use timetable
instead. For more information, see Convert Financial Time Series Objects fints to Timetables.
Syntax
Description
replaces missing values (represented by newfts
= fillts(oldfts
,fillmethod
)NaN
) in the financial
time series object oldfts
with real values, using either a
constant or the interpolation process indicated by fillmethod
.
replaces all the missing values on the specified dates newfts
= fillts(oldfts
,fillmethod
,newdates
)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 fillmethod
. If any of the dates in
newdates
exists in oldfts
, the
existing one has precedence.
additionally allows the designation of specific times of day for addition or
replacement of data. newfts
= fillts(oldfts
,fillmethod
,newdates
,newtimes
)
Examples
Fill Missing Values in Time Series for Financial Time Series Object
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 is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints (line 169) 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]}
Fill the missing data in
OpenFts
using cubic interpolation.FilledFts = fillts(OpenFts,'cubic')
Warning: FINTS is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints/fillts (line 217) 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]}
Fill Missing Values for Specific Time for Time Series for Financial Time Series Object
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 is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints (line 169) 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]}
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 is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints/fillts (line 217) 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]}
Spanning time interval to Fill Time Series for Financial Time Series Object
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 is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints (line 169) 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]}
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 is not recommended. Use TIMETABLE instead. For more information, see Convert Financial Time Series Objects (fints) to Timetables. > In fints/fillts (line 217) 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]} {'04-Jan-2001'} {'11:00' } {[ 9.8404]} {' " '} {'12:00' } {[ 9.9994]}
Input Arguments
oldfts
— Financial time series object
fints
object
Financial time series object, specified as a fints
object.
Data Types: object
fillmethod
— Valid fill methods
'linear'
(default) | character vector
Valid fill methods (interpolation methods), specified as a character vector.
'linear'
— linear'linearExtrap'
— linear with extrapolation'cubic'
— cubic'cubicExtrap'
— cubic with extrapolation'spline'
— spline'splineExtrap'
— spline with extrapolation'nearest'
— nearest'nearestExtrap'
— nearest with extrapolation'pchip'
— pchip'pchipExtrap'
— pchip with extrapolation
(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
.
Data Types: char
newdates
— Dates
column vector | date character vector | cell array of date character vectors
Dates, specified as a column vector of serial date numbers, a date
character vector, or a column cell array of date character vector. 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'
.
If you specify only one date for newdates
, specifying a
start and end time generates only times for that specific date.
Data Types: double
| cell
| char
newtimes
— Times
date character vector | cell array of date character vectors
Times, specified as a date character vector or a column cell array of date
character vector. 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'
.
If you specify only one date for newdates
, specifying a
start and end time generates only times for that specific date.
Data Types: char
| cell
delta
— Time interval in minutes
positive integer
Time interval in minutes, specified as a positive integer.
delta
is the span between the start time and end
time.
Data Types: double
sortmode
— Sort mode
0
(unsorted) (default) | integer with value 0
or 1
Sort mode, specified as a an integer where 0
is
unsorted and 1
is sorted.
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.1
— Sorts the output. After interpolation, no reordering of the date sequence occurs.
Data Types: double
Output Arguments
newfts
— Financial time series object
fints
object
Financial time series object, specified as a fints
object.
Data Types: object
Version History
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)