Documentation |
Periodic average of FINTS object
avgfts = peravg(tsobj) avgfts = peravg(tsobj, numperiod) avgfts = peravg(tsobj, daterange)
tsobj | Financial time series object |
numperiod | (Optional) Integer specifying the number of data points over which each periodic average should be averaged |
daterange | (Optional) Time period over which the data is averaged |
peravg calculates periodic averages of a financial time series object. Periodic averages are calculated from the values per period defined. If the period supplied is a string, it is assumed as a range of date string. If the period is entered as numeric, the number represents the number of data points (financial time series periods) to be included in a period for the calculation. For example, if you enter '01/01/98::01/01/99' as the period input argument, peravg returns the average of the time series between those dates, inclusive. However, if you enter the number 5 as the period input, peravg returns a series of averages from the time series data taken 5 date points (financial time series periods) at a time.
avgfts = peravg(tsobj, numperiod) returns a structure avgfts that contains the periodic (per numperiod periods) average of the financial time series object. avgfts has field names identical to the data series names of tsobj.
avgfts = peravg(tsobj, daterange) returns a structure avgfts that contains the periodic (as specified by daterange) average of the financial time series object. avgfts has field names identical to the data series names of tsobj.
Note: peravg calculates periodic averages of a FINTS object. Periodic averages are calculated from the values per period defined. If the period supplied is a string, it is assumed as a range of date strings. If the period is entered as numeric, the number represents the number of data points to be included in a period for the calculation. |
If you enter 01-Jan-2001::03-Jan-2001 as the period input argument, peravg returns the average of the time series between those dates, inclusive. However, if you enter the number 5 as the period input, peravg returns a series of averages from the time series data, taken 5 date points at a time.
%% Create the FINTS object %% 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]); data = [(1:6)', 2*(1:6)']; myFts = fints(dates_times, data, {'Data1', 'Data2'}, 1, 'My first FINTS') %% Create the FINTS object %% [p, pFts] = peravg(myFts, 3)
p = Data1: [2 5] Data2: [4 10] pFts = desc: My first FINTS freq: Daily (1) 'dates: (2)' 'times: (2)' 'Data1: (2)' 'Data2: (2)' '02-Jan-2001' '11:00' [ 2] [ 4] '03-Jan-2001' '12:00' [ 5] [ 10]
[p, pFts] = peravg(myFts,'01-Jan-2001 12:00::03-Jan-2001 11:00')
p = Data1: 3.5000 Data2: 7 pFts = desc: My first FINTS freq: Daily (1) 'dates: (1)' 'times: (1)' 'Data1: (1)' 'Data2: (1)' '03-Jan-2001' '11:00' [ 3.5000] [ 7]