ADV filter, how to code to reference equity size?
Author: swuzy
Creation Date: 5/21/2015 2:49 PM
profile picture

swuzy

#1
ADV filter, how to code to reference equity size?

Hi,

I wish to implement in my Code, an ADV (Average Dollar Volume) stock filter that varies with my Position Size.

(see article on Screening for Liquidity .. Average Dollar Volume per Minute)

http://seekingalpha.com/article/229341-all-listed-stocks-by-average-dollar-trading-volume

Assuming my Equity size is $100,000 and my Position Size is 20% of equity,
(Equity Position Size is $20,000), I might want to enter stocks with at least $2,000 of Dvm (Dollar Volume per Minute).

So would like to code to filter

CODE:
Please log in to see this code.


How do I code to reference my equity size or my position size?

Later on, as I play around more with this, I will hope to be able to ratchet the 10% Dvm variable along a different scaling ratio than my Equity Size. For example, the article cites usage of a 25% ratio to a $100k equity position size, and a 10% Dvm ratio to a $1M equity position size.

QUOTE:
As a matter of policy, we do not invest in stocks that have a three-month average daily trading volume of less than $25,000 per minute - no matter what -- and would generally seek to use positions per account that prospectively enable an exit or entry in no more than a couple of minutes. For example, for a $100,000 position, we would prefer an average dollar volume of more than $25,000 per minute, and for a $1 million position, we would be a lot happier with a dollar volume of several $100,000 per minute.


Thanks.

PS actually for my code, not knowing how to reference Equity Size, I just use KDM for "Thousand Dollar Minute", as in

QUOTE:
&& KDM >= 2;


profile picture

Eugene

#2
Referring to equity or position size in strategy is not that simple. Please start by reading this FAQ: How to display portfolio equity (exposure, drawdown etc.) series and/or access them in scripts?
profile picture

swuzy

#3
Ouch. Definitely sends me to Dyslexia Land, and beyond my level of comfort.

Hope you will consider including in your Position Sizers an ability to filter stocks by the size of their Dollar Volume per MInute (or their KDM Thousand Dollar Minute) as a ratio to Equity Size or Position Size.

Best to you.
profile picture

Eugene

#4
Frankly, it's not easy to include a lesser used idea like DVM in Position Options (the primary destination for such position sizing tweaks and filters) and maintain its composition and usability.

Although I understand that it's not the same as Average Dollar Trading Volume, what about a workaround that exists in the Position Options PosSizer: "Reject if size > X% of Average Volume (SMA)"?
profile picture

swuzy

#5
That definitely seems not as safely robust. Even though "0.1%" of a low liquidity penny stock is the same "0.1%" of a high liquidity large cap, I and most others would not want to touch the 0.1% low liquidity penny stock.

In contrast choosing a stock having $10K of DVM (Dollar Volume Minute) is more economically equivalent in comparative liquidity whether it is a $1 stock with $3.9 million of ADV or a $50 stock with $3.9 million of ADV (Average Dollar Volume a day [390 trading minutes a day]).

It seems to be comparing apples to oranges rather than grapes to grapefruit. It is simply not a work around as I don't see it as an equivalency because the quality of the DVM or ADV filter is much consistently superior and more robust than that of Average Volume.

I feel it is a far better service to WL stock strategy coders to have DVM or ADV available as a Position Sizer filtering tool.

Just because it hasn't been clamored for, does not mean it isn't substantially better; but rather that at best it hasn't been thought about, and at worse because the tools not being set out as easily cataloged and available, need to be separately fashioned by each, and the DVM dollar threshold value adjusted incrementally for each equity size as it changes up and down in back testing (instead of simply being set as a percent of equity size).

Just my two bits, and hoping it will make it onto your To Do lists one of these days.

Cheers and have a good day.

profile picture

LenMoz

#6
Seth,

QUOTE:
How do I code to reference my equity size or my position size?

