mmyjh86

[러닝-인강] 차트 극소 극대

Jul 26th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from pykrx import stock
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from scipy.signal import argrelextrema
  5.  
  6. # 주가 스크래핑
  7. samsung = stock.get_market_ohlcv_by_date("20200101", "20200630", "005930")
  8. plt.plot(samsung['종가'], label='samsung (005930)')
  9.  
  10. # 21이평
  11. ma21 = samsung['종가'].rolling(21).mean()
  12. plt.plot(ma21, label='samsung moving average 21')
  13.  
  14. # 극대값
  15. idx = argrelextrema(ma21.values, np.greater)
  16. plt.plot(ma21.index[idx], ma21.iloc[idx], '.', c='b', ms=20, label=' local maximum point')
  17.  
  18. # 극소값
  19. idx = argrelextrema(ma21.values, np.less)
  20. plt.plot(ma21.index[idx], ma21.iloc[idx], '.', c='r', ms=20, label=' local minimum point')
  21. plt.legend()
Advertisement
Add Comment
Please, Sign In to add comment