One share may cost only a few cents, the other maybe over 100 euros. Only if your strategy does not buy the same number of shares in each value, but instead assesses the same capital, the backtest becomes meaningful. And this is exactly what you can do with the following code.
PS_Method (global, local, none),
Variables: cap, con;
// redistribution of portfolio p/l equally to all stocks
if PS_Method = global then cap =(PS_Capital + globalclosedequity) / PS_Members;
// redistribution of single stock p/l to single stock
if PS_Method = local then cap =(PS_Capital)/ PS_Members + closedequity;
// do not redistribute p/l
if PS_Method = none then cap = PS_Capital / PS_Members;
if close<>0 then con = round(cap/close/ Lot_Size,0)* Lot_Size;
The script starts with defining some inputs for the right position sizing. You may change these according to your needs. The first input is called ‘PS_Members’. It defines how many stocks you will trade. For a single stock strategy this value is 1, if you want to trade all FTSE100 stocks (for example) then set to 100. As you can see the default setting for this input is 10.
Second step is to define the capital for the whole portfolio. The default setting for ‘PS_Capital’ is 1,000,000.
Third, is to decide what happens with profits and losses. They can be ignored by choosing ‘none’ from the ‘PS_Method’ option. In this case the strategy always uses the given initial capital. If you want to reinvest the P & L of a given security to this security then select ‘local’. If you would like to redistribute the Portfolio P&L equally to all portfolio members then select ‘global’.
Fourth, and the final step, is to define the lot size of the security. If you want to buy in steps of 1, then set this to 1, if you always want to buy 100 stocks as a bundle then set it to 100.
Watch the video and see how this script is used in conjunction with a sample strategy. The video also shows you how to copy and paste the script into Tradesignal® to make it available for any of your strategies or one of the many pre-build strategies Tradesignal is shipped with. Here are all the steps to explain how to make use of the script:
- 01. Right-hand side; click ‘Strategies’ and choose ‘New Strategy…’.