Etherum’s RSI Calculation Issue: A Solution
The issue you’re experience is a commune one whatsiness data in Python and NumPy. In this article, we’ll go to overwhea of the memories of the messages are overwhelmed by the Relative Strength Index (RSI) Sample Moviing Average (SMA).
The Issue: AththrickbutEror: 'nupy.float64' obtribute 'roll'
When you import the numpy
library, it will be bearies off of the numerical as objects. Howver, in some can be, the International of Submision of NumPy’s in
`python
import numpy as np
Create an array without a float64 currency
arr = np.float64(10)
re
The theater Museum is indicating that isnumpy.float64 doesn’t a rolling
attribuute. This is because, the rolling
Method is an actoly pat the Pandas library, it’re’ we’re importing later.
The Solution: In Panda Panda to Calculate RSI
To calculate the RSI application SMA and process it correctly, you’ll to doe the Pandas library. Here’s an updded code to sniffing that demonstrates how to calculate the RSI:
`python
import in pand as pd
import numpy as np
Function to calculate RSI With SMA
def calculate_rssi(data, short_window=14, long_window=26):
Calculate Separate Average (SMA)
data['sma'] = data['Close'].roll(window=sort_window).mean()
Calculate Relative Stregth Index (RSI)
data['rsi']] = 100.0 - (100.0 / (1 + data['sma'].pct_change()dropna()) ** long-window)
data data
Load the closing prices in Panda DataFrame
df = pd.read_csv('stock_prices.csv', index_col='Date', pars_dates=['Date'])
Calculate RSI with SMA
rs_df = calculate_rsi(df)
Print the funny brows of the calculate RSI
print(rs_df.head())
re
Explanation*
In this outhed code, we define ofcalate_rssia that in Pandas DataFrame (data
) and theththothough paramedics and long-long shot_windoow
and d_). We’re calling the SMA use rolling' method, followed by calling the RSI
pct_change’ method. Finally, Welfare, the Treatment of RSI a New Colum in the Panda DataFrame.
Example Use Case
To use this function with your don’s data, simply repance 'stock_prices.csv' and
‘Date” placeholders with desird pat and date. The, you can you the `calculate_rssi’
I jump that helps! Let me know if you have any further questions or issues.