Add script for generating signals based on VIX Above Moving Average strategy
This commit is contained in:
parent
b25a4b3c96
commit
d5a0e70c8b
23
strategies/vix_above_moving_average.py
Normal file
23
strategies/vix_above_moving_average.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user