[R-SIG-Finance] [R] Quantstrat package question

Brian G. Peterson brian at braverock.com
Sun Aug 28 17:17:57 CEST 2011


Sorry, the function should only return the indicator, not all the
columns of mktdata too.   You'll need to modify it to only return the
indicator, or I'll try to get to it tomorrow.


On Sun, 2011-08-28 at 16:36 +0900, 이원재 wrote:
> Dear Brian,
> 
> 
> I tried the custom indicator, 'indiMerge', and it seems that I was
> mistaken 
> 
> 
> From the codes:
> 
> 
> indMerge <- function(mktdata=quote(mktdata),x){
> if (!is.xts(x)) x <- getSymbols(x, auto.assign = FALSE)
> x <- cbind(mktdata, x[paste(first(index(mktdata)) ,
> last(index(mktdata)) , sep='/')])
> x <- na.locf(x)
> x
> }
> 
> 
> the output 'x' of  indMerge will be mktdata with merged-in reference
> data.
> 
>  
> 
> So, I tried add.indicator codes like  below and  got error messages :
> 
> 
> stratTest <- add.indicator(strategy = stratTest, name = "indMerge", 
>   arguments = list(mktdata=quote(mktdata),x=dailyindex) ) 
> Error in if (inherits(sret$indicators, "xts") & nrow(mktdata) == nrow(sret$indicators)) { : 
>   argument is of length zero
> 
> 
> 
> stratTest <- add.indicator(strategy = stratTest, name = "indMerge", 
>   arguments = list(x=dailyindex)
> Error in merge.xts(..., all = all, fill = fill, suffixes = suffixes) : 
>   object is not a matrix
> 
> 
> Obviously, the dailyindex is a matrix.
> 
>  
> 
> I am not sure how to use 'indMerge'  function and call the output 'x'
> which has merged-in data.
> 
> 
> Can you show me an example?
> 
> 
> 
> Thanks for your help.
> 
> 
> 
> Wonjae
> 
> 
> 
> 
> 
> -----Original Message-----
> From: "Brian G. Peterson"<brian at braverock.com> 
> To: "이원재"<wjlee2002 at naver.com>
> Cc: r-sig-finance at r-project.org
> Sent: 11-08-27(토) 23:37:17
> Subject: Re: [R-SIG-Finance] [R] Quantstrat package question
> 
> On Sat, 2011-08-27 at 22:20 +0900, 이원재 wrote:
> > Hi, 
> > I am working on Quantstrat package. 
> > I would like to ask if it is possible to use reference data in the
> qunatstrat packages.
> 
> Of course you can.
> 
> > For example, my market data for trading is 'intra-day' data, and I
> need to use daily indicators which are computed with 'daily' index
> data like S&P 500.
> 
> You'll need to have your indicator function look up and merge for you.
> 
> > But, in this packages, every data has to be a trading symbol in
> order to be called by functions such as 'add.indicator' and
> 'add.signal'.
> 
> The trading data is all symbols that you will trade, correct, but your
> indicator and signal functions can take any arguments.
> 
> > Is is possible to use indicators from reference data, especially in
> a different time frame with trading symbols?
> 
> 
> I think you're going to want to write a quick custom indicator,
> something like:
> 
> indMerge <- function(mktdata=quote(mktdata),x){
> if (!is.xts(x)) x <- getSymbols(x, auto.assign = FALSE)
> x <- cbind(mktdata, x[paste(first(index(mktdata)) , 
> last(index(mktdata)) , sep='/')])
> x <- na.locf(x)
> x
> }
> 
> This works for me to merge in the columns of SPY from yahoo to a tick
> data series.
> 
> I often do similar things for strategy parameters that can change
> daily,
> I just merge them and na.locf so that they'll be availabe at every
> timestamp internally. Not the most memory-efficient, but simplifies
> many other things so that I don't have to write some many custom
> functions later in the stack.
> 
> Regards,
> 
> - Brian
> 
> -- 
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
> 
> 
> 
> 
> 
> 
> 

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list