Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TA-lib python, How use MAVP - Moving average with variable period

Tags:

python

ta-lib

real = MAVP(close, periods, minperiod=2, maxperiod=30, matype=0)

i am trying to use this method but it raises an error because the periods parameters, How to use this method for Dataframe like this enter image description here

like image 840
Abdelrahman Hamdy Avatar asked Mar 23 '26 15:03

Abdelrahman Hamdy


1 Answers

This period parameter must be passed as an array of the periods you want to get. I got the Apple stock price from Yahoo Finance and got a moving average for the entire period I got it.

import yfinance as yf
data = yf.download("AAPL", start="2020-01-01", end="2021-01-01")

data.head()
    Open    High    Low     Close   Adj Close   Volume
Date                        
2020-01-02  74.059998   75.150002   73.797501   75.087502   74.333511   135480400
2020-01-03  74.287498   75.144997   74.125000   74.357498   73.610840   146322800
2020-01-06  73.447502   74.989998   73.187500   74.949997   74.197395   118387200
2020-01-07  74.959999   75.224998   74.370003   74.597504   73.848442   108872000
2020-01-08  74.290001   76.110001   74.290001   75.797501   75.036385   132079200

import talib as ta
import numpy as np

data.reset_index(drop=False,inplace=True)
periods = data.Date
real = ta.MAVP(data.Close, periods, minperiod=2, maxperiod=30, matype=0)

real
0             NaN
1             NaN
2             NaN
3             NaN
4             NaN
          ...    
248    131.465004
249    134.330002
250    135.779999
251    134.294998
252    133.205002
Length: 253, dtype: float64
like image 134
r-beginners Avatar answered Mar 26 '26 05:03

r-beginners



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!