[R-SIG-Finance] Please help in a trade rule based on obv
Brian G. Peterson
brian at braverock.com
Sun Apr 3 13:07:47 CEST 2011
On 04/02/2011 06:45 PM, xri pro wrote:
> Hi to all
> I am new to R and I would like to test the scenario that it is mentioned to
> this paper "Tsang, William Wai Him and Chong, Terence Tai Leung, (2009),
> Profitability of the On-Balance Volume Indicator, Economics Bulletin, 29,
> issue 3, p. 2424-2431."
> The trading rule examined in the paper is the crossover of OBV and its
> simple 20-day moving average (OBVMA).
> Trading Rule
> Buy at day t: OBVt-1< OBVMAt-1 and OBVt> OBVMAt
> Buy at day t: OBVt-1> OBVMAt-1 and OBVt< OBVMAt
> long position is taken when OBV rises above its 20-day moving average, and
> the position is
> liquidated once OBV drops below the 20-day OBVMA .
> So far i managed to write a few lines for the script of this trading rule
> because just i said above i am new to R
> Here are the commands
> getSymbols("GEK.AT", from="2006-01-01")
> obv<- OBV(Cl(GEK.AT), Vo(GEK.AT))
> obvma.20<- SMA(obv, n=20)
> I would like to help me to write the commands
> 1)for the trade rule,
> 2)to show up the plots of the obv and the obvma in the same graph and
> 3)the outcome of this trade rule.
The 'TTR' package has OBV and MA functions.
'quantmod' has chartSeries and chart_Series that will let you chart
price/volume information along with your OBV and OBVMA indicators.
You can see some excellent blog posts by Josh Ulrich on backtesting
trading ideas 'by hand' in R, or the 'quantstrat' has functions for
merging all this into a full strategy definition containing indicators,
signals, and rules, It also has several demo strategies that, if
examined, should give you an idea of how to construct the OBV strategy
that you describe above.
More information about the R-SIG-Finance