23 lines
807 B
Python
23 lines
807 B
Python
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 |