2 types of stock with different buy, ranking and sell rules in same sim? Counting number of stocks in a universe

Good morning,

I am trying to do the following and I am asking for your help in order to see if this can be implemented.
On the strategies sim, on a daily basis I am acquiring stocks (stocks type 1) which are sold once their rank and momentum is not appropriate anymore.

I would like to acquire different stocks (stocks type 2), with different buy rules and ranking than stock type 1, when (a) the number of stocks existing in the universe is sufficient (let’s say 25 stocks) and (b) maybe also according to the momentum of the market.
Stocks type 1 would be sold when these conditions (a) and (b) arise to buy these stocks type 2.
Stocks type 2 should be sold according to a different rule (likely time ownership of 1 year).

Then either stocks type 1 or stocks type 2 would be acquired depending on the number of stocks type 2 available in the universe.

I am not sure how to test such a strategy:
• How to calculate number of stocks answering to said characteristics in the universe (or creating a different universe and counting the number of stocks)
• How to buy/sell different types of stocks with different rules
• Etc.

Maybe my idea would have been to create 2 strategy sims with inverse hedge rules and try consolidate them in a book but the book seems only to allow rebalance mechanics and there would be no more possibility to test with rolling periods.

Julian

Hi Julian, I don’t know the answer and haven’t done what you describe, but a couple of functions that may be involved.

NodeRank()
https://www.portfolio123.com/doc/doc_detail.jsp?factor=NodeRank&popUpFullDesc=1

Portfolio()
https://www.portfolio123.com/doc/doc_detail.jsp?factor=Portfolio&popUpFullDesc=1

PosCnt()
HoldingsCnt()

Before I attempt to answer this, I would just like to get things clear. Would you be continuing to use the first strategy if the conditions are met for the second or would you switch the strategies altogether? If you’d be continuing to use the first strategy with the second as well, how would you divide your portfolio between the two strategies?

I’m not sure that such a complicated strategy can be effectively simulated on Portfolio123. If you’re planning to switch strategies altogether, then using the Portfolio() command would be essential . . . but I think I’d need more details before answering fully.

I have a few thoughts on this.

First, the book combines two strategies in a set percentage. You can set both of the underlying strategies to go to cash under certain, presumably mutually exclusive conditions. In our system cash has a return of zero (which has been a pretty good assumption for the past decade or so). This means that the returns of the liquidated strategy would not affect the other portfolio’s returns during the period that it was active.

Second, I have in the past helped someone create a custom formula that was all of the sell rules of the the portfolio for use in the buy rules. The idea was that they absolutely, positively did not want even the Buy/Sell Difference transactions in their strategy, so they used the sell-rule formula in their buy rules to check before buying anything: If a stock would meet the sell rules at the time of purchase, don’t buy it.

You could, theoretically, do that for a completely different portfolio, or in an Eval function. That is:

Eval(<some logical test>,$SellRules1,$SellRules2)

The trick is that in all likelihood your sell rules would go from implied-or to implied-and unless you constructed the formulas juuuuuuust right.

Finally, I think that you might need FCount and the Portfolio function:

FCount("Portfolio(number here)")<5

I agree with Yuval that this might be beyond us, but I’d be willing to pitch in and try to solve it. My email address is paul@portfolio123.com if you want to take this private so that you can get into more detail. (And the devil is likely to be in the details.)

Good morning,

The idea is to switch from a strategy to the other.
Strategy 1 is default one.
Strategy 2 applies mainly when there are enough stocks existing (“condition 2”) for applying strategy 2.
Then when the stocks of strategy 2 are sold (let’s say after 1 year), it should check if “condition 2” is met or not.
If “condition 2” is met, then Strategy 2 again.
If “condition 2” is not met then Strategy 1 by default.

If “condition 2)” is met at any point again, we go back to strategy 2.

Thank you Paul.
I will email you.

Thank you.
I will look at these functions.