EqtyCond: Sum of +Rtns > Sum of -Rtns
Posted 5/8/2014 11:45 AM (#5852)
Subject: EqtyCond: Sum of +Rtns > Sum of -Rtns


Posts: 3907
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[1]) / C[1]

isolating the positive ones: (C>C[1]) * (C[1]-C)/C[1]
isolating the negative ones: (C<C[1]) * (C-C[1])/C[1]
... 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[1]) * (C[1]-C)/C[1], 100)
sum of negative ones in prior 100 bars: sum((C<C[1]) * (C-C[1])/C[1], 100)

the final condition ... sum of positive > sum of negative, for prior 100 bars (before each test bar, moving forward)

sum((C>C[1]) * (C[1]-C)/C[1], 100) > sum((C<C[1]) * (C-C[1])/C[1], 100)

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[1]-C)/C[1], 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

Top of the page Bottom of the page