Portfolio Backtesting - total portfolio liquidation value  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
johnsel
Posts: 7
Joined: 11 Aug 2011
Has thanked: 8 times

Portfolio Backtesting - total portfolio liquidation value

Postby johnsel » 13 Apr 2015

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.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: Portfolio Backtesting - total portfolio liquidation valu

Postby orion » 13 Apr 2015

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.

User avatar
johnsel
Posts: 7
Joined: 11 Aug 2011
Has thanked: 8 times

Re: Portfolio Backtesting - total portfolio liquidation valu

Postby johnsel » 13 Apr 2015

Thanks very much.

Interestingly, if you use:

Code: Select all

once print(NumToStr(Portfolio_Equity, 2));
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.

User avatar
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]

Postby furytrader » 14 Apr 2015

No it doesn't. Compile this code as a signal and run it as a portfolio money management signal:

Code: Select all

Print(Date," Portfolio Equity = ", Portfolio_Equity," Portfolio Net_Profit = ", Portfolio_NetProfit);
You will see unique values for both portfolio_equity and portfolio_netprofit for each day (assuming that your system trades).


Return to “MultiCharts”