[R-SIG-Finance] help with monthlyReturn command

Joshua Ulrich josh.m.ulrich at gmail.com
Sat Jan 21 01:11:22 CET 2012


On Fri, Jan 20, 2012 at 5:17 PM, benn fine <bennfine at gmail.com> wrote:
> I am having trouble figuring out what the monthlyReturn command is doing.
>
> That is, consider SPY
>
> getSymbols("SPY")
>
> I then do monthlyReturn(SPY)
>
> 2011-10-31     0.109147150
> 2011-11-30    -0.004063745
> 2011-12-30     0.004080326
> 2012-01-19     0.047490040
>
> hmmm. November is negative.....
> On Nov 1, Spy closed at 121.23 (adjusted close)
> On Nov 30, Spy closed at 124.20 (adjusted close)
>
> This gives a return for November of (124.2/121.23)-1 = 2.45%
>
> For October
> Oct 3, SPY = 109.24
> OCT 31, SPY = 124.71
>
> This gives a return for October of (124.71/109.24)-1 = 14.17%
>
> Can anyone please explain the discrepancy? Am I defining monthly returns
> incorrectly?
>
Yes.  You're omitting the return that occurs on the first day of the
month (between 10/31 and 11/1 in your first example).
121.23/124.71-1 = -0.02790474
124.20/124.71-1 = -0.004089488

--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-SIG-Finance mailing list