From d5a0e70c8b8eee325681c52b1f0a20acf72f2587 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 21 Nov 2024 12:28:22 -0800 Subject: [PATCH] Add script for generating signals based on VIX Above Moving Average strategy --- strategies/vix_above_moving_average.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 strategies/vix_above_moving_average.py diff --git a/strategies/vix_above_moving_average.py b/strategies/vix_above_moving_average.py new file mode 100644 index 0000000..52a7972 --- /dev/null +++ b/strategies/vix_above_moving_average.py @@ -0,0 +1,23 @@ +from pandas import DataFrame, Series + +from daily_data import get_daily_data + +def signals(data: DataFrame) -> Series: + """ + Generate long signals based on the VIX Above Moving Average strategy. + + Returns a Series with 'L' for long signals and 'N' for no signal. + """ + ma_200 = data['Close'].rolling(window = 200).mean() + above_200_ma = data['Close'] > ma_200 + + start_date = data['Date'].min() + end_date = data['Date'].max() + vix_data = get_daily_data(symbol='VIX.XO', start_date = start_date, end_date = end_date) + + vix_ma_10 = vix_data['Close'].rolling(window = 10).mean() + vix_close_10_percent_above_ma = vix_data['Close'] >= (1.1 * vix_ma_10) + + signals = Series('N', index = data.index) + signals[above_200_ma & vix_close_10_percent_above_ma] = 'L' + return signals \ No newline at end of file