Quantcast

SMA & large n

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

SMA & large n

Duny
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SMA & large n

Joshua Ulrich
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SMA & large n

Dirk Eddelbuettel
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SMA & large n

BBands
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [SPAM] - Re: SMA & large n - Email found in subject

David Reiner
I suppose an interface to Wikipedia might be possible? http://en.wikipedia.org/wiki/377_%28number%29#370s
"377 = 13 × 29, Fibonacci number, sum of the squares of the first six primes."

Not directly in answer to your question, but I have found these sites very useful for decimals and sequences:

Plouffe's Inverter (for decimals) 3.141592653589793238462: http://pi.lacim.uqam.ca/eng/
and
On-Line Encyclopedia of Integer Sequences(tm) (OEIS(tm)): http://oeis.org/

Hope this helps someone sometime,
-- David


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of BBands
Sent: Tuesday, September 27, 2011 11:51 AM
To: R-sig-finance
Subject: [SPAM] - Re: [R-SIG-Finance] SMA & large n - Email found in subject

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.


This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, "XR Content") are confidential and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are protected by intellectual property laws.  Without the prior written consent of XR, the XR Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of XR or its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

_______________________________________________
[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.
Loading...