Can I set a maximum share size?
Author: thodder
Creation Date: 10/5/2009 10:52 AM
profile picture

thodder

#1
I've noticed with some backtests that look good that my strategy is buying more than 56,000 shares on shares that may only have an average daily volume of 100,000 shares. That won't work in the real world as my trade will obviously affect the price. I'd like to put some code in my strategy to prevent the maximum number of shares from exceeding 1/100th of the daily volume (or possibly even less).

It appears the only way I can override the share size is by controlling it in my strategy and backtesting with Position Sizing set to "Wealthscript Override". I'd like to be able to set a maximum with Position Sizing set to "Percent of Equity" or "Fixed Dollar". Is there any way to do this?

At the momment I'm just excluding securities that have a price below a certain value and average volume since those are the ones that I'm trying purchase with large share sizes.
profile picture

Eugene

#2
Yes, enabling "Reduce Quantity based on Volume" in Preferences > Backtest Settings should work.



profile picture

thodder

#3
Thanks Eugene! That should help some.

The preferences feature uses the current bar's volume which would be the volume in 1 minute for a Scale of 1 minute. I actually wanted to code it based on the average daily volume. Is there any way for me to control the maximum number of shares in my strategy code without actually overriding the size?

From my experimenting, it appears the following code may work; however 'LastPosition.OverrideShareSize' appears to be undocumented:

CODE:
Please log in to see this code.
profile picture

Eugene

#4
OverrideShareSize is an undocumented function which, as we believe, is used by SetShareSize internally.

You'll be able to mix your intraday trade size limit logic with "Pct of Equity" sizing once Version 5.6 brings the support for PosSizers (aka $imuScripts).
profile picture

thodder

#5
Any chance this will become a documented feature as my test shows this does exactly what I want?
profile picture

Eugene

#6
Why? The code is equivalent to using SetShareSize before BuyAtMarket, and should not work unless Override is on.
profile picture

thodder

#7
I thought OverrideShareSize was working even when Position Sizing was set to something other than "Wealthscript Override", but now I'm getting different results during my testing. I may have commented too soon.

I'll wait to see what 5.6 has to offer with the PosSizers. Until then I'll try the "Reduce Quantity based on Volume" in Preferences > Backtest Settings that you suggested.

Thanks.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).