FRank with custom variable works in the screener but not in sim

I tried to run a sim and entered the following functions:

SetVar(@ROE_RankScore, FRank(“ROE%TTM”,#All,#DESC) )
SetVar(@EBIT_Margin_RankScore, FRank(“OpMgn%TTM”,#All,#DESC) )
SetVar(@rankscore_sum,@ROE_RankScore + @EBIT_Margin_RankScore)

Finally to sort stocks based on my custom variable “@rankscore_sum” and to return the top 30%, I used the buy rule: FRank(“@rankscore_sum” , #all, #DESC) >70

But after that when I tried to run my sim I got the notification“Value not set for temp variable @rankscore_sum…" I don´t know what I did wrong, because in the screener all rules above work like a charm.

Perhaps somebody can help why these rules work in the screener but not in the sim?

I’m guessing it’s still the “optimization” issue lingering; https://www.portfolio123.com/mvnforum/viewthread_thread,7244#36185

Walter

EDIT: I think you can make this work in a simulation if you;

  1. make custom formulas $ROE_RankScore, $EBIT_Margin_RankScore and $rankscore_sum
  2. create a ranking system that calls $rankscore_sum - let’s name the ranker “rankscore_sum”
  3. use Rating(“rankscore_sum”)>70 in the simulation

I tried that in the screener and the results are nearly identical to your SetVar version. For some reason, one or two stocks get dropped.

I suspect putting everything in a ranker would work, too.

Looks okay to me. I tried in a sim; no issues running it. Where do you referencing “@rankscore_sum” in your buy rules?

Walter and Primus, thanks very much for taking your time to help me solving this problem.

Walter, yes your mentioned thread from 2014 seems to refer to the same problem I have. Your suggested workaround seems to be a good compromise to handle this problem… I will try it and see how it works in my sim. But of course it would be better if this issue could be fixed. Therefore I would be glad to hear from Marco if this issue can possibly be fixed in the near future.

Primus, did you have no issues running a sim while using my buy rules or did you refer to Walter´s workaround?

@Michael,

I have no issues running a port sim with the rules as you’ve printed them. I am just wondering if its possible that @rankscore_sum is accidentally mentioned before it is defined in your rules. I’ve done that more than a few times.

//dpa

ok, now I understand. In the first 3 buy rule lines I entered my printed 3 SetVar functions, so the variable @rankscore_sum should be sufficiently defined. And in the fourth line I set up my buy rule “FRank(”@rankscore_sum" , #all, #DESC) >70".
But If I replace this FRank buy rule with let´s say "@rankscore_sum > 150, then everything works.

Oops. I totally mentally skipped that part of your explanation. Please forgive!

Anyway, I have the same problem you have. I believe that cross-sectional analysis on a custom variable in the the Screener is also not possible unless the #Previous scope parameter is used. The #previous parameter, however, is not defined for portfolios because, as Marco, put it:

See: Feature Request: Enable Use of #Previous Scope for FRank, FOrder and Similar for Simulations

Thanks for your hint regarding the #previous parameter, but I also tested the same rules in the screener and here the FRank-function with the scope parameter “ALL” (FRank(“@rankscore_sum” , #all, #DESC) >70) works without any problems.

Perhaps Marco can say something about this issue.

Portfolios and simulations evaluate all cross-sectional functions first, regardless of interleaved rules. This includes FRank, FMedian, FCount, FSum, FOrder, ZScore, and Aggregate.
We don’t support anything like composite ranking via these functions, its efficacy in the screener being a side-effect of the way the screener evaluates criteria.

Currently, the only supported way to build a composite ranking is by leveraging a ranking system. You may reference up to 3 auxiliary ranking systems from a model by specifying its name in the [font=courier new]Rating[/font] function.

I realize that I might be missing something, but if someone asked me how to rank two factors concurrently, I’d recommend plunking them both in a ranking system and getting a beer. Your manual rank_score thing as described is pretty much is doing exactly what a ranking system with two nodes would do.

And by the way, if you need to combine two ranking systems, it’s ugly, but this should work:

Create a new ranking system. Add two composite nodes, one called Ranking System 1 and one called Ranking System 2. (Or, y’know…whatever.) :slight_smile:

Then go to the first ranking system in another window and looking at the Factors page, you should be able to see the Text Editor link above it. Click it and then copy everything that’s between the node at the top and the at the bottom. You can close that window.

Go back to your earlier window and the Text Editor. Paste everything that you just copied between the first <Composite Name=“Ranking System 1” Weight=“0%” RankType="Higher and the first .

Then repeat with your second ranking system and your second composite node. Then save up at the top and go back to Factors and you’ll have a ranking system that combines two (or more, if you’d like) ranking systems. My general experience is that combining a big bunch of nodes isn’t going to improve performance much, just to warn you, but this is how I’d combine ranking systems for a portfolio.

Thank you Aaron & Paul for your detailed explanations and support.