[R] vectorizing a double loop

2009-05-31 Thread wapita wapita

Hello,

I have to build a function that takes a time serie and calculate the momentum. 
For each date of the serie, I have to build a loop to calculate it using the 
last few data.

My problem is that it takes one minute to compute and I need to run this 
function very often.
I would like to vectorize it, as much as possible. 

Can somebody help me? I have read the 
http://www.burns-stat.com/pages/Tutor/R_inferno.pdf tutorial but it seems I am 
not smart enough to vectorize this.

here is the code of my function:



momentum = function(price,H,N,HL) {

indicator = price#creates the empty 
vector for the indicator
indicator[,1]=0

if ((H/N)==floor(H/N)) {#Checks if length 
of subperiods is an integer

for (i in 1:(length(indicator)-H)) {
ph=last(price,H+1)#Horizon time data 
list
horizonPerformance=as.numeric(last(ph))/as.numeric(first(ph))-1
#Performance over the time horizon
for (j in 1:N) {
phj=last(first(ph,(N-j+1)*H/N+1),H/N+1)#subperiod 
data list
periodPerf=as.numeric(last(phj))/as.numeric(first(phj))-1
#Performance over period j
if (periodPerf*horizonPerformance>0)#checks 
consistency with time horizon perf 

indicator[length(indicator)-i+1,1]=indicator[length(indicator)-i+1,1]+sign(periodPerf)
}
price=last(price,-1)#shift the data list
}

}

return(indicator)
}

_
Inédit ! Des Emoticônes Déjantées! Installez les dans votre Messenger ! 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Decompose function : calculation of each component

2009-07-07 Thread wapita wapita

as tu lu l'article suggere dans l'aide:
M. Kendall and A. Stuart (1983) The Advanced Theory of Statistics, Vol.3, 
Griffin, 410–414. 


> Date: Mon, 6 Jul 2009 13:22:17 -0700
> From: m.gha...@yahoo.fr
> To: r-help@r-project.org
> Subject: [R]  Decompose function : calculation of each component
> 
> 
> Hello,
> 
> I'd like to know how R does calculate each component in the decompose()
> function? 
> More precisely, how is calculated the final trend component in this
> function?
> 
> Thanks for your answer
> Myriam
> -- 
> View this message in context: 
> http://www.nabble.com/Decompose-function-%3A-calculation-of-each-component-tp24362207p24362207.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

_

[[elided Hotmail spam]]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fitting a trend-line

2009-07-08 Thread wapita wapita

Why dont you do a linear regression?

> Date: Wed, 8 Jul 2009 15:01:19 +0530
> From: anupam.cont...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Fitting a trend-line
> 
> Hi all,
>  I am new to R. How does one go about fitting a trend-line to a
> scatter plot? Any help is appreciated.
> 
> Thanks and regards,
> 
> Anupam
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

_

[[elided Hotmail spam]]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] RODBC and sqlSave issue

2009-07-08 Thread wapita wapita







Hello,

I contact you after having unsuccessfully asked my question to R mailing list. 

I use the package RODBC to connect to a MS-SQL server. 
I am able to getQuery from the database.

I
am now studying the sqlSave some data into the database. Unfortunetly,
I meet some issues relating to the format of the data that arrives into
the database. I have three columns. The first one should be in the
MS-SQL format "datetime". The second one in the MS-SQL format
"varchar(50)", and the third one in the MS-SQl format "numeric(20,8)".




I use the following command line:
> sqlSave(channel, DF, tablename="essai_global", rownames=FALSE, oldstyle=FALSE)

The data is indeed send to the database. But the types are wrong (varchar(255) 
pour les trois colonnes.)

I have then tried to use the varTypes argument, but I do not manage to use it.

If I use the following command lines:
> varTypes=c("datetime","varchar(50)","numeric(20,8)")
> sqlSave(channel, DF, tablename="essai_global", rownames=FALSE, oldstyle=FALSE)



I have the following resturn:

