2

I want to use the following function of ta-lib.

I want to understand the meaning of periods.

MAVP

MAVP([input_arrays], [minperiod=2], [maxperiod=30], [matype=0])

Moving average with variable period (Overlap Studies)

Inputs:
price: (any ndarray) periods: (any ndarray)
Parameters:
minperiod: 2 maxperiod: 30 matype: 0 (Simple Moving Average)
Outputs:
real

It gives an error back when the length of periods is different to the length of price (additionally: it gives back a nparray, if matype is >= 0 and <= 8, else an error is thrown).

The original documentation: https://mrjbq7.github.io/ta-lib/func_groups/overlap_studies.html

A reference to some (auto generated) documentation: https://www.backtrader.com/docu/talibindautoref.html

EDIT: The underlying c code is here: http://svn.code.sf.net/p/ta-lib/code/trunk/ta-lib/c/src/ta_func/ta_MAVP.c

also posted here: https://github.com/mrjbq7/ta-lib/issues/175

1 Answers1

3

As depicted in https://github.com/mrjbq7/ta-lib/issues/175#issuecomment-356042378:

This is what the function does. It gets an input price array, and a periods array that are the same length. The output price array is the moving average at the point using the specified period at the point. So, if you have an array of [1, 5, 3, 8] and you specify periods [2,3,3,2] then the output will be:

[SMA(2)[0], SMA(3)[1], SMA(3)[2], SMA(2)[3]]

With the exception that it puts maxperiods number of nan's at the front, for some reason so you'd need to call it like:

>>> prices = np.array([1,5,7,8], dtype=float)
>>> periods =np.array([2,3,3,2], dtype=float)
>>> ta.MAVP(prices, periods, maxperiod=3)
array([        nan,         nan,  4.33333333,  7.5       ])

>>> ta.SMA(prices, 2)
array([ nan,  3. ,  6. ,  7.5])

>>> ta.SMA(prices, 3)
array([        nan,         nan,  4.33333333,  6.66666667])