TAlib python,如何使用可变周期的MAVP移动平均值

2024-10-17 08:25:29 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我尝试使用此方法,但它会引发错误,因为periods参数, 如何对这样的数据帧使用此方法enter image description here


Tags: 数据方法close参数错误realperiodsminperiod
1条回答
网友
1楼 · 发布于 2024-10-17 08:25:29

此period参数必须作为要获取的时段数组传递。我从Yahoo Finance那里得到了苹果股票的价格,并得到了整个期间的移动平均值

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

相关问题 更多 >