Warning message:
In sqlSave(channel, DF, tablename = "essai_global", rownames = FALSE,  :
  argument 'varTypes' has no names and will be ignored



and the types are still wrong..

How can I use the varTypes??? I have read the documentation, but I dd not 
manage to find out.

Thank you very much

Wapita
_

r  !  Téléchargez-le maintenant ! 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] change capital to small letters?

2009-07-08 Thread wapita wapita

Hello R users,

 

I have a string of characters in capital letters and I need to convert it in 
small letters, is there an easy way to do it?

 

Thanks a lot

 

Wapita

_
Découvrez toutes les possibilités de communication avec vos proches

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] change capital to small letters?

2009-07-08 Thread wapita wapita

ok, find!

 

?toupper

?tolower

 

sorry!!! (but you have perhaps learned something...)
 


From: wap...@hotmail.com
To: r-help@r-project.org
Subject: change capital to small letters?
Date: Thu, 9 Jul 2009 03:07:35 +



Hello R users,
 
I have a string of characters in capital letters and I need to convert it in 
small letters, is there an easy way to do it?
 
Thanks a lot
 
Wapita



Découvrez toutes les possibilités de communication avec vos proches
_

r  !  Téléchargez-le maintenant ! 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] adjusting grid on Xaxis ticks

2009-07-23 Thread wapita wapita

Hello,
I have been trying to plot correctly a graph for 2 month now, with no success.I 
want to put a grid, adjusted on the X axis tickers.
Here is the way I build my X-Axis and my grid:


grid(11, NULL, col="grey40")
axis(2)  

# build the tickers on the beginning of each monthticks.at <- 
seq(ISOdatetime(lastYear, 01, 01, hour=0, min=0, sec=0, tz="GMT"), 
ISOdatetime(lastYear, 12, 31, hour=0, min=0, sec=0, tz="GMT"), by = "months")
ticks.lab <- format(ticks.at, format = "%b")
Axis(ISOdatetime(lastYear, substr(index(xts1),6,7), substr(index(xts1),9,10), 
hour=0, min=0, sec=0, tz="GMT"), at = ticks.at, side = 1, labels = ticks.lab, 
las = 2)
box()


If anyone can help me, I would be very grateful.
Xavier
_

[[elided Hotmail spam]]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] adjusting grid on Xaxis ticks

2009-07-30 Thread wapita wapita

Thank you j, its perfect!!
Wapita

> Date: Fri, 24 Jul 2009 06:41:16 -0400
> Subject: Re: [R] adjusting grid on Xaxis ticks
> From: jholt...@gmail.com
> To: wap...@hotmail.com
> CC: r-help-boun...@r-project.org; r-help@r-project.org
> 
> is this what you want:
> 
> plot(0, xlim=as.POSIXct(c('2009-01-01', '2009-12-31')), xaxt='n')
> x <- seq(as.POSIXct('2009-01-01'), as.POSIXct('2009-12-13'), by='1 month')
> axis(1, at=x, labels=format(x, "%b"))
> abline(v=x, lty=2)
> 
> 
> On Thu, Jul 23, 2009 at 11:37 PM, wapita wapita wrote:
> >
> > Hello,
> > I have been trying to plot correctly a graph for 2 month now, with no 
> > success.I want to put a grid, adjusted on the X axis tickers.
> > Here is the way I build my X-Axis and my grid:
> >
> >
> > grid(11, NULL, col="grey40")
> > axis(2)
> >
> > # build the tickers on the beginning of each monthticks.at <- 
> > seq(ISOdatetime(lastYear, 01, 01, hour=0, min=0, sec=0, tz="GMT"), 
> > ISOdatetime(lastYear, 12, 31, hour=0, min=0, sec=0, tz="GMT"), by = 
> > "months")
> > ticks.lab <- format(ticks.at, format = "%b")
> > Axis(ISOdatetime(lastYear, substr(index(xts1),6,7), 
> > substr(index(xts1),9,10), hour=0, min=0, sec=0, tz="GMT"), at = ticks.at, 
> > side = 1, labels = ticks.lab, las = 2)
> > box()
> >
> >
> > If anyone can help me, I would be very grateful.
> > Xavier
> > _
> >
> > [[elided Hotmail spam]]
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?

_

[[elided Hotmail spam]]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.