# peravg

Periodic average of FINTS object

`peravg` is not recommended. Use `timetable` instead. For more information, see Convert Financial Time Series Objects fints to Timetables.

## Syntax

```avgfts = peravg(tsobj)
avgfts = peravg(tsobj,numperiod)
avgfts = peravg(tsobj,daterange)
```

## Arguments

 `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

## Description

`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 character vector, it is assumed as a range of date character vector. 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 character vector, it is assumed as a range of date character vectors. If the period is entered as numeric, the number represents the number of data points to be included in a period for the calculation.

## Examples

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)```
```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: My first FINTS freq: Daily (1) 'dates: (6)' 'times: (6)' 'Data1: (6)' 'Data2: (6)' '01-Jan-2001' '11:00' [ 1] [ 2] ' " ' '12:00' [ 2] [ 4] '02-Jan-2001' '11:00' [ 3] [ 6] ' " ' '12:00' [ 4] [ 8] '03-Jan-2001' '11:00' [ 5] [ 10] ' " ' '12:00' [ 6] [ 12] Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/peravg (line 85) p = struct with fields: Data1: [2 5] Data2: [4 10] Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) 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')`
```Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/peravg (line 85) p = struct with fields: Data1: 3.5000 Data2: 7 Warning: FINTS will be removed in a future release. Use TIMETABLE instead. > In fints/display (line 66) pFts = desc: My first FINTS freq: Daily (1) 'dates: (1)' 'times: (1)' 'Data1: (1)' 'Data2: (1)' '03-Jan-2001' '11:00' [ 3.5000] [ 7]```