[R-SIG-Finance] Preventing active-neutral-active bouncing signals by staying neutral

Murali.MENON at fortisinvestments.com Murali.MENON at fortisinvestments.com
Wed Jul 8 12:38:45 CEST 2009


Folks,
 
I have a series of active (+1, -1) and neutral (0) signals, and I want
to prevent bouncing from active to neutral to active (same sign). E.g.,
if I am -1 yesterday and neutral today, I will neutralise, but if the
signal becomes -1 again tomorrow, I want to remain neutral; if it does
remain -1 the following day as well, I will accept that and go short.
 
So if I have:
 
> x <- zoo(matrix(c(1,0,1,1,0,-1,0,1,-1,0,1,1),ncol=2), as.Date(1:6))
> x
1970-01-02  1  0
1970-01-03  0  1
1970-01-04  1 -1
1970-01-05  1  0
1970-01-06  0  1
1970-01-07 -1  1
 
in the first column, I'll neutralise my position on 03-Jan-70, ignore
the new active signal on 04-Jan-70, and go long again until 05-Jan-1970;
neutral again on 06-Jan-70, but will go short on 07-Jan-70, because the
signal is opposite to what it was before I neutralised.
 
Likewise, in column 2, I'll go neutral on 05-Jan-1970 but accept the
long signal the very next day because it is opposite to my previous
position.
 
How best to convert this zoo into a new zoo with ZEROES in place of
active signals where I have determined I want to continue to remain
neutral?

In general, I may want to remain neutral for 'n' consecutive days, and
then only accept a signal in the same direction as I started with after
I get 'm' successive identical active signals; but I will accept a
signal in the opposite direction at once if it appears after the 'n'
neutrals.
 
Is there a way to code this generalisation?

(All I could think of was rather roundabout: determine the dates of
inception of each signal (separately for +1s and -1s), and if the
difference between these dates is n-1, then neutralise the signal on the
latter date. But this doesn't take care of the 'm' successive active
signals before activating.)
 
Cheers,
Murali



More information about the R-SIG-Finance mailing list