Click here to Login





                                                   NbPositions, deviations in backtesting results

  0

0
Torsten
2015-07-10 06:37:51


Hi all,

I've a question regarding the Simulation setting "SetSimSetting(_NbPositions,n)".

In my understanding the maximum number of positions should have no impact on the backtesting results, as long as I set it to the number of available time series in the backtest.
(e.g. 50 futures in backtests means at maximum 50 simultaneous positions)

I'm not sure why, but if I increase Nbpositions to 500 or 5000, the backtesting results show huge deviations even though the system can take 50 positions at max in theory.
Furthermore If I look at the "Number of positions" in the report overview it shows me a maximum of 10 simultaneous positions, so the simulation setting should have no impact as long as it is greater than 10.

I'm not sure if I got something wrong about "NbPositions", does anyone have an idea where this deviation in the backtests might result from?

Thanks,
Torsten







Torsten
2015-07-10 08:25:03

  0

I just found this description:

"If you want to trade NASDAQ100 stocks and don't want to invest in more than 10 stocks at the same time then you should put 10 as number of positions.
Each position will get around 10% of the total capital. If you set the number of positions to 5 then each position will get around 20% of the total capital."

In my system the risk based position sizing is covered in the AMM. I assumed that an AMM script overrules the automatic allocation of capital by nbPositions. Obviously I'm wrong, as the total number of trades goes down if I increase nbPositions.

Is there a way to turn this off?







QuantShare
2015-07-10 12:06:17

  0

By default, each position will get 100/(Nb_Positions)% of capital.

You can change the number of shares to buy (and thus the share) in an AMM script.



Torsten
2015-07-10 15:24:12

  0

Hi QS,

the AMM script I use updates the contracts to buy. Nevertheless does the setting NbPositions influence the backtesting results somehow.
To narrow it down, I created a new AMM script with a single line in the "OnNewPosition" event:

Functions.UpdateNumberOfShares(2);

I run the same backtest (in this case with 33 time series) 4 times and changed only the _NbPositions setting in the strategy tab. As you can see with an increasing _NbPositions setting the number of total trades goes down, even if the number of simultanoues trades if far below the setting.

SetSimSetting(_NbPositions,33); -> Trades: 1990, max number of simultaneous pos. from back test summary: 10
SetSimSetting(_NbPositions,50); -> Trades: 1990, max number of simultaneous pos. from back test summary: 10
SetSimSetting(_NbPositions,500); -> Trades: 1755, max number of simultaneous pos. from back test summary: 10
SetSimSetting(_NbPositions,5000): -> Trades: 717, max number of simultaneous pos. from back test summary: 6






QuantShare
2015-07-10 18:26:17

  0

Yes of course it would influence the result.
If you put 50 positions then it there is 50 positions that meet the buy condition on a specific bar, the "OnNewPosition" will be executed 50 times, unless the portfolio runs out cash. In that case, no more positions will be added.

If you put for example 50 positions, has 10000 as equity and execute this:
Functions.UpdateNumberOfShares(2000); // worth $10000

Then only one position will be taken as they will be no more cash to buy further positions.



Torsten
2015-07-11 08:39:51

  0

Yes I understand that, but that's not the issue. The problem is that signals are not executed even if the number of open trades is far below nbPosition and enough cash is available. If the AMM takes care of the position sizing all signals should be passed to the AMM, as long as the maximum number of open trade is lower than nbPositions.
But that's obviously not the case:

If I set the initial equity to 10.000.000$
Functions.UpdateNumberOfShares(1);
and run the simulation with 33 futures

I get the following results:
nbPositions = 50 --> 1990 trades
nbPositions = 50000 --> 158 trades

In both cases nbPositions shouldn't be a limiting factor, as it will never be reached with 33 futures in simulation. But for whatever reason a higher nbPositions limits the execution of signals.

For me it looks as if the equity is divided by nbPosition for equal distribution and that this calculated value has to be greater than X of a new signal.
If this is correct, the question is what is X for stocks and what is X for futures (margin is set to 0 in the simulation) and shouldn't this check be turned off if the AMM defines the actual position size?

By setting a high number for nbPosition (50), I just wanted to ensure that all signal are going through and nothing is stopped by this setting.

