Hi,
I’m attempting to write portfolio rebalancing code for a portfolio backtest.
On the last bar of each month, I wish to evaluate the portfolio and rebalance based on some code I have written to determine what percentage of capital should be invested in each symbol.
What I need is:
1) For each symbol, if I have an open position, what is the total liquidation value of the position?
PositionValue = close * CurrentShares;
(This works fine)
2) What is the total liquidation value of the portfolio including cash?
PortfolioValue = ????
(I don’t know how to get this)
From these two values, I can calculate whether I need to buy or sell the security to get the allocation I need.
I don’t know how to get the total portfolio value. I’ve tried Portfolio Equity but in the back test, it returns the final Portfolio Equity from the entire backtest, it doesn’t seem to evaluate on each bar. This seems to be because Portfolio_NetProfit returns the final net profit from the test.
Can someone help me?
Any help would be much appreciated.
Portfolio Backtesting - total portfolio liquidation value [SOLVED]
Re: Portfolio Backtesting - total portfolio liquidation valu
Portfolio_Equity function supplied with MC should do it. Both the function and Portfolio_NetProfit keyword evaluate on every bar. So it is likely there is some other bug in your code.
Re: Portfolio Backtesting - total portfolio liquidation valu
Thanks very much.
Interestingly, if you use:
it will show the final equity position even though it runs this on the first bar, which is why I was very confused.
Thanks for your help.
Interestingly, if you use:
Code: Select all
once print(NumToStr(Portfolio_Equity, 2));
Thanks for your help.
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
Re: Portfolio Backtesting - total portfolio liquidation valu [SOLVED]
No it doesn't. Compile this code as a signal and run it as a portfolio money management signal:
You will see unique values for both portfolio_equity and portfolio_netprofit for each day (assuming that your system trades).
Code: Select all
Print(Date," Portfolio Equity = ", Portfolio_Equity," Portfolio Net_Profit = ", Portfolio_NetProfit);