Strange result from "portfolio" function

Here are two alternative buy rules:
Buy1: EVAL((eval(ticker(“SPY”)&Portfolio(1314242),1,0)+eval(ticker(“spy”)&Portfolio(1451475),1,0))>=1,ticker(“SPY”),ticker(“IEF”))
Buy2: EVAL((eval(ticker(“SPY”)&Portfolio(1314242),1,0)+eval(ticker(“spy”)&Portfolio(1451475),1,0))>=1,ticker(“RSP”),ticker(“IEF”))

Both rules check whether SPY is in any of the two Portfolios and returns 1 if true and 0 if false. If the sum is greater or equal to 1 it buys SPY, otherwise IEF (for Buy1). For Buy2 it is supposed to buy RSP, but it only buys IEF, never RSP.

There is something wrong here, because the sum of the evaluation of the two Portfolio functions in each of the buy rules can only be 0, 1 or 2. This is after all just a number and should not have any influence on the ETF that is specified to be bought.

https://www.portfolio123.com/port_summary.jsp?portid=1579283



From the description for Portfolio: “Return TRUE if stock being analyzed is held in the strategy or strategies.” Each Eval statement can only look for SPY in the referenced ports while SPY is being analyzed as a possible purchase. The rest of the time the tickers are not SPY so the Evals set IEF to be purchased, I think.

So Buy2 would set ticker RSP while processing SPY, but ticker RSP would fail while being processed (not SPY and presumably not held in the referenced ports) and ticker IEF would be set for purchase. Is this the situation? If so, good luck! Perhaps make versions of the other ports that hold RSP instead of SPY? Maybe there’s another way but nothing comes to mind yet.

What should work better in this instance is a command that evaluates whether or not a given ticker is held in another port, not whether or not the ticker being considered is held in another port.

Bob,
“Return TRUE if stock being analyzed is held in the strategy or strategies.”
That is what the eval statement does. If the stock being analyzed is held in the strategy then it returns 1, otherwise 0. The subsequent decision what to buy should not have anything to do with the eval statement, because it should only consider whether the sum of the results of the two eval statements is greater or equal to 1.

Yes, Georg. But my understanding is that the Eval statement is processed for every ETF in the universe and the results will differ depending on what ETF is being analyzed. Work through what the Buy2 rule should result in when RSP is processed. The ticker being analyzed is not SPY but RSP, so the resulting Eval should be:
EVAL((eval(False&False,1,0)+eval(False&False,1,0))>=1,ticker(“RSP”),ticker(“IEF”))
Which should set IEF as the resulting ticker.

Similarly it can be shown that while SPY is being processed, RSP should result. My point is that it is not logical for RSP to remain the result when it can’t pass the rule.

I gladly apologize if this reasoning is wrong and someone can show what else is actually happening.

Does the P123 Team has any comments to this anomaly?

There is no anomaly. It is as Robert explained: you can’t expect both [font=courier new]Ticker(“SPY”)[/font] and [font=courier new]Ticker(“RSP”)[/font] to succeed in the same rule.
A workaround would be to make a custom formula for [font=courier new]Ticker(“SPY”) & (Portfolio(1314242) | Portfolio(1451475))[/font] and use it within [font=courier new]FSum[/font].

Thanks Aaron, always something new to learn on P123.
Great platform.

Aaron, thank you for your advice.
It works fine now with RSP - see chart.


Nice results, Georg. Thanks, Aaron! Glad it got figured out! Now we know how to check ports for a specific holding other than the one being processed.

And adding another portfolio from my arsenal of timers to the test gives the best SPY-IEF timer so far.
Can anybody improve on this?