What you're asking is an architectural change to WL. First, some background... In a multi-symbol backtest, WL first runs your strategy for each symbol individually, generating potential signals without regard to buying power. After all symbols have been run individually, the list of potential signals is processed by the selected PosSizer, in date/priority order, where potential signals become actual signals according to the rules of the PosSizer. Not all potential signals become actual signals due to buying power (or other) limitations. So, you can see why your strategy cannot reference equity size or position size. These are not known at the time your strategy is running for a symbol.

I agree that this a severe limitation. So why design such an architecture? Answer: So that a backtest can be run in a reasonable amount of time without powerful hardware. Consider the alternative - running the portfolio a bar at a time across all symbols. This would let a strategy know equity and buying power at each bar. What does this require? It requires that I calculate all required DataSeries for all symbols for the period of the backtest before I start. Keeping them in memory requires lots of hardware. Keeping them on disk, even SSD, may be slow. Alternatively, I might try using Indicator.Value instead of Indicator.Series. Now I need a lot of processor speed to keep recalculating the DataSeries.

The current WL design works for many strategy designs and has a body of strategies that would have to change for the new paradigm. I hope this helps explain why you're getting some resistance to your idea.

Len
profile picture

swuzy

#7
Thank you Len for explaining that the architecture prohibits applying equity position sizing upon running the strategy code body.
And so we appreciate the design and application of PosSizer equity and position sizing filters after the run of stock strategy filters.

I hope it is possible and will come to fruit, to add to PosSizer features an ability to apply Average Dollar Volume by equity size filtering.

If one wants to apply ADV over a back test to an equity position size that starts at say $100 K and ranges up to $1 M (a ratio or factor of ten), one will want the ADV PosSizer for initially strategy selected stocks to be varying, say $20 AKDM (Average Thousand Dollar Minute) to $200 AKDM as the equity size increases and contracts.

To vary the AKDM PosSizer from 20 to 200, is equivalent to varying ADV from $7,800,000 to $78,000,000 (also a ratio or factor of ten, same as the change in equity size). So to appropriately use ADV-AKDM in back testing, it must be linked by reference to equity size so that the two will grow or shrink in the same proportion from the initial starting values.

ADV is clearly a logically correct and more appropriate PosSizer filter, with immediate, direct real world application, all across the board.

Thanks for the very hard working development team's consideration of this.



profile picture

Eugene

#8
The "Minute" part in ADV/AKDM limits its application to intraday data only. A users enabling that imaginary filter in Position Options and trying to apply it to EOD data would be confused because a) PosSizer's GUI can not be altered depending on underlying data so to disable the inapplicable option and b) it would not do anything for him once enabled.
profile picture

swuzy

#9
Hi Eugene,

I can understand the possibility of confusion in use or application.

I do not trade intraday, I only do daily bars, and to me, my "KDM" is only an ease of reference for conceptualization purposes.

Since I would be buying and selling symbols only in easily conceptualized increments of 1k, 5k, 10k, 15k, 20k, 25k, 30k, .... 50k, ..., I'd like to be able to choose symbols that I can exit easily by reference to the ADV that relates to the Average Thousand Dollar Daily Minute (not real intraday data, but merely ADV / 1000 / 390 [390 minutes in a normal trading day]). It is just a more easily referenced concept to relate to the $ K position in symbols.

It is dramatically better and easier than having to mentally calculate or recognizing in my head that $3.9 million of ADV is equivalent to 10 KDM, $7.8 M ADV is 20 KDM, $11.7 M ADV is 25 KDM, or that $23.4 M ADV is equivalent to 30 KDM, etc, etc. From a user's viewpoint it is easier to handle and apply, and it would be necessary to clarify that KDM is NOT based on minute bars but rather is merely ADV / 1000 / 390.

I suppose that for a real intra day trader, they might wish to use minute bar kdm, and if so, another scaling option to choose that could be provided. Actually if you did provide different scaling options within the PosSizer upfront, it will help reduce confusion that a single option might have multiple meanings.

