Skip to content

Commit 09fa901

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 94eec36 commit 09fa901

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

financial/Relative Strength Index (RSI).py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import List
22

3+
34
def calculate_rsi(prices: List[float], period: int = 14) -> List[float]:
45
"""
56
Calculate the Relative Strength Index (RSI) for a given list of prices.
@@ -33,7 +34,7 @@ def calculate_rsi(prices: List[float], period: int = 14) -> List[float]:
3334
# Calculate price changes between consecutive days
3435
for i in range(1, len(prices)):
3536
delta = prices[i] - prices[i - 1]
36-
37+
3738
# Gain if delta is positive, otherwise it's a loss
3839
gains.append(max(0, delta))
3940
losses.append(max(0, -delta))
@@ -57,7 +58,7 @@ def calculate_rsi(prices: List[float], period: int = 14) -> List[float]:
5758
# Calculate the rest of the RSI values using smoothed moving averages
5859
for i in range(period, len(prices)):
5960
delta = prices[i] - prices[i - 1]
60-
61+
6162
# Update gains and losses
6263
gain = max(0, delta)
6364
loss = max(0, -delta)
@@ -81,6 +82,22 @@ def calculate_rsi(prices: List[float], period: int = 14) -> List[float]:
8182

8283
# Example usage:
8384
if __name__ == "__main__":
84-
prices = [44.0, 44.15, 44.09, 44.20, 44.30, 44.25, 44.40, 44.35, 44.50, 44.60, 44.55, 44.75, 44.80, 44.70, 44.85]
85+
prices = [
86+
44.0,
87+
44.15,
88+
44.09,
89+
44.20,
90+
44.30,
91+
44.25,
92+
44.40,
93+
44.35,
94+
44.50,
95+
44.60,
96+
44.55,
97+
44.75,
98+
44.80,
99+
44.70,
100+
44.85,
101+
]
85102
rsi = calculate_rsi(prices, 14)
86103
print("RSI Values:", rsi)

0 commit comments

Comments
 (0)