Message-ID: <CAPPM_gTO-YeOaDy3yG-RwWrm3v-yuzm2v2-sf1DL2GEoTC=5PA@mail.gmail.com>
Date: 2011-09-27T12:54:17Z
From: Joshua Ulrich
Subject: SMA & large n
In-Reply-To: <CAGejiYbb6mLSUX+zHe-0WnWgMU0b0T_jZWYWpX64XWag3+97yw@mail.gmail.com>
After the call to to.monthly(), SPY only has 180 rows. Quite simply,
you can't take a 377-period MA of a series that only has 180
observations.
--
Joshua Ulrich ?| ?FOSS Trading: www.fosstrading.com
On Tue, Sep 27, 2011 at 7:42 AM, Anna Dunietz <anna.dunietz at gmail.com> wrote:
> Hi List!
>
> I would like to calculate the 377-day simple moving average on closing
> prices using the SMA function, but an error is always returned:
>
>
>
> SMA(Cl(SPY),n=377)Error in runSum(x, n) : Invalid 'n'
>
>
>
> Here is some code in order for you to quickly reproduce what I am doing:
>
>
>
> getSymbols("SPY", from='1995-01-01', to='2010-01-01',
> index.class=c("POSIXt","POSIXct"))
>
> SPY = to.monthly(SPY, indexAt='endof')
>
> mysma<-SMA(Cl(SPY),n=377)
>
>
>
> Thank you very much!
>
>
>
> Anna
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>