Add script for generating swing trading signals based on declines
This commit is contained in:
parent
70425b9e6d
commit
52d651209b
22
strategies/declines.py
Normal file
22
strategies/declines.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from pandas import DataFrame, Series
|
||||||
|
from daily_data import get_daily_data
|
||||||
|
|
||||||
|
def signals(data: DataFrame) -> Series:
|
||||||
|
"""
|
||||||
|
Generate long signals based on the Decline / Advance Ratio strategy.
|
||||||
|
|
||||||
|
Returns a Series with 'L' for long signals and 'N' for no signal.
|
||||||
|
"""
|
||||||
|
above_200_ma = data['Close'] > data['Close'].rolling(window = 200).mean()
|
||||||
|
|
||||||
|
start_date = data['Date'].min()
|
||||||
|
end_date = data['Date'].max()
|
||||||
|
advances = get_daily_data(symbol = 'IINA.Z', start_date = start_date, end_date = end_date)
|
||||||
|
declines = get_daily_data(symbol = 'IIND.Z', start_date = start_date, end_date = end_date)
|
||||||
|
|
||||||
|
ratio = declines['Close'] / advances['Close']
|
||||||
|
ratio_greater_than_2 = ratio >= 2
|
||||||
|
|
||||||
|
signals = Series('N', index = data.index)
|
||||||
|
signals[above_200_ma & ratio_greater_than_2] = 'L'
|
||||||
|
return signals
|
Loading…
Reference in New Issue
Block a user