R에서 금융 데이터 가져오기와 관리
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
getSymbols("MSFT", from = "2004-07-01", to = "2004-12-31")
"MSFT"
# 주식분할·배당을 반영해 데이터 조정
msft_adjusted <- adjustOHLC(MSFT)
# 객체명이 티커 심볼이 아님
my_data <- MSFT
# symbol.name 인자 사용
my_data_adjusted <- adjustOHLC(my_data, symbol.name = "MSFT")

# Yahoo Finance에서 분할 데이터 다운로드
splits <- getSplits("GE")
head(splits, n = 4)
GE.spl
1971-06-08 0.5
1983-06-02 0.5
1987-05-26 0.5
1994-05-16 0.5
# Yahoo Finance에서 분할 반영 배당 데이터 다운로드
dividends <- getDividends("GE")
head(dividends, n = 4)
GE.div
1970-03-03 0.00677
1970-06-11 0.00677
1970-09-21 0.00677
1970-12-07 0.00677
# Yahoo Finance에서 미조정 배당 데이터 다운로드
dividends_raw <- getDividends("GE", split.adjust = FALSE)
# 조정/미조정 배당 비교
head(merge(dividends, dividends_raw))
GE.div GE.div.1
1970-03-03 0.00677 0.64992
1970-06-11 0.00677 0.64992
1970-09-21 0.00677 0.64992
1970-12-07 0.00677 0.64992
1971-03-03 0.00677 0.64992
1971-06-17 0.00729 0.34992
splitsdividendscloseSplit, Div)의 xts 객체getSymbols("GE", from = "2000-01-01")
"GE"
close <- Cl(GE)
splits <- getSplits("GE")
dividends_raw <- getDividends("GE", split.adjust = FALSE)
# 분할, 미조정 배당, 미조정 종가를 전달
ratios <- adjRatios(splits = splits,
dividends = dividends_raw,
close = close)
# 미조정 종가에 분할·배당 비율을 곱함
close_adjusted <- close * ratios[, "Split"] * ratios[, "Div"]
head(merge(close, close_adjusted, Ad(GE)), n = 4)
GE.Close GE.Close.1 GE.Adjusted
2000-01-03 150.0000 29.50422 29.44630
2000-01-04 144.0000 28.32405 28.26845
2000-01-05 143.7500 28.27488 28.21937
2000-01-06 145.6718 28.65289 28.59664
R에서 금융 데이터 가져오기와 관리