Portfolio Backtester: Trade Size as a % of Portfolio Equity

Questions about MultiCharts and user contributed studies.
KeyDiver
Posts: 8
Joined: 29 May 2010
Location: Trinity, Florida

Portfolio Backtester: Trade Size as a % of Portfolio Equity

Postby KeyDiver » 21 Sep 2012

A very common long-term investment strategy is to buy the "n" top-ranked mutual funds from a list. This is done every week, month, quarter, depending on your preference. The reserved word "PortfolioEntriesPriority" assigns the ranking value and Backtester uses that value to choose which signals to take.

I am trying to backtest a strategy that will buy the 5 top ranked ETFs from a list of 26, using 20% of the current account equity. The account is funded with $100,000 to start. When the strategy begins, buy $20,000 of each of the top five. After the holding period, rebalance the holdings with the new top five ranked ETFs. This looks to keep you invested in the "best" ETFs according to your ranking algorithm.

I have attached a very simple Strategy to do rebalancing on a weekly basis, ignoring the ranking feature for now. Here's the code --

Code: Select all

// If today is Thursday then sell the position tomorrow (Friday) at the Open
if DayOfWeek(Date) = 4 then Sell next bar at Open;

// If today is Friday then buy the position Monday at the Open
if DayOfWeek(Date) = 5 then Buy next bar at Open;
You can see it buys on Monday and sells on Friday. I applied this Strategy to a BackTester portfolio of 25 ETF's. (I tried to attach a portfolio file to make it easier to test this, but the forum will not accept .pws files)

If I set the Trade Size to "500 Shares" in the Portfolio properties, Backtester will create 500-share positions until it runs out of portfolio equity. If I set Trade Size to $20,000, it will create $20k-sized positions until it runs out of portfolio equity. It just starts at the top of the ETF list and goes down until it runs out of money.

The problem comes when I set Trade Size to 20% of Equity in the Portfolio Properties. Now Backtester buys the entire list. It starts with 20% of $100K for the first position. It uses 20% of $80K for the second. Then 20% of $64K for the third. It continues to use the declining account balance until it reaches the end of the list.

I'm looking for comments and/or suggestions on this behavior. My experience with other backtesters (Wealth Lab, NT, AB, TradersStudio) is that they will take 20% of the current portfolio equity, not of the declining balance, for each new position. These other testers will create five positions at any time with close to 20% of the portfolio equity.

Has anyone out there worked on this problem ?

Do you have a way to tell Backtester to make five 20% positions as the portfolio equity grows and shrinks over time?

Thanks.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Portfolio Backtester: Trade Size as a % of Portfolio Equ

Postby Dave Masalov » 09 Oct 2012

Hello KeyDiver,

Here is an example of the code that should do what you need:

Code: Select all

var: Pcnt20(0), maxploss(0);
Pcnt20 = (InitialCapital+Portfolio_NetProfit)*0.2;
maxploss = Portfolio_CalcMaxPotentialLossForEntry(1, 1, Close);

if maxploss<>0 then
buy Pcnt20/maxploss contract next bar at market;


Return to “MultiCharts”