예전부터 코인에 관심 많았는데, fastdtw를 이용해
CCXT BINANCE로 과거 5년데이터 수집 후 , 차트 유사도 검출 -> 미래 가격 예측 코드이다.
- RSI (Relative Strength Index)
- 가격 데이터의 상승/하락 비율을 기반으로 시장 과매수/과매도 상태를 측정.
- period=14로 설정
- RSI=100−(1+RS100)
- MACD (Moving Average Convergence Divergence)
- 12일 , 26일 이동 평균의 차이를 계산한 후, 신호선(9일)과 비교.
- MACD Line이 신호선을 상향 돌파하면 매수 신호.
- MACD Line이 신호선을 하향 돌파하면 매도 신호
- Bollinger Bands20일의 이동 평균과 표준편차를 기반으로 상한선, 중앙선, 하한선을 계산.
def calculate_rsi(close_prices: pd.Series, period: int = 14) -> pd.Series:
delta = close_prices.diff()
gain = (delta.where(delta > 0, 0)).rolling(window=period).mean()
loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean()
rs = gain / loss
return 100 - (100 / (1 + rs))
def calculate_macd(close_prices: pd.Series, fast: int = 12, slow: int = 26, signal: int = 9) -> Tuple[pd.Series, pd.Series]:
exp1 = close_prices.ewm(span=fast, adjust=False).mean()
exp2 = close_prices.ewm(span=slow, adjust=False).mean()
macd = exp1 - exp2
signal_line = macd.ewm(span=signal, adjust=False).mean()
return macd, signal_line
def calculate_bollinger_bands(close_prices: pd.Series, period: int = 20, std_dev: int = 2) -> Tuple[pd.Series, pd.Series, pd.Series]:
middle_band = close_prices.rolling(window=period).mean()
std = close_prices.rolling(window=period).std()
upper_band = middle_band + (std * std_dev)
lower_band = middle_band - (std * std_dev)
return upper_band, middle_band, lower_band
'Python' 카테고리의 다른 글
서든어택 객체탐지 (Object Detection) (0) | 2025.01.29 |
---|---|
파이썬 코드 암호화 알고리즘 (1) | 2025.01.03 |
Python - Regression(Ridge, LASSO, ELASTICNET) (0) | 2022.10.25 |
Python - Regression 회귀 분석 (0) | 2022.10.24 |
Python - 다중공선성 , 차원축소 , 군집 (0) | 2022.10.24 |