joshuaulrich / joshuaulrich/quantmod

Unexpected Behavior in adjustOHLC

Open
#152 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
R
Stars
906
Forks
233
PR merge metrics
No merged PRs in 30d

Description

The following two examples produce different results, although I initially thought they would/should yield identical results:

> x = getSymbols("GOOGL", from = "2014-04-02", to = "2014-04-04", auto.assign = F)
> adjustOHLC(x)
GOOGL.Open GOOGL.High GOOGL.Low GOOGL.Close GOOGL.Volume GOOGL.Adjusted
2014-04-02 1141.90 1144.80 1124.00 1135.10 4168000 568.1181
2014-04-03 573.39 588.30 566.01 571.50 4018300 571.5000
2014-04-04 578.55 579.72 544.49 545.25 5363700 545.2500

> GOOGL = getSymbols("GOOGL", from = "2014-04-02", to = "2014-04-04", auto.assign = F)
> adjustOHLC(GOOGL)
GOOGL.Open GOOGL.High GOOGL.Low GOOGL.Close GOOGL.Volume GOOGL.Adjusted
2014-04-02 571.5216 572.973 562.5626 568.1181 4168000 568.1181
2014-04-03 573.3900 588.300 566.0100 571.5000 4018300 571.5000
2014-04-04 578.5500 579.720 544.4900 545.2500 5363700 545.2500

I do understand that this is due to the fact that `adjustOHLC` deparses its first argument. But this kind of potential pitfall should be strongly emphasized in the documentation `?adjustOHLC`, because it is not obvious at all from cursory reading. In fact, initially I (wrongly) thought that `adjustOHLC` grabs the symbol name from the column names of the `xts` object.

Alternatively (and I think this might be a better solution), one could add an attribute to the return value of `getSymbols` that keeps track of the symbol name and is later grabbed by `adjustOHLC` or other functions as needed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.