Page 1 of 1

Portfolio Trader - % Equity Doesn't Seem to Work as Expected

Posted: Nov 02 2021
by petermcphee
Hello,

(Sorry, long post here!)

I'm trying to understand how the allocation of capital works with the Portfolio Trader as it doesn't seem to be working as I'd expect.

I've created a simple buy and hold strategy to test this using a collection of stocks that simply buys as soon as the Barnumber is >= 0.

I use the Portfolio Trader reserved words for determining the capital. Here is my sample code:

Code: Select all

Variables: NumContracts(0), PercentPerTrade(3); If GetAppInfo(AiIsPortfolioMode) = 1 then Numcontracts = (Portfolio_Equity * (PercentPerTrade / 100)) / Close Else Numcontracts = 1000 / Close; If BarNumber >= 0 Then Buy NumContracts Shares Next Bar Market; If LastBarOnChart Then SetExitOnClose;
Now, I have 30 stocks loaded in my portfolio. Each trade that I take uses 3% of available equity. This should mean every stock has enough room to be added (with 30 stocks at 3% I will be at 90% capacity).

I then use these settings in Portfolio Settings:

Exposure (% of Portfolio Capital): 100%
Max % of Capital at Risk per Position: 100%
Initial Capital: 100,000
Margin Value: 100%
Max Potential Loss: 100%

When I load the strategy I can see that it indeed allocates the 3% of the value for each trade. But, it stops adding new stocks after only 19 stocks have been taken - so 57% of capital only. I thought perhaps the equity curve had dropped significantly, but no, this didn't happen and in fact 19 stocks is all that the strategy ever takes.

So, I thought I would change the Max % of Capital setting from 100% to 3% (even though I've already set 3% in the strategy). Now, every stock has been added to the strategy (despite the lower %) BUT the amount of capital per trade is wrong (by a multiple of about 0.5x); it completely ignores my number of shares setting in the strategy.

I think I have probably misunderstood how the portfolio's equity is used against the number of shares traded in the strategy? How does the Max % of Capital relate to what is specified in the strategy?

Any ideas please?

Many thanks,

Peter.

Re: Portfolio Trader - % Equity Doesn't Seem to Work as Expected

Posted: Nov 02 2021
by petermcphee
I think I see what the problem is...the Portfolio_InvestedCapital doesn't seem to calculate correctly. If I build a portfolio of one symbol and buy 1 share, the allocated capital doesn't equal the notional value of share buy. E.g.

Code: Select all

If BarNumber >= 0 Then Buy 1 Shares Next Bar Market; If LastBarOnChart Then Begin SetExitOnClose; Print(Symbol,",",entryprice,",",Portfolio_Equity,",",Portfolio_InvestedCapital,",",Portfolio_MaxOpenPositionPotentialLoss); End;
This outputs:

AAPL, 149.81,99999.15, 299.62, 149.81

The Portfolio_InvestedCapital should equal 149.81. Sometimes it does but often, especially when I test back over a large amount of data it is often out to the share total.

I checked the Quote Manager settings and ensured that the BigPointValue was 1. I also have Max Potential Loss = 100%.

Any other ideas on what could cause the Portfolio_InvestedCapital to not equal the total spend?

Re: Portfolio Trader - % Equity Doesn't Seem to Work as Expected

Posted: Nov 03 2021
by petermcphee
After some more testing I can see that Portfolio_InvestedCapital is being multiplied x 2.

I created a new, single stock portfolio with the exact same settings as the first and used this code:

Code: Select all

If BarNumber >= 0 Then Buy 1 share Next Bar Market; If LastBarOnChart Then Begin SetExitOnClose; Print(Symbol,",",entryprice,",",close,",",PosTradeSize(0,0),",",Portfolio_Equity,",",Portfolio_InvestedCapital,",",Portfolio_MaxOpenPositionPotentialLoss); End;
The wrong portfolio showed this:

AAPL, 24.68, 150.02, 1.00,100125.34, 49.36, 24.68

And the correct one showed this:

AAPL, 24.68, 150.02, 1.00,100125.34, 24.68, 24.68

The difference is the reported Portfolio_InvestedCapital, which throws out my other % based strategies.

Any idea where I can find the culprit for the multiple of the invested amount? I've looked everywhere and I cannot seem to find it. I can always just use the new portfolio but would like to know so it doesn't catch me out again.

Thanks!

Re: Portfolio Trader - % Equity Doesn't Seem to Work as Expected  [SOLVED]

Posted: Dec 14 2021
by Tammy MultiCharts
Hello petermcphee,

The reason why Portfolio_InvestedCapital returns a value twice as much as was spent for buying the stocks is MaxPotentialLoss set to 100% in Portfolio Settings > Potential Loss per Contract section.
With this setting 100% of the sum of the contract is additionally reserved for potential losses.
Please set MaxPotentialLoss to 0%.

Re: Portfolio Trader - % Equity Doesn't Seem to Work as Expected

Posted: Dec 23 2021
by joebone
This needs to be easier to find. Been trying to figure this out for myself the last few days as well. Also a side note Portfolio Equity doesnt seem to be in the wiki?

EDIT
Going to drop some tags here for future people to find

Portfolio Buying power calculations
Available Buying Power

This was also helpful
https://www.multicharts.com/trading-sof ... _Portfolio