Search code examples
rquantmod

R Quantmod discrepency in yearlyReturn based on adjustOHLC() and Ad()


based on the below two calculations I get numbers that are very close but there is a minor difference. Is this due to rounding? (Data is downloaded from Yahoo)

getSymbols("0005.hk")
yearlyReturn(Ad(`0005.HK`))
             yearly.returns
2007-12-31    -0.06995571
2008-12-31    -0.43571264
2009-12-31     0.22058512
2010-12-31    -0.10458219
2011-12-30    -0.25523618
2012-12-31     0.38690270
2013-12-31     0.04151717
2014-12-31    -0.11737805
2015-12-31    -0.15820108
2016-01-06    -0.04281099
yearlyReturn(adjustOHLC(`0005.HK`))
             yearly.returns
2007-12-31    -0.07190533
2008-12-31    -0.43571057
2009-12-31     0.22058133
2010-12-31    -0.10457942
2011-12-30    -0.25523699
2012-12-31     0.38690493
2013-12-31     0.04150802
2014-12-31    -0.11737174
2015-12-31    -0.15820416
2016-01-06    -0.04281099

getSplits("0005.hk")
[1] NA

Using quantmod version 0.4-5 and R version 3.2.3


Solution

  • Yes, it's due to rounding. The adjusted column in the raw Yahoo data only has 3 decimal places of precision. The calculated adjusted prices have more precision. To illustrate:

    R> head(merge(Ad(`0005.HK`),Cl(adjustOHLC(`0005.HK`))))
               X0005.HK.Adjusted X0005.HK.Close
    2007-01-01           135.014       135.0135
    2007-01-02           135.961       135.9610
    2007-01-03           137.098       137.0980
    2007-01-04           136.245       136.2452
    2007-01-05           135.866       135.8663
    2007-01-08           134.824       134.8240