![]() |
Glanies Takahata
Follow
4 years, 1 month ago · 1142 Views
|
Dear Ivan,
I ran a Strategic Allocation backtest with 3 counters - IWDA, EIMI and BRK.B. I notice that in the Portfolio and Simulated Orders section, only 2 counters are included: EIMI (50%), IWDA (47.9%) and cash (2%). In the Positions section however, it states that as of Feb 2021, the portfolio should hold 3 counters - BRK.B (31.7%), EIMI (46.3%), IWDA (44.5%) and cash (1.9%).
Given that this is a Strategic Allocation backtest with 3 counters, shouldn't the portfolio hold 3 counters at all times based on the weight I allocated in the settings? Why then is BRK.B absent from the Portfolio section but present in the Position section?
FYI, the portfolio is set to be rebalanced on a yearly basis.
Here's the link to the results of the backtest: https://pyinvesting.com/invest/results/b1f26d1865e5492d9eb1c990fcbb780b
Also, how is the cash component determined?
Thank you!
The stock with the lowest ranking based on the signals you selected will be sold off first. For example, let's say in your backtest you specified that you want stocks with the lowest PE ratio because they are cheap relative to their earnings. If the cash allocation increases, the model will sell stocks with the highest PE ratio because it has the worst ranking based on your criteria of selecting stocks with the lowest PE ratio.
Same thing when market sentiment is bullish and when the model needs to buy stocks, it will choose the stocks with the highest ranking based on the signals you selected. In the above example, it will pick stocks with the lowest PE ratio as they will be ranked the highest.
The freqency is based on the rebalancing frequency you specify. For example, if you specify weekly frequency, the cash levels will only be adjusted once a week. So even if the fear and greed index flashes in between rebalancing periods, it will not affect the cash allocation as changes to positions will only occur during the rebalancing periods.
Hope this helps!
![]() |
Glanies Takahata
Follow
4 years, 2 months ago
|
Thanks Ivan for the explanation. I get how the function operates as per your explanation.
I'm not so clear about how selecting this function for my strategy will affect/influence my strategy.
Say I implemented a Moving Average Backtest strategy and hold a portfolio of 30 stocks. When market sentiment is bearish, how would the Cash Allocation function influence my strategy to instruct me to sell stocks to raise cash, and how would it prioritise the 30 stocks to sell? Would it be the stock with the steepest drop in price that would be sold first?
Similarly, when market sentiment is bullish, how would the Cash Allocation function influence my strategy to buy stocks - would it prioritse stocks with the steepest increase in price first?
If it does not prioritise stocks by the steepest change in prices, how does the Cash Allocation function tell me which of the 30 stocks to sell/buy then?
Also, how frequently would the the function instruct me to raise cash or buy stocks? Would it be based on the rebalancing setting chosen for the backtest, or would it do so whenever there is a change in the Fear and Greed Index?
This risk management system will look at the trends of around 200 stocks using the 6 month moving average. If a stock is above its moving average it's in an uptrend. If a stock is below its moving average it's in a downtrend. From there we find the percentage of stocks that are in an uptrend. For example, if out of these 200 stocks, 100 stocks are in an uptrend, this percentage is 50%. The system will start increasing its cash linearly when this percentage falls below 50%. The lower the percentage of stocks in an uptrend, the higher the cash allocation to protect the portfolio from experiencing large drawdowns during a crisis. It works well when markets are trending either upwards or downwards. However it performs poorly when markets are volatile because for example if it raises cash and market rebounds strongly, it will miss out on the initial rebound as it gradually reduces cash and buys stocks.
![]() |
Glanies Takahata
Follow
4 years, 2 months ago
|
Thanks for the explanation, Ivan.
Regarding point 3, could you further explain more about the Cash Allocation function? Say when market sentiment is bearish and the portfolio sells stocks and raises cash, what rules/algorithims would the portfolio follow to decide which stocks to sell? How would this function interact with or overwrite the strategy?
Hi Glanies,
1. The cash component is decided by the backester. If it sells stocks, the exceed cash will be reflected in the portfolio. If it borrows cash on leverage the cash will be negative.
2. In your backtest, some leverage was used because the rebalance band threshold is 10%. If you were to reduce this threshold to say 5%, your positions will be closer to the target allocation of 33% each.
3. The Cash Allocation function is an active risk management system that adjusts the level of cash in your portfolio based on market sentiment. When the fear and greed index is showing market sentiment is bearish, the portfolio will sell stocks and raise cash to protect the portfolio from large drawdowns. If the market sentiment is bullish, the portfolio will buy stocks and reduce cash.
Kind regards,
The PyInvesting Team
![]() |
Glanies Takahata
Follow
4 years, 3 months ago
|
Dear Ivan,
Thanks for checking and for clarifying that the issue was due to the updating of data.
Some questions:
1. Could you explain how the cash component of the portfolio is derived?
2. Additionally, could you explain how the "Cash Allocation" function works? In other backtests that I ran with that function selected, I notice that the Portfolio holds a cash component (e.g. -10%). What does a -10% cash component translate to?
3. Is there a relationship between the "Cash Allocation" function and the Fear and Greed Index, and if so, how do the two relate to each other?
Thanks!
Hi Glanies,
Can you please replace BRK.B shares with the Berkshire class A shares instead? We just tried and the results are better. Thanks.
Kind regards
The PyInvesting Team
It's because BRK.B price data only available until 1st of Feb while the other 2 instruments have data until 2nd of Feb. Hence the positions only show 2 instruments as the data for BRK.B has not been updated. There seems to be a delay for the price data for BRK.B which is causing the issue.
© PyInvesting 2025