The difficulty with applying Kdm ( ADV / 1000 / 390 ) currently to coding is that if you are doing a 10 year backtest, your equity starting with $100 K might range to $1 M, such that a 10% position sizing starts with $10 K positions and may range to $100 K positions; but you will need to choose and set a Kdm size up front and whatever you choose up front will handicap your back testing.

If you set a Kdm of >= $1 K because of your initial $10 K lots, you will be applying a $1 K liquidity threshold to $100 K lots later on; clearly inappropriately and dangerously low levels of liquidity.

If you set a Kdm of >= $10 K because you are seeing endpoints (or interim highpoints) of $100 K lots, you will be unnecessarily cutting yourself off from many qualifying symbols at the front end $10 K lot levels by limiting yourself to stocks with 10 X the level of liquidity you might otherwise be willing to entertain.

This is why, it would be a wonderfully great service to the WL public, to be able to link the filtering threshold for Average Dollar Volume Minute proportionately to Position Size, that is,
QUOTE:
ADVM Threshold Filter --

ADVM >= ##.## % of Position Size.

* Here, ADVM (Average Dollar Volume per Minute) is averaged from daily bars, not minute bars.

This way, if your Position Size is $10,000 and you set ADVM as 2.5% 25% of Position Size, your ADVM threshold for eligible stocks is $2,500 Dollar Volume a Minute. If your Position Size changes to $100,000, your ADVM threshold dynamically resizes as appropriate and automatically changes to $25,000.

This would be so much simpler, so much easier to conceptualize, understand and implement from a user perspective.

Best to you,

Errors corrected? Sorry, I am confusing myself and the reader, switching in talk between using AKDVM (Average Thousand Dollar Minutes) and ADVM (Average Dollar Minutes).
profile picture

Eugene

#10
Hi Seth,

QUOTE:
the Average Thousand Dollar Daily Minute (not real intraday data, but merely ADV / 1000 / 390 [390 minutes in a normal trading day]).

I see. However, Wealth-Lab extensions do not specifically target Wealth-Lab Pro and U.S. markets. If we want it to be of great service to the WL public, we must not assume that a normal trading day has 390 minutes. In the first place, a day may have less than that. What's more important, futures / international exchanges with their variable market hours and round-the-clock trading add to the picture. Now imagine the ability to trade external symbols via SetContext() or by virtue of using the Watchlist provider to mix various symbols from different DataSets together.

QUOTE:
Actually if you did provide different scaling options within the PosSizer upfront, it will help reduce confusion that a single option might have multiple meanings.

There's not enough screen "real estate" in Position Options to justify this and other options. (New or another PosSizer is not considered).

QUOTE:
The difficulty with applying Kdm ( ADV / 1000 / 390 ) currently to coding is that if you are doing a 10 year backtest, your equity starting with $100 K might range to $1 M,

Good point. But "Reduce Quantity based on Volume", although a simplification and approximation, appears more universally applicable without the design trouble caused by ADVM. It's pretty difficult to implement this concept in its entirety.
profile picture

swuzy

#11
Curious then, how does WL present for use PosSizer: "Reject if size > X% of Average Volume (SMA)" to different markets with different period sizes ( 6.5 hour volume, 24 hour volume, 3 hour volume, etc), as for different geographies, half day holidays, 24 hour futures?

How do the users apply differentiating formulations for their usage?

Is Average Volume based on 3 months average daily volume for whatever the default scaling is used, or is it just say average of 60 bars (3 x 20 bars) ?

The easy solution is just to use just let the User specify how it is desired to convert Bars to Minutes by applying a Normalized Minute factor.

So the User will self determine, select and input a Normalized Minute factor for:


QUOTE:
5 min. bar = 5,
10 min. bar = 10,
60 min. bar = 60,
390 min. day bar of 6.5 hours = 390,
480 min. day bar of 8 hours = 480,
1440 min. day bar of 24 hours = 1440,
1950 min. week bar of 5 days of 6.5 hours = 1950,
7800 min. month bar of 20 days of 6.5 hours = 7800,
10080 min. 7 day week bar of 24 hour days = 10080.


