[R] Adjusting OHCL data via quantmod

Joe O joerodonnell at gmail.com
Thu Mar 15 21:56:47 CET 2018


Took out snippet of problematic code:

###
library(quantmod)

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

#Manual adjustments for splits, and split-adjusted dividends
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"]
head(merge(close_av, close_av_adj, Ad(AAPL)))

#Adjust all data for splits, and split-adjusted dividends (I think)
AAPL_a <- adjustOHLC(AAPL, use.Adjusted = TRUE)
head(AAPL_a)
###


On Thu, Mar 15, 2018 at 4:16 AM, Joe O <joerodonnell at gmail.com> wrote:

> 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 (https://campus.datacamp.com/
> courses/importing-and-managing-financial-data-in-r/
> importing-text-data-and-adjusting-for-corporate-actions?ex=10) (and
> quantmod documentation) to determine how Alpha Vantage's data is adjusted.
>
> Here are my findings:
>
> -It seems that Alpha Vantage's OHLC data are unadjusted, and the adjusted
> close column provided is adjusted for splits, and split-adjusted dividends.
> -If I use AV's adjusted close column to adjust my OHCL data, my data will
> be adjusted for splits, and split-adjusted dividends. (So, I can use
> adjustOHLC(), with argument use.Adjusted = TRUE to adjust for splits, and
> split-adjusted dividends)
>
> Evidence:
>
> ###
> library(quantmod)
>
> #AV data
> getSymbols("AAPL",src = "av" ,api.key = my_api_key
>            , adjusted = TRUE, output.size = "full") #supply your own api
> key
>
> #Manual adjustments for splits, and split-adjusted dividends
> 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"]
> head(merge(close_av, close_av_adj, Ad(AAPL)))
>
> #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
>
> #Adjust all data for splits, and split-adjusted dividends (I think)
> AAPL_a <- adjustOHLC(AAPL, use.Adjusted = TRUE)
> head(AAPL_a)
> ###
>
> Two questions:
> -1. Am I interpreting these adjustments correctly?
> -2. What adjustment method minimizes the difference between backtesting
> and live-trading?
>
> p.s., I expect there is no "correct" method for adjusting data. I'm
> curious if there is a "best-practice" or norm that is used. I'm curious if
> there is a method which minimizes the difference between backtesting and
> live-trading. Thanks you, -Joe
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list