# SMA & large n

5 messages
Open this post in threaded view
|
Report Content as Inappropriate

## SMA & large n

 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]] _______________________________________________ [hidden email] 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.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: SMA & large n

 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 <[hidden email]> 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]] > > _______________________________________________ > [hidden email] 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. > _______________________________________________ [hidden email] 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.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: SMA & large n

 In reply to this post by Duny On 27 September 2011 at 14:42, Anna Dunietz wrote: | 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) Monthly data from Jan 1995 to Jan 2010 covers 181 months:    R> mm <- seq(as.Date("1995-01-01"), as.Date("2010-01-01"), by="month")    R> head(mm)    [1] "1995-01-01" "1995-02-01" "1995-03-01" "1995-04-01" "1995-05-01" "1995-06-01"    R> length(mm)    [1] 181    R> You cannot run a moving average of length 377 over 181 observations.   Maybe the magic number 377 came from daily data and you now want something like 377 / 21 or about 18? Dirk -- New Rcpp master class for R and C++ integration is scheduled for San Francisco (Oct 8), more details / reg.info available at http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php_______________________________________________ [hidden email] 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.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: SMA & large n

 On Tue, Sep 27, 2011 at 6:02 AM, Dirk Eddelbuettel <[hidden email]> wrote: > Maybe the magic number 377... That magic number is the 14th Fibonacci number, which raises an interesting question. Is there an R resource that allows one to enter a number and returns a list of which common number series it belongs to? For example 377 is a member of the Fibonacci series, an odd number, but it is not prime. Best, John _______________________________________________ [hidden email] 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.