Posted 5/8/2014 11:45 AM (#5852) Subject: EqtyCond: Sum of +Rtns > Sum of -Rtns
Location: USA: GA, Lawrenceville
Steve Mayo recently had a neat idea for an Equity Condition rule, and he requested some help with the formula. Apparently, the result turned out to be fairly useful, and this might become part of the Portfolio Balancer tool. He's given me permission to post it here (thanks, Steve) not only as a useful tool on its own, but also as a good example of the cool things that are possible via OScript ... (also, click here for some additional background information about Boolean Math in OmniScript)
His original request:
I want to write an OV condition that goes/stays long when the sum (or average) of the positive returns exceeds the same sum/avg of the negative daily returns.
Here's the thinking-process that I went through to arrive at the solution:
daily return as fraction = (C-C) / C
isolating the positive ones: (C>C) * (C-C)/C
isolating the negative ones: (C<C) * (C-C)/C
... for those two formulae, the first boolean-comparison term (paren's are important here) is -1 if true, 0 if false; note that the return-fraction is flipped to compensate for true= -1
adding them up - use the "sum(expression,bars)" function:
sum of positive ones in prior 100 bars: sum((C>C) * (C-C)/C, 100)
sum of negative ones in prior 100 bars: sum((C<C) * (C-C)/C, 100)
the final condition ... sum of positive > sum of negative, for prior 100 bars (before each test bar, moving forward)
I tested this on All US stocks using OScan and got 5800 hits out of 9402 live stocks ... I did not hand-check the math though ;~).
The sum function, like the HHV and LLV functions, can consume a lot of CPU time btw. I suggested 100 bars of lookback, since trades don't occur on every bar. You might want to tighten it up so the calc runs faster.
Another suggestion - consider doing an RSI:
RSI( (C-C)/C, 100 )
... since RSI tracks the consistency of moves, it might be a good (and simpler and faster) substitute
Thread moved by JimDean on 8/4/2014 8:50 AM from Markets & Methods > OmniVest, Money Mgmt & Risk Control > EqtyCond: Sum of +Rtns > Sum of -Rtns