In [1]:
import numpy as np
import pandas as pd
from pandas_datareader import data
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
# 삼성전자
# http://finance.yahoo.com/quote/005930.KS?p=005930.KS
df = data.get_data_yahoo(
"005930.KS",
start="20160101",
end="20161231",
)
In [3]:
df.head()
Out[3]:
In [4]:
ax = df["Adj Close"].plot(label=True)
ax.set_title("삼성전자 주가 변화 (2016)")
Out[4]:
In [5]:
# 이동평균선 ( 5일선, 20일선, 60일선 )
df["MA5"] = df["Adj Close"].rolling(window=5).mean()
df["MA20"] = df["Adj Close"].rolling(window=20).mean()
df["MA60"] = df["Adj Close"].rolling(window=60).mean()
ax = df[["MA5", "MA20", "MA60", "Adj Close"]].plot()
ax.set_xlim("20161201", "20161231")
ax.set_ylim(1500000, 1900000)
ax.set_title("삼성전자 차트 - 이동평균선")
Out[5]: