I am learning how to build position sizers and I am also curious about the internal workings of the Kelly position sizer.
I can make the default position size pretty small but not zero. If zero, there are no trades and the win % is 0 so no bet is ever made. I think if the underlying strategy is known and all the trades is made is known, the position sizer should use that for determining the bet and not just the ones that were taken when using the criterion.
I downloaded the attachment for the Position Sizer extension but was unable to see it.
Is it possible to see the code for this sizer? it would be very helpful
Thanks.
Size:
Color:
QUOTE:
Is it possible to see the code for this sizer? it would be very helpful
Let me quote the page from where you downloaded:
Download Project Source (demo version 2011.11)QUOTE:
PosSizers included in this demo solution:
Random PosSizer - in two versions, demonstrating how to inherit from BasicPosSizer+PosSizerSettingsBase and from PosSizer+ ICustomSettings
Limit Average Volume: limits positions to selected percent of average volume over selected number of days (option exists in Position Options)
Script-based Percent Equity: sizes position according to a % of equity passed as a Position.Tag value (double) or via SetShareSize (option exists in Position Options)
The examples illustrate all typical PosSizer creation patterns. There is no plan to share any other PosSizer's code.
Size:
Color:
People implement Kelly differently. I would just like to know how this position sizer works. Right now it is a black box as the description provided is lacking a lot of details.
For example, does the window count the currently open trades when calculating the win percentage?
Can you provide more details on the calculation of the Kelly fraction the the sizer is using w/o divulging code?
How is this sizer calculating the W (Win loss ratio)
http://www2.wealth-lab.com/WL5WIKI/psKelly.ashxThanks
Size:
Color:
One of the reasons I am asking is that on a given day, I would think the percentage bet being made would be the same for all trades taken that day yet when I look at the positions taken from the trades tab the bets for example on Jan 5 are not. I would guess that on Jan 5, any position taken should be based on the Kelly fraction calculated from the previous trades
See the attachment. Can anyone tell me why for example that on Jan 5 some positions are 100k (GOOGL) and some are much less (GRMN)
Anyone?
I am using 1% default %, 40day window, 10% max, 100% Kelly fraction
When I go back and change the dates to end on Jan 4 (to get the suggested trades for Jan5), I get the same dollar values for trade alerts.
I will try to reproduce this with one of the pre-packaged strategies so it can be replicated by the community
Size:
Color:
QUOTE:
For example, does the window count the currently open trades when calculating the win percentage?
Yes, open trades are not separated.
QUOTE:
Can you provide more details on the calculation of the Kelly fraction the the sizer is using w/o divulging code?
Kelly = Win rate - (100 - Win rate) / [Avg. win / Avg. loss];
QUOTE:
How is this sizer calculating the W (Win loss ratio)
Win rate = (winning trades * 100) / Window,
where Window = 30 by default (number of trades)
Size:
Color:
QUOTE:
QUOTE:
I would think the percentage bet being made would be the same for all trades taken that day
What part of the Wiki documentation would create this impression? I think that the bet is readjusted after each new Position taken.
Thank you for the explanation
This is an end of day strategy. The alerts give a number of shares to trade on the open the next day (at a limit price)
The dollar value of these alerts are all equal based on that end of day estimate of the Kelly percentage of the portfolio to trade.
When they show up in the trades tab, they are not for the same equal dollar value amounts.
How can the results be achieved if after the trade I think I've done is adjusted by the position sizer and says I really didnt trade that amount? The position sizer shouldnt be able to know about positions I've traded on the same day.
I appreciate your help.
QUOTE:
Kelly = Win rate - (100 - Win rate) / [Avg. win / Avg. loss];
How does the sizer handle cases where there have been no losses or no gains in the window period? Avg loss = 0?
Size:
Color:
A couple of notes.
1. When Kelly fraction comes out less than 0, the PosSizer has to re-size the trade to the default percent equity value.
2. It would also cap the maximum size at specified percentage.
Steve, please try to reproduce the position size inequality scenario using a dummy or pre-packaged strategy using EOD data for a manageable DataSet like Dow 30. I'll investigate and tell if it's a bug or by design.
Size:
Color:
Ok Eugene, here goes
Strategy is Active Trader 2009-12 | Modified Turtle Soup
I ran it over the period 1/1/2009 - 5/17/2012
The Kelly configuration is 1% Default Equity, 40 trade window, 100 Kelly Fraction, 10% max size allowed
Portfolio Size 1,000,000
This generated 3 alerts on 5/17/12 to buy
225 shares of IBM close was 197.89 so approx. market value is 44,525.25
387 shares of V close was 116.41 so approx. market value is 45,050.67
1398 shares of XOM – sell order
I then changed the period to include the 17th e.g. I ran from 1/1/09 to 5/18/12 (1 day later)
Open trades included
186 shares of IBM @ 198.78 (MV = 36,973.08)
97 shares of V @ 114.85 (MV = 11,140.45)
I received no errors regarding sufficient capital.
Here is what I have for the Dow 30 set
AXP BA CAT CSCO CVX DD DIS GE GS HD IBM INTC JNJ JPM KO MCD MMM MRK MSFT NKE PFE PG T TRV UNH UTX V VZ WMT XOM
Please let me know if you need more data. I hope you can reproduce this
Interestingly
The date 6/7/10 is interesting too. 4 alerts on the 7th MV approx 10,400 for the 4 alerts (AXP,CSCO,MMM,UTX)
running to 6/8/10 I get roughly the correct shares purchased in the trades tab
I then ran to 6/8/2011 (1 year later)
I looked in the trades tab (All trades) and the quantities were quite different.
Size:
Color:
Here the way I test quickly for any dataset with a kelly run and another example
I take all the trades, copy to clipboard. In Excel, Multiply shares by entry price to get market value.
For any symbols that are traded on the same date, the market values should be roughly equal if the kelly percentage of the portfolio was calculated the night before.
I just did it for a simple portfolio(c, cvx v vz xom) with the strategy above and kelly 1,40,100,10 and got odd results for c and vz on 6/9/11
Size:
Color:
Thank you Steve for pointing out the problem with unexpected size. Having investigated into the issue, I've found the culprit: the Kelly formula is negatively affected by including the newly opened positions. The fix is to exclude open positions from the calculation and to work with closed positions only (ETA ~ early February).
Size:
Color:
Thanks Eugene
I appreciate your help with this. The Kelly criterion is very cool and used by many hedge funds. I'm looking forward to to seeing how it works in February. I imagine the result will be included in a new release of the Position Sizer Extension. I will look for it there.
Thanks again for your help.
Steve
p.s. This makes sense. As the currently open positions gain/lose value, it will affect both the win% and the avg gain/loss so the sizer will adjust after the fact. I imagine there are other sizers that might be affected by open positions as well.
Size:
Color:
QUOTE:
I imagine the result will be included in a new release of the Position Sizer Extension. I will look for it there.
Right on: it's the
MS123 PosSizer library. You might want to enable "Check for updates on program start" in the
Extension Manager to be notified automatically.
Size:
Color:
Pps.
I was thinking about the problem some more. There are two ways you might want to handle it. You could choose to exclude open trades all together or you could use them but for sizing purposes "fix" them as of night (bar?) before. Either way, the equity that the Kelly percentage is applied to should include the current equity (including the open trades). I'll be curious to know what ultimately gets implemented
Thanks again
Size:
Color:
I will filter out open trades altogether which seems to be a more simple and robust approach.
Size:
Color:
QUOTE:
I will filter out open trades altogether which seems to be a more simple and robust approach.
Might be nice to have as an option
A quick and dirty simulation in Excel tells me the
outstanding performances I was getting will be drastically reduced once the new sizer is written. Looking forward to putting it through some paces.
Size:
Color:
Steve,
Extension has been updated.
Size:
Color:
The results look a lot more reasonable now. I still see some instances where the sizer claims it is out of capital but the closed equity curve shows more than adequate capital. I'll try and track that down and see what's going on
I have to admit, the old Kelly sizer had some nice properties. I still fantasize and get a kick out of turning 1mm into 70mm over 10 years even though I know it's bogus ;-)
Size:
Color: