quantstrat help
Thanks Josh, Ilya, Nick. I will start on those lectures of Guy. Josh> Thx for correcting the vectorization part of the code. It is a steep curve indeed but enjoyable! Best Rgds Raghu
On Fri, Oct 17, 2014 at 2:06 PM, Nick White <n-e-w at qtradr.net> wrote:
Raghu, I highly recommend you start with Guy Yollin's excellent lectures @ http://www.r-programming.org/papers Begin with understanding the `blotter` package. Guy's notes then proceed onto quantstrat and each successive lecture introduces progressively more advanced features. Lecture 1 will more than sufficiently cover what you're trying to do. There's a learning curve to quantstrat -- but if you follow Guy's lectures it will be about as painless as its possible to be. n. On Fri, Oct 17, 2014 at 11:31 PM, Raghuraman Ramachandran <optionsraghu at gmail.com> wrote:
Thx Josh.
Here is the code:
require(quantmod)
require(TTR)
getSymbols('^GSPC')
colnames(GSPC)=c("Open","High","Low","Close","Volume","AdjPrice")
for (i in 1: nrow(GSPC))
{
GSPC$signal[i]=ifelse((GSPC$Close[i]>1.02*GSPC$Open[i]), 1
,ifelse(GSPC$Close[i]<= 0.98*GSPC$Open[i], -1, 0))
}
So there will be consecutive days of longs or shorts but how to ignore
the subsequent signals and take the first occurrences inside
quantstrat pls?
Rgds
Raghu
On Fri, Oct 17, 2014 at 12:50 PM, Joshua Ulrich <josh.m.ulrich at gmail.com>
wrote:
On Fri, Oct 17, 2014 at 4:37 AM, Raghuraman Ramachandran <optionsraghu at gmail.com> wrote:
Dear guRus I am trying to understand the quantstrat package. My signal is very simple. I want to buy if daily close > 2% of open and vice versa. But my signals produce consecutive 1s (when market is going higher) and -1s (when market is going lower) so I want to avoid buying (or selling) more if already bought or sold.
Then only take the first signal. If you want more specific instructions about how to do that, then provide more specific details about your problem (e.g. your actual code).
My question is: Is it possible to tell quantstrat a) Please do not buy if already bought and if a new buy signal appears and b) Please buy even though if already bought and a new signal appears.
a) Yes. b) Yes.
Also, when a leave a trailing stop which takes precedence? A trailing stop or a new signal on the opposite side and is it possible to change this precedence please?
Rules are processed in the order described in the Details section of ?add.rule. You can change the order, but it is strongly discouraged because it's very easy to create unrealistic behavior if you modify the order incorrectly.
Sincere thanks for the guidance, Raghu
-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com
_______________________________________________ R-SIG-Finance at r-project.org 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.