Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pykrx import stock
- import matplotlib.pyplot as plt
- import numpy as np
- from scipy.signal import argrelextrema
- # 주가 스크래핑
- samsung = stock.get_market_ohlcv_by_date("20200101", "20200630", "005930")
- plt.plot(samsung['종가'], label='samsung (005930)')
- # 21이평
- ma21 = samsung['종가'].rolling(21).mean()
- plt.plot(ma21, label='samsung moving average 21')
- # 극대값
- idx = argrelextrema(ma21.values, np.greater)
- plt.plot(ma21.index[idx], ma21.iloc[idx], '.', c='b', ms=20, label=' local maximum point')
- # 극소값
- idx = argrelextrema(ma21.values, np.less)
- plt.plot(ma21.index[idx], ma21.iloc[idx], '.', c='r', ms=20, label=' local minimum point')
- plt.legend()
Advertisement
Add Comment
Please, Sign In to add comment