기업행위 조정

R에서 금융 데이터 가져오기와 관리

Joshua Ulrich

Quantitative Analyst & quantmod Co-Author and Maintainer

주식분할·배당 반영 (1)

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")
R에서 금융 데이터 가져오기와 관리

주식분할·배당 반영 (2)

R에서 금융 데이터 가져오기와 관리
# 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
R에서 금융 데이터 가져오기와 관리

미조정 배당 다운로드

# 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
R에서 금융 데이터 가져오기와 관리

adjRatios()

  • 어떤 시계열이든 분할, 배당 또는 둘 다에 대해 과거 조정
  • 인수 3개:
    • splits
    • dividends
    • close
  • 반환: 2개 열(Split, Div)의 xts 객체
R에서 금융 데이터 가져오기와 관리

단변량 시계열을 분할·배당으로 조정

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)
R에서 금융 데이터 가져오기와 관리

단변량 시계열을 분할·배당으로 조정

# 미조정 종가에 분할·배당 비율을 곱함
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에서 금융 데이터 가져오기와 관리

Laten we oefenen!

R에서 금융 데이터 가져오기와 관리

Preparing Video For Download...