int64
int64

Reputation: 91

quantstrat enable.rule not working

When I use enable.rule I cannot override the rule's internal enabled=FALSE.

For example:

## Stop Loss Rule
stratstocky <- add.rule(stratstocky,
                        name = "ruleSignal",
                        arguments = list(sigcol = "sdH", 
                                         sigval = TRUE,
                                         replace = FALSE,
                                         orderside = "long",
                                         ordertype = "stoptrailing",
                                         tmult = TRUE,
                                         threshold = quote(stopLossPercent),
                                         orderqty = "all",
                                         orderset = "ocolong"),
                        type = "chain",
                        parent = "getLong",
                        label = "StopTrailingLong",
                        enabled = FALSE
)

When I place this code before applyStrategy:

enable.rule(stratstocky, type="chain", "StopTrail", enable=TRUE)

The rule will not become enabled or active. The only way to activate the rule it to change it's internal enable to TRUE. I have tried exact spelling but it is not working for me.

This is not a big issue as I can just parameterize the rule's internal enable and control it this way but would prefer to use the existing code to run my system.

Any insight into enable.rule issues?

Upvotes: 4

Views: 185

Answers (1)

Brian G. Peterson
Brian G. Peterson

Reputation: 3600

Your example is not reproducible, but I can reproduce your problem with some assumptions.

It appears that you are mixing up store=TRUE and store=FALSE

Your add.rule call appears to assume store=FALSE, and then you pass your stratstocky object to enable.rule.

When store=FALSE , enable.rule will return the strategy object. I believe that in your use case, you probably want:

stratstocky <- enable.rule(stratstocky, type="chain", "StopTrail", enable=TRUE)

to update your object with the now-enabled rule.

To create a reproducible example, try

demo('macross',ask=FALSE)

which will run the demo, and create some objects. Like what I presume to be your example, the macross demo uses store=FALSE.

now:

stratMACROSS <- enable.rule(stratMACROSS,type='exit',label='ruleSignal.rule',enable=FALSE)

will disable the exit rule, and

stratMACROSS <- enable.rule(stratMACROSS,type='exit',label='ruleSignal.rule')

will enable it again.

Upvotes: 5

Related Questions