diff --git a/strategies/turnaround.py b/strategies/turnaround.py new file mode 100644 index 0000000..5e18f75 --- /dev/null +++ b/strategies/turnaround.py @@ -0,0 +1,16 @@ +from pandas import DataFrame, Series, to_datetime + +def signals(data: DataFrame) -> Series: + """ + Generate long signals based on the day of the week and downward close conditions. + + Returns a Series with 'L' for long signals and 'N' for no signal. + """ + date_series = to_datetime(data['Date'], errors = 'coerce') + monday_or_tuesday = date_series.dt.dayofweek.isin([0, 1]) + lower_past_two_days = (data['Close'] < data['Close'].shift(1)) & (data['Close'].shift(1) < data['Close'].shift(2)) + + signals = Series('N', index=data.index) + signals[monday_or_tuesday & lower_past_two_days] = 'L' + + return signals \ No newline at end of file