Aaron and I discussed this for a while. Jrinne’s solution is the best that we came up with, with the addition of setting Allow Immediate Repurchase to Yes. Then you can just set your sell rules to True (to always sell) and take the net transactions.
We had some theoretical ways around it, but they’re so much work relative to Jrinne’s solution and accepting the adjustment transactions that it doesn’t seem worth it.
If you want to play around with them, I have, in the past, helped someone set up a custom formula that encompasses all of the buy rules into a single formula. Basically, it would be a series of custom formulas that feeds into a single custom formula that would resolve to either true or false. It would be true if all of the buy rules are true – meaning that the given stock would pass the buy rules – or false if any were false. It can be used in a sell rule to evaluate whether a stock would pass the buy rules now.
It looks like this:
$BuyRule1
MktCap>2000
$BuyRule2
ROE%TTM>5
$BuyRules
$BuyRule1*$BuyRule2
A quirk of the system is that a true inequality resolves to one and a false inequality resolves to zero. So $BuyRules is going to be true only when both $BuyRule1 and $BuyRule2 are true.
The other idea is that the Portfolio function might help. It will be true for any given security that is in the Portfolio, and can be used to evaluate in the Portfolio itself. It is worthless in a sell rule – the sell rules only evaluate for stocks in the portfolio anyway – but it might be handy in a buy rule.
My initial thought was something like:
Portfolio(blah blah) and RankPos<10
as a sell rule, but that is exactly identical to RankPos<10, so there’s no point to it.
The offshoot was that we couldn’t come up with a more precise and practical solution that is better than just moving whatever buy rules that you can to a universe, and then setting both Allow Immediate Repurchase and Force Positions Into Universe to yes.
Oh, and I think, separately, that I should emphasize that the portfolio algorithm attempts to be fully invested at all times. The problem of “there’s no other stock to invest in” is rare. So rare, in fact, that if you’re seeing it, I would consider how restrictive your rules are and maybe ease up a little.