[R-SIG-Finance] Quantmod function to collect close prices into new object

Joshua Ulrich josh.m.ulrich at gmail.com
Sun Sep 12 01:02:29 CEST 2010


Please don't create duplicate posts (especially after only one day!).
You asked your question on a Friday afternoon; be patient.
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com


On Sat, Sep 11, 2010 at 5:56 PM, Keith Peter <kbpeter21 at gmail.com> wrote:
>
> Quick help question from a newbie.
>
> I have the script below where I am trying to collect the one day returns for
> many stocks into a new variable. You can see below where I have to hand
> enter the tickers into the column extraction function Cl() in quantmod. I'm
> looking for a line that recognizes the tickers already. I've tried a variety
> of things to create this code with no luck.
>
> Questions:
> 1) Is there a search feature on the R-SIG archive because I imagine this one
> has been addressed already? Going through the archive by hand is tedious.
>
> 2) What is the loop/function to recognize the length of the Tickers object
> and then feed the closing prices into the variable "closepx."
>
> 3) If I plan to do this with hundreds of stocks, is this the most efficient
> way to do it?
>
> Thanks in advance.
>
> Keith
>
> Script:
> #have an open excel sheet with QCOM,MSFT,ORCL,AAPL,IBM in column A#
> #I plan to pull the list from a *.csv file because it seems easier to hand
> enter the tickers in excel and save# Maybe there is a better way?
>
> Tickers<-read.table("clipboard")
> Tickers<-as.character(Tickers$V1)
> getSymbols(Tickers,return.class='xts',from=Sys.Date()-60,to=Sys.Date())
>
> *A function or loop (if best) that recognizes the length of Tickers and
> feeds each of them into the Cl(() to closepx.
>
> closepx<-cbind(Cl(QCOM),Cl(MSFT),Cl(ORCL),Cl(AAPL),Cl(IBM))
> head(closepx)
> clrtn<-log(closepx/lag(closepx,k=1))
> head(clrtn)
>
> On Sat, Sep 11, 2010 at 5:44 PM, Andre Barroso <andre.barroso at gmail.com>wrote:
>
> > Dear all,
> >
> > I  tried to change the Faber demo from quantstrat to include transaction
> > fees but without success. The original rule is:
> >
> > stratFaber <- add.rule(stratFaber, name='ruleSignal',arguments =
> > list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000,ordertype='market',
> > orderside='long', pricemethod='market'), type='enter',path.dep=TRUE)
> >
> > my idea was just to include TxnFees as an argument, but this was
> > ineffective:
> >
> > stratFaber <- add.rule(stratFaber, name='ruleSignal',arguments =
> > list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000,ordertype='market',
> > orderside='long', pricemethod='market'),TxnFees=-5,
> > type='enter',path.dep=TRUE)
> >
> > Any ideas of how this work?
> >
> > Thanks,
> >
> > Andre
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Finance at stat.math.ethz.ch 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.
> >
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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.



More information about the R-SIG-Finance mailing list