from pandas import DataFrame, Series from daily_data import get_daily_data def signals(data: DataFrame) -> Series: """ Generate signals based on the Put / Call Ratio Highs 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() put_volume = get_daily_data(symbol = 'VPOT.Z', start_date = start_date, end_date = end_date) call_volume = get_daily_data(symbol = 'VCOT.Z', start_date = start_date, end_date = end_date) # The put and call volume data contains extraneous data for holidays when the market is closed. put_volume = put_volume[put_volume['Date'].isin(data['Date'])].reset_index(drop = True) call_volume = call_volume[call_volume['Date'].isin(data['Date'])].reset_index(drop = True) put_call_ratio = put_volume['Close'] / call_volume['Close'] put_call_high_5_day = put_call_ratio == put_call_ratio.rolling(window = 5).max() signals = Series('N', index = data.index) signals[above_200_ma & put_call_high_5_day] = 'L' return signals