[R-SIG-Finance] Customized indicator for quantstrat
me
me at censix.com
Sat Dec 15 11:26:42 CET 2012
On Fri, 14 Dec 2012 23:56:08 -0500
"Robert A'gata" <rhelpacc at gmail.com> wrote:
> Hi,
>
> I am trying to learn how to create customized indicator. Mostly I
> have my own recipe which TTR does not cover. I only know that the
> indicator function is supposed to return xts. But I couldn't get it
> to work on my example. I attached the file here. The customized
> indicator function is called "devCalc" which calculates deviation
> between current price and a given VWAP. Then normalized with
> volatility. I named the indicator as "dev" in add.indicator's label.
> R complains that no "dev" found when I try to use it to define my
> signal. Any help would be appreciated. Thank you.
Robert
I think I have encountered this problem before. For some reason, you
have to make sure that the 'devCalc' function that calculates your
indicator returns an xts object *with the correct column names*. In your
case, I think you should do something like this.
devCalc(...){
...
colnames(res) <- 'dev'
return(res)
}
For some reason, the label="dev" argument in the declaration below is
not enough.
stratVwap <- add.indicator(strategy=stratVwap,name="devCalc",
arguments=list(price=quote(mktdata$price),
vwap=quote(mktdata$vwap)),
label="dev");
Cheers
------------------------------------------------------------------
Soren Wilkening
http://censix.com
More information about the R-SIG-Finance
mailing list