attributeError:' numpy.float64'对象没有属性'滚动'
我想在SMA中再次计算RSI数字并对其进行处理。 但是,与主题类似的错误发生。 “ attributeError:'numpy.float64'对象没有属性'滚动'”
import talib
import requests
import pandas as pd
import time
class RSI:
def rsi(symbol, timeinterval, limit, period):
coin = Can.get_fu_coin(symbol, timeinterval, limit)
coin['close'] = coin['close'].astype(float)
data = coin['close']
period = period
delta = data.diff()
up, down = delta.copy(), delta.copy()
up[up < 0] = 0
down[down > 0] = 0
_gain = up.ewm(com = (period - 1), min_periods = period).mean()
_loss = down.abs().ewm(com = (period - 1), min_periods = period).mean()
RS = _gain / _loss
rsi = 100 - (100 / (1 + RS))
rsi = rsi.iloc[-1]
rsi = round(rsi, 4)
return rsi
def rma(symbol, timeinterval, limit, period, n):
data = RSI.rsi(symbol, timeinterval, limit, period).rolling(n)
return talib.SMA(data,n)
RSI.rma('BTCUSDT', '1m', '1000', 14, 7)
I would like to calculate the RSI figure once again in SMA and process it.
However, an error similar to the subject occurs. " AttributeError: 'numpy.float64' object has no attribute 'rolling' "
import talib
import requests
import pandas as pd
import time
class RSI:
def rsi(symbol, timeinterval, limit, period):
coin = Can.get_fu_coin(symbol, timeinterval, limit)
coin['close'] = coin['close'].astype(float)
data = coin['close']
period = period
delta = data.diff()
up, down = delta.copy(), delta.copy()
up[up < 0] = 0
down[down > 0] = 0
_gain = up.ewm(com = (period - 1), min_periods = period).mean()
_loss = down.abs().ewm(com = (period - 1), min_periods = period).mean()
RS = _gain / _loss
rsi = 100 - (100 / (1 + RS))
rsi = rsi.iloc[-1]
rsi = round(rsi, 4)
return rsi
def rma(symbol, timeinterval, limit, period, n):
data = RSI.rsi(symbol, timeinterval, limit, period).rolling(n)
return talib.SMA(data,n)
RSI.rma('BTCUSDT', '1m', '1000', 14, 7)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论