def is_strong(df_close, window=12):
""" In 12 days periods, How many are ROC'security more than ROC' SET (percent %) """
# df_roc has calculated by daily_returns
df_roc = roc(df_close)
# Empty Data Frame
df_main = pd.DataFrame(index=df_close.index, columns=df_close.columns)
for symbol in df_close.columns:
if symbol == 'SET':
continue
df_compare = df_roc['SET'] < df_roc[symbol]
# In python True is 1, False is 0
# 1: meaning 12 days periods, ROC'security > ROC'SET always
# 2: meaning 12 days periods, ROC'security < ROC'SET always
df_main[symbol] = pd.rolling_mean(df_compare[window:], window)
df_main['SET']=0
print(df_main)
评论列表
文章目录