from datetime import datetime from pandas import DataFrame from strategies import advances from strategies import cumulative_rsi from strategies import declines from strategies import double_5s from strategies import down_days_in_a_row from strategies import end_of_month from strategies import engulfing from strategies import high_volume_days from strategies import hilo_index_lows from strategies import ibs_rsi from strategies import internal_bar_strength from strategies import internal_bar_strength_band from strategies import large_moves_down from strategies import lower_lows from strategies import put_call_ratio_highs from strategies import r3 from strategies import rsi_25_75 from strategies import rsi_power_zones from strategies import short_term_lows from strategies import tps from strategies import trin from strategies import trin_thrusts from strategies import turnaround from strategies import two_period_rsi from strategies import vix_above_moving_average from strategies import vix_reversal_1 from strategies import vix_reversal_2 from strategies import vix_reversal_3 from strategies import vix_rsi from daily_data import get_daily_data def calculate_signals(data: DataFrame, days: int = 12) -> DataFrame: start_date = data['Date'].min() end_date = data['Date'].max() advances_data = get_daily_data(symbol = 'IINA.Z', start_date = start_date, end_date = end_date) declines_data = get_daily_data(symbol = 'IIND.Z', start_date = start_date, end_date = end_date) new_highs_data = get_daily_data(symbol = 'FINH.Z', start_date = start_date, end_date = end_date) new_lows_data = get_daily_data(symbol = 'FINL.Z', start_date = start_date, end_date = end_date) put_volume_data = get_daily_data(symbol = 'VPOT.Z', start_date = start_date, end_date = end_date) call_volume_data = get_daily_data(symbol = 'VCOT.Z', start_date = start_date, end_date = end_date) trin_data = get_daily_data(symbol = 'RINT.Z', start_date = start_date, end_date = end_date) vix_data = get_daily_data(symbol = 'VIX.XO', start_date = start_date, end_date = end_date) strategy_signals = [ {'strategy': '2-Period RSI', 'signals': two_period_rsi(data)}, {'strategy': 'Advances', 'signals': advances(data, advances_data, declines_data)}, {'strategy': 'Cumulative RSI', 'signals': cumulative_rsi(data)}, {'strategy': 'Declines', 'signals': declines(data, declines_data, advances_data)}, {'strategy': 'Double 5\'s', 'signals': double_5s(data)}, {'strategy': 'Down Days in a Row', 'signals': down_days_in_a_row(data)}, {'strategy': 'End of Month', 'signals': end_of_month(data)}, {'strategy': 'Engulfing', 'signals': engulfing(data)}, {'strategy': 'High Volume Days', 'signals': high_volume_days(data)}, {'strategy': 'HILO Index Lows', 'signals': hilo_index_lows(data, new_highs_data, new_lows_data)}, {'strategy': 'IBS + RSI', 'signals': ibs_rsi(data)}, {'strategy': 'Internal Bar Strength', 'signals': internal_bar_strength(data)}, {'strategy': 'Internal Bar Strength Band', 'signals': internal_bar_strength_band(data)}, {'strategy': 'Large Moves Down', 'signals': large_moves_down(data)}, {'strategy': 'Lower Lows', 'signals': lower_lows(data)}, {'strategy': 'Put / Call Ratio Highs', 'signals': put_call_ratio_highs(data, put_volume_data, call_volume_data)}, {'strategy': 'R3', 'signals': r3(data)}, {'strategy': 'RSI 25 / 75', 'signals': rsi_25_75(data)}, {'strategy': 'RSI PowerZones', 'signals': rsi_power_zones(data)}, {'strategy': 'Short-Term Lows', 'signals': short_term_lows(data)}, {'strategy': 'TPS', 'signals': tps(data)}, {'strategy': 'TRIN', 'signals': trin(data, trin_data)}, {'strategy': 'TRIN Thrusts', 'signals': trin_thrusts(data, trin_data)}, {'strategy': 'Turnaround', 'signals': turnaround(data)}, {'strategy': 'VIX Above Moving Average', 'signals': vix_above_moving_average(data, vix_data)}, {'strategy': 'VIX Reversal 1', 'signals': vix_reversal_1(data, vix_data)}, {'strategy': 'VIX Reversal 2', 'signals': vix_reversal_2(data, vix_data)}, {'strategy': 'VIX Reversal 3', 'signals': vix_reversal_3(data, vix_data)}, {'strategy': 'VIX RSI', 'signals': vix_rsi(data, vix_data)} ] signal_data = [] for signal_info in strategy_signals: signal_dict = {'Strategy': signal_info['strategy']} signals = signal_info['signals'].tail(days) dates = [datetime.strptime(str(date), '%Y-%m-%d').strftime('%m/%d') for date in data.tail(days)['Date']] for date, signal in zip(dates, signals): signal_dict[date] = signal signal_data.append(signal_dict) return DataFrame(signal_data)