attributeError:' numpy.float64'对象没有属性'滚动'

发布于 2025-01-18 00:08:12 字数 1195 浏览 1 评论 0原文

我想在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文