Initial commit of R3 strategy
This commit is contained in:
parent
218bb347aa
commit
e49f430394
23
strategies/r3.py
Normal file
23
strategies/r3.py
Normal file
@ -0,0 +1,23 @@
|
||||
import numpy as np
|
||||
|
||||
from pandas import DataFrame, Series
|
||||
|
||||
from indicators import sma, rsi
|
||||
|
||||
def r3(data: DataFrame) -> Series:
|
||||
"""
|
||||
Calculate signals for the R3 strategy.
|
||||
|
||||
Returns a Series with 'L' for long signals and 'N' otherwise.
|
||||
"""
|
||||
ma_200 = sma(data, period = 200)
|
||||
above_ma_200 = data['Close'] > ma_200
|
||||
|
||||
rsi_2 = rsi(data, period = 2)
|
||||
first_day_condition = rsi_2.shift(2) < 60
|
||||
second_day_condition = rsi_2.shift(1) < rsi_2.shift(2)
|
||||
third_day_condition = rsi_2 < rsi_2.shift(1)
|
||||
three_day_drop = first_day_condition & second_day_condition & third_day_condition
|
||||
|
||||
conditions = above_ma_200 & three_day_drop & (rsi_2 < 10)
|
||||
return Series(np.where(conditions, 'L', 'N'), index = data.index)
|
Loading…
Reference in New Issue
Block a user