모멘텀 전략
import numpy as np
from pandas import Series, DataFrame
import pandas as pd
import Data_Reader as dr
df = dr.db_read('002290')
yeild = df["종가"]/df["종가"].shift(6)
cond = yeild>1.03
cond_m = cond.shift(1).fillna(False)
s = df.loc[cond_m,"종가"]/df.loc[cond_m,"시가"]
print(s.cumprod().iloc[-1])
지수이동평균 수익률
s = df["종가"].ewm(span=20,adjust=False).mean()
cond = s.shift(1)<df["시가"]
result = df.loc[cond,"종가"]/df.loc[cond,"시가"]
result = result.cumprod().iloc[-1]
print(result)
'DataFrame' 카테고리의 다른 글
주식 데이터분석 기초 (0) | 2022.04.25 |
---|---|
1 (0) | 2022.04.16 |
Data 관리 Main (0) | 2022.04.14 |
finance-datareader (0) | 2022.04.13 |
KRX (0) | 2022.04.13 |
댓글