# [R] Adjusting OHCL data via quantmod

Joe O joerodonnell at gmail.com
Thu Mar 15 12:16:06 CET 2018

```Hello,

I'm trying to do two things:
-1. Ensure that I understand how quantmod adjust's OHLC data
-2. Determine how I ought to adjust my data.

My overarching-goal is to adjust my OHLC data appropriately to minimize the
difference between my backtest returns, and the returns I would get if I
was trading for real (which I'll be doing shortly).

Background:
-1. I'm using Alpha Vantage's data, and quantmod's data adjustment tools.
-2: I used Joshua Ulrich's DataCamp guidance (
(and quantmod documentation) to determine how Alpha Vantage's data is

Here are my findings:

-It seems that Alpha Vantage's OHLC data are unadjusted, and the adjusted
-If I use AV's adjusted close column to adjust my OHCL data, my data will

Evidence:

###
library(quantmod)

#AV data
getSymbols("AAPL",src = "av" ,api.key = my_api_key
, adjusted = TRUE, output.size = "full") #supply your own api key

close_av <- Cl(AAPL)
splits <- getSplits("AAPL")
dividends <- getDividends("AAPL", split.adjust = TRUE)
ratios_av <- adjRatios(splits = splits, dividends = dividends, close =
close_av)
close_av_adj <- close_av * ratios_av[,"Div"] * ratios_av[,"Split"]

#The leftmost column is the raw close data from Alpha Vantage,
#the middle column is the raw Alpha Vantage close column manually adjusted
#for splits and split-adjusted dividends, and the last column is the
adjusted close column returned by Alpha Vantage

###

Two questions:
-1. Am I interpreting these adjustments correctly?
-2. What adjustment method minimizes the difference between backtesting and