how can I limit a maximum number of shares which should be open in backtest?
As this option is missing in SetOption configuration I assume it must be done within custom backtest (CBT).
Can you please help mi with this piece of code?
When running a backtest with position sizing I want to have ability to limit maximum number of shares for ticker and limit it to this number.
Set Position Size with option spsShares will set number of each trade to fixed number. But this is not what I asked for.
I would like to know, how in backtest when a position sizing is used and equity is growing to limit maximal number of buy/sell shares to avoid buying 100.000 of shares, etc...
spsValue (=1) - dollar value of size (as in previous versions)
spsPercentOfEquity (=2) - size expressed as percent of portfolio-level equity (size must be from ..100 (for regular accounts) or .1000 for margin accounts)
Please tell me how with above setting I can limit maximum number of shares to buy?
OK, a simple example.
Ticker ABC = price 100 USD per 1 share
Initial equity 1000 USD
Let' say initial number of shares to buy is set to 50% of total equity.
So with first trade, we buy 5 shares of ABC ticker => total value 500 = 50% of current equity.
If your equity during backtest grows, let's say it will be 100.000, then we would buy 500 shares of ABC ticker (assuming price at that point will be the same). But I would like to add a restriction to code, to limit max number of shares to let's say 250 shares!
It's a trivial question, however I am not able to find a solution to it.