Add script for generating Turnaround Tuesday (or Monday) swing trading signals

This commit is contained in:
moshferatu 2024-11-08 10:52:52 -08:00
parent 99a7165ffb
commit dc8e340294

16
strategies/turnaround.py Normal file
View File

@ -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