subsref
Subscripted reference
subsref
is not recommended. Use timetable
instead. For more information, see Convert Financial Time Series Objects fints to Timetables.
Syntax
subref
Description
subsref
implements indexing for a financial time series object.
Integer indexing or date (and time) character vector indexing is allowed.
Serial date numbers cannot be used as indices.
To use date character vector indexing, enclose the date character vector(s) in a pair
of single quotation marks ''
.
You can use integer indexing on the object as in any other MATLAB® matrix. It returns the appropriate entry(ies) from the object.
Additionally, subsref
lets you access the individual components of
the object using the structure syntax.
Examples
Create a time series named myfts
:
myfts = fints((datenum('07/01/98'):datenum('07/01/98')+4)',... [1234.56; 2345.61; 3456.12; 4561.23; 5612.34], [], 'Daily',... 'Data Reference')
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) myfts = desc: Data Reference freq: Daily (1) 'dates: (5)' 'series1: (5)' '01-Jul-1998' [ 1.2346e+03] '02-Jul-1998' [ 2.3456e+03] '03-Jul-1998' [ 3.4561e+03] '04-Jul-1998' [ 4.5612e+03] '05-Jul-1998' [ 5.6123e+03]
Extract the data for the single day July 1, 1998:
myfts('07/01/98')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Data Reference freq: Daily (1) 'dates: (1)' 'series1: (1)' '01-Jul-1998' [ 1.2346e+03]
Now, extract the data for the range of dates July 1, 1998, through July 5, 1998:
myfts('07/01/98::07/03/98')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Data Reference freq: Daily (1) 'dates: (3)' 'series1: (3)' '01-Jul-1998' [ 1.2346e+03] '02-Jul-1998' [ 2.3456e+03] '03-Jul-1998' [ 3.4561e+03]
You can use the MATLAB structure syntax to access the individual components of a financial time
series object. To get the description field of myfts
, enter
myfts.desc
at the command line, which returns
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) ans = 'Data Reference'
Similarly
myfts.series1
returns
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Data Reference freq: Daily (1) 'dates: (5)' 'series1: (5)' '01-Jul-1998' [ 1.2346e+03] '02-Jul-1998' [ 2.3456e+03] '03-Jul-1998' [ 3.4561e+03] '04-Jul-1998' [ 4.5612e+03] '05-Jul-1998' [ 5.6123e+03]
The syntax for integer indexing is the same as for any other MATLAB matrix. Create a new financial time series object containing both dates and times:
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]); anewfts = fints(dates_times,(1:6)',{'Data1'},1,'Another FinTs')
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) anewfts = desc: Another FinTs 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' [ 4] '03-Jan-2001' '11:00' [ 5] ' " ' '12:00' [ 6]
Use integer indexing to extract the second and third data items from the object.
anewfts(2:3)
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Another FinTs freq: Daily (1) 'dates: (2)' 'times: (2)' 'Data1: (2)' '01-Jan-2001' '12:00' [ 2] '02-Jan-2001' '11:00' [ 3]
For date character vector, enclose the indexing character vector in a pair of single quotation marks.
If there is one date with multiple times, indexing with only the date returns all the times for that specific date:
anewfts('01-Jan-2001')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Another FinTs freq: Daily (1) 'dates: (2)' 'times: (2)' 'Data1: (2)' '01-Jan-2001' '11:00' [ 1] ' " ' '12:00' [ 2]
To specify one specific date and time, index with that date and time:
anewfts('01-Jan-2001 12:00')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Another FinTs freq: Daily (1) 'dates: (1)' 'times: (1)' 'Data1: (1)' '01-Jan-2001' '12:00' [ 2]
To specify a range of dates and times, use the double colon (::
)
operator:
anewfts('01-Jan-2001 12:00::03-Jan-2001 11:00')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Another FinTs freq: Daily (1) 'dates: (4)' 'times: (4)' 'Data1: (4)' '01-Jan-2001' '12:00' [ 2] '02-Jan-2001' '11:00' [ 3] ' " ' '12:00' [ 4] '03-Jan-2001' '11:00' [ 5]
To request all the dates, times, and data, use the ::
operator
without specifying any specific date or time:
anewfts('::')
Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/subsref (line 106) Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) ans = desc: Another FinTs 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' [ 4] '03-Jan-2001' '11:00' [ 5] ' " ' '12:00' [ 6]