Initial commit of RSI 25 / 75 strategy

This commit is contained in:
moshferatu 2024-12-07 01:54:59 -08:00
parent e4e8fd29cc
commit 218bb347aa
3 changed files with 34 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from .internal_bar_strength_band import internal_bar_strength_band
from .large_moves_down import large_moves_down
from .lower_lows import lower_lows
from .put_call_ratio_highs import put_call_ratio_highs
from .rsi_25_75 import rsi_25_75
from .rsi_power_zones import rsi_power_zones
from .short_term_lows import short_term_lows
from .tps import tps

20
strategies/rsi_25_75.py Normal file
View File

@ -0,0 +1,20 @@
import numpy as np
from pandas import DataFrame, Series
from indicators import sma, rsi
def rsi_25_75(data: DataFrame) -> Series:
"""
Calculate signals for the RSI 25 / 75 strategy.
Returns a Series with 'L' for long signals and 'N' otherwise.
"""
ma_200 = sma(data, period = 200)
rsi_4 = rsi(data, period = 4)
above_ma_200 = data['Close'] > ma_200
rsi_below_25 = rsi_4 < 25
conditions = above_ma_200 & rsi_below_25
return Series(np.where(conditions, 'L', 'N'), index = data.index)

13
test/rsi_25_75_test.py Normal file
View File

@ -0,0 +1,13 @@
from datetime import datetime, timedelta
from ohlc import ohlc
from strategies import rsi_25_75
today = datetime.today()
data = ohlc('SPY', start_date = today - timedelta(days = 365), end_date = today)
signals = rsi_25_75(data)
result = data[['Date']].copy()
result['Signal'] = signals
print(result.tail(50))