Long story short: How can I ensure that the nbPosition setting doesn't limit my positions?

Thanks,
Torsten



QuantShare
2015-07-11 12:37:13

  0

Hi Torsten,

If you select "50000" as number of positions then each position will get a very small amount (in dollars). Since that amount is so small, you wouldn't be able to purchase even one share and that explains why there are so few trades. There is also min shares/value settings you can find here "Update Trading Systems -> Settings -> Capital".

Also there is a setting that you need to know about. It is used for optimization (memory) purposes.
Under the "Update Trading Systems -> Settings -> More Settings" button, you can specify the maximum number of signals to keep in memory.



Torsten
2015-07-11 16:15:52

  0

Hi QS,

I think I understand the logic. The question is whether it should be applied in all situations especially in future trading.

As of now the backtester cuts off 25% of the trades, in case a risk based position sizing model is applied in the AMM, because some rule says the equity isn't sufficient.
As the equity is a variable in the position sizing algorithm it wouldn%u2019t help just to increase the equity for simulation purposes.
The only way to ensure that all signals gets to a trade is to ignore the risk based position sizing and trade every position with one contract -> Functions.UpdateNumberOfShares(1).

Following the logic you described above, an initial equity of $500.000 and max position of 10 would lead to $50.000 for every potential future position.
For me the question is to what are those $50.000 compared, in case the backtester turns down a generated signal. Margin requirements would make sense, but they are all set to 0 in the backtests. It definitely doesn't make sense to compare it to the value of the contract.




QuantShare
2015-07-11 21:00:31

  0

For any asset that doesn't have margin requirements set, the number of shares is calculated based on the amount per position and the asset price.
If margin requirements are set then calculation is different.

If you want to analyze all signals, then either set a very high initial equity value or just check the signal in the AMM and accept or reject the ones you don't need. Not sure why you are putting a very high value in the number of positions (50000).

If you put $500.000 as initial equity and 10 as maximum position then all these 10 signals would be passed to AMM assuming you still have cash in your portfolio.



Torsten
2015-07-12 02:47:47

  0

Hi QS,

I used the high number of position to figure out what is happening, means for testing purposes only. In the real setup I'm using the number of futures in simulation (usually 50) as the number of open trades is already limited by a ranking function. But no matter if I use 10, 50 or 5000 as number of positions the signals are not executed.

I updated the margin deposit for all futures to "1" - no change. Please let me know how the calculation works if margin requirements are set.

"If you want to analyze all signals, then either set a very high initial equity value"
As the equity is part of the position size algorithm it doesn't help just to increase the initial equity, the system would just buy more contracts (tested with an initial equity up to $10.000.000.)

"or just check the signal in the AMM and accept or reject the ones you don\'t need."
How do I do that? As I don't reject any signal in the AMM, I assumed they never get to the AMM.

The only thing I want to achieve is that all signals are executed and are not limited by the nbPosition setting.

Thanks again,
Torsten



QuantShare
2015-07-12 19:16:27

  0

Can you please send us your trading system by email and tell us what exactly you are expecting?

When you say "But no matter if I use 10, 50 or 5000 as number of positions the signals are not executed", I am not sure what exactly you mean.
zero signals are executed? Just few? How many? Are you sure the "buy" rule generates many signals on that bar?



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
High to low stock pattern for the close price
Currency Mgmt v 0.9
Historical Index Composition
Survivorship bias-free S&P 500 database downloader
Selectable center of gravity index

How-to Lessons
How to run a screen or a watchlist from a script
Difference between the watchlist and the screener tools
How to plot the number of stock tweets per day
How to execute a script at regular intervals
How to hide a trading indicator from a particular time frame

Related Forum Threads
Watchlists results are not matching criteria
Save simulation/backtest results
Why Would the Ranking Analyzer Results Differ Here?
Trading strategy backtesting
backtesting on currency pairs

Blog Posts
Create a HTML or PDF Report of your Trading System Backtesting Re...
9 mistakes you should avoid when backtesting an end-of-day stock ...
Backtesting All Candlestick Patterns in 10 Minutes
Getting Accurate Backtesting Results: Survivorship bias-free S&P ...
Backtesting Process









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.