Then there is no need to worry our head about multi-variegated market scaling.

So a more complete, simple, and meaningful ADVM screen would be:

QUOTE:
ADVM (Average Dollar Volume per Minute) Threshold Filter --

ADVM >= #.## % of Position Size.

Enter #.## %: _____%
Current default setting based on your strategy run setting is: XXX minutes per bar.
To use a different number, enter number of minutes per bar here: _____ [e.g., "5" for 5 min bar, or "600" for a 10 hour daily bar.]

* E.g., ADV (Average Dollar Volume) for daily bars is 3 months trailing average (of 60 bars).
ADVM is ADV divided by your Normalized Minute factor of YY minutes per bar.



Assuming PosSizer can ascertain what bar scale (5 min bar, 60 min bar, daily bar, weekly bar), that the User is applying to run the strategy and the bar scale at which buys and sells are made, then PosSizer should use such bar scale by default and "minutize" it accordingly as defaults, based on the User strategy run settings.

The User should then be given to option to over ride the default and apply custom Normalized Minute factors, as a bar of 8 hour trading days, a bar of 7 day weeks, etc.

Then the PosSizer won't have to "mind read" a Normalized Minute factor for each variegated possibility of Bars.

I do believe that if there is a will, then there will be a way, to find appropriate "real estate" in Position Options for such a very importantly useful tool.

profile picture

Eugene

#12
QUOTE:
Curious then, how does WL present for use, PosSizer: "Reject if size > X% of Average Volume (SMA)" to different markets with different period sizes ( 6.5 hour volume, 24 hour volume, 3 hour volume, etc), as for different geographies, half day holidays, 24 hour futures?

Just like you do when you apply an SMA to any stock on any timeframe: on a bar by bar basis. It's agnostic to the number of bars in a trading session.

QUOTE:
Is Average Volume based on 3 months average daily volume for whatever the default scaling is used, or is it just say average of 60 bars (3 x 20 bars) ?

There's no option to select "month" or "day" there. You type in any number of bars exactly like in Indicator Settings.

QUOTE:
The easy solution is just to use Average Dollar Volume per Bar of a specified, or user specified set of bars, and apply it to the user's default scaling (intraday, 5 min bars, hourly bars, 2 hour bars, daily bars, weekly bars, monthly bars.

So currently we can have a condition like:

* Projected share size (X) is > Y% of Z-bar SMA of Volume

The proposed addition of Average Dollar Volume per Bar is:

* Projected dollar size ($X) is > Y% of Z-bar SMA of (Volume * Price)

Correct?

QUOTE:
The easy solution is just to use just let the User specify how it is desired to convert Bars to Minutes by applying a Normalized Minute factor.

What would be the benefit in adding the normalizing factor to the equation? In my opinion, ADVM (the per-minute logic) might not bring enough bang for the buck to justify the complication and overloading the GUI for a minor potential enhancement over the already existing liquidity filter.
profile picture

swuzy

#13
Why include a normalized minute factor? Why because someone suggested or implied a need for it --
QUOTE:
If we want it to be of great service to the WL public, we must not assume that a normal trading day has 390 minutes.


Insufficient bang to the buck for minor potential enhancement of existing liquidity filter?

Sigh.

Obviously I am clumsy in my persuasion (I had to go back and rewrite and delete many, many, clumsy passages above, but evidently to no avail).

If you and other people cannot see the difference in value of benefit of ADVM over AV, ... I give up for now, as additional colorful language will not be helpful.

Indeed some may say, "Please don't bother", "I hope they won't understand to use and implement such a feature, so that I can reap the benefits myself."

So it is perfectly all right as is, there must not be any much difference in benefit; at least, nothing that I can explain sufficiently clearly or persuasively.

Good night or good day as the case may be.