Kelly

157 views
Skip to first unread message

B

unread,
Sep 25, 2012, 10:58:43 AM9/25/12
to JBookTrader
Hi I noticed that the kelly fraction is calculated.

But, I can't seem to find the code in JBooktrader that returns any
account information in order to use the kelly fraction to size my
positions.

Does that code exist?
And if not, what's the point then of calculating the kelly fraction?

nonlinear

unread,
Sep 25, 2012, 6:18:51 PM9/25/12
to jbook...@googlegroups.com
You are right in that the Kelly Criterion is typically used to calculate the optimum bet site (or in the case of trading, the position size). However, in JBT it's used for a different purpose, which is ranking the strategy with respect to a given set of parameters. Think of it this way: suppose you have two strategies, A and B. Let's say they make the same profit, and have the same max drawdown. What's different is that the Kelly for strategy A is 30, and for strategy B it is 60. Which one would you trade? The answer is obvious: you want to trade strategy B, because the higher Kelly indicates that the performance is more stable and predictable. In JBT, the optimizer can be configured to use Kelly as a way to rank the optimization parameters. So, Kelly in JBT is used as a strategy performance metric (along with other metrics, such as Net Profit, Profit Factor) during the strategy optimization. 

Lawrence Perepolkin

unread,
Sep 26, 2012, 1:51:24 AM9/26/12
to jbook...@googlegroups.com
Another point one can raise when calculating a Kelly position size is that how well a given strategy works. For example, one can optimize an EMA crossover system that never looses on one particular instrument. If the system never looses then the Kelly position size would be infinity -- a sure thing. Easy to do, using large EMA time frames. Most know that the chances of winning are small. This type of approach is not that great.

Another approach would be to use a very large data set -- multiple instruments with a lot of history -- something that would require a few months of running 24/7 to crunch out a Kelly number. Turns out a realistic Kelly number is about 0.005. The turtles have also confirmed that 0.005 is a pretty good number.  Using small data sets one runs the risk of over fitting. On the other hand, using large data sets one also runs into the problem of combinatorial explosions--too many parameters and strategies to evaluate. 
--
You received this message because you are subscribed to the Google Groups "JBookTrader" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jbooktrader/-/5d2XPjWraH0J.
To post to this group, send email to jbook...@googlegroups.com.
To unsubscribe from this group, send email to jbooktrader...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jbooktrader?hl=en.

B

unread,
Sep 26, 2012, 10:50:38 PM9/26/12
to JBookTrader
I see. But the Kelly criterion accounts for this very case. ie.
Betting on two (or any number of) assets.

Let's say you believe you have information (in the information theory
sense of the word) on two assets. I'll use your two strategies A and
B. If the kelly fraction for A is 30, and for B is 60, then in order
to determine how to size your bet you would need to know how
correlated the returns are between A and B are during your backtests.

If A and B are perfectly correlated (corr = 1), then the math comes
out where you'd reduce each bet for A and B by half, since the
correlation between the strategies implies A and B are the same bet.

If A and B are perfectly anti-correlated, then the math comes out that
you'd bet *more* than 30x and 60x since the correlation between
strategies implies a reduction of variance due to the fact the two
returns of the two strategies are anti-correlated.

If A and B are perfectly non-correlated (corr = 0), then the math
comes out that you'd in fact bet 30x and 60x for A and B respectively.

In all cases, you need to know a) the correlation between strategies
of A and B, and b) the size of your bankroll in order to determine the
size of your trades in order to maximize growth given the information
you believe you have for A and B.


In the continuous case for a single asset, the kelly fraction is =
mean(returns)/variance(returns)
In the continuous case for multiple assets, the kelly fractions are =
covarianceMatrix^-1 * meanReturnsVector, where ^-1 means matrix
inverse, and the returns are the returns generated in your backtests.
mean(returns) would be the average single-bet return gained using some
strategy, and variance(returns) is the variance of those single-bet
returns. So if you're using 1min ticks, then the return over 1min
would be a single bet. If you're using 1hr, then that 1hr would be
considered a single bet, and so on..

In either case, calculating the kelly fraction, and *not* using it to
determine bet/position size is a pointless calculation.

So I guess there are no plans to create something like, AccountManager
to execute queries to return liquidation value of the account's
portfolio?

B

unread,
Sep 26, 2012, 11:07:17 PM9/26/12
to JBookTrader
I don't believe a calculation like that would take months. The most
complicated computation would be inverting a covariance matrix. And
your covariance matrix would only be as large as the number of assets
you're trading. The second most complicated computation would be
calculating the average single-period return of a strategy, and I
don't think anybody can be convinced that this would take months to
calculate either.

Either way, the kelly fraction *depends* on a) expected return, b) the
variance of that expected return, and c) the correlations between the
return and any other things you may be trading. Meaning, the kelly
fraction of an asset would change if any one of these three things
changed.

So, I'm not too clear on where 0.005 would be considered a good
number. In context to what? An asset in a portfolio with 5 other
differently-correlated assets? What betting period? 1min? 1 day? A
month? A kelly fraction of 0.005 is terrible if your period is a
month, but awesome if you're talking about a single asset over 1min.

And even if you had perfect information that implied infinite
leverage, an automated trading system would *still* need to know what
your bankroll was in order to place the appropriate bet
"automatically" using the leverage limits set by IB.


If there aren't any plans to put this functionality in, would you guys
be opposed to reviewing code that enabled this feature?

nonlinear

unread,
Sep 27, 2012, 2:54:51 PM9/27/12
to jbook...@googlegroups.com

In either case, calculating the kelly fraction, and *not* using it to
determine bet/position size is a pointless calculation.


I disagree. In my previous comment, I used the comparison between strategy A and strategy B, but what actually happens in JBT is that it's the same strategy that is being evaluated by the optimizer with respect to the optimization parameters. So, let's use Lawrence's example of a simple crossover system. For example, the rules may be that we buy when EMA(N) is above EMA(K), and we sell otherwise. In this particular instance there are two parameters, N and K, and the same strategy can be optimized with respect to different combinations of these parameters. Furthermore, if you plot these combinations of parameters against the corresponding performance metric (such as Net Profit, Profit Factor, and Kelly), there is often a pattern with what I call a "sweet spot", which is the area of bets performance which looks like a plateau, rather than a spike. Now, my argument is that identifying these areas using Profit Factor is just as useful as identifying them using Kelly. If you are using Kelly, the plateau is that elevated surface where a particular combination of parameter values (and the surrounding parameter values) yields high Kelly, meaning that in the neighborhood of certain values for N and K, the strategy is stable and is performing well. Now coming back to my previous 30-60 example, we are essentially saying that we have twice more the amount of confidence in strategy B, compared to that of strategy A, and as such, we'd rather trade strategy B. So, again, in JBT, Kelly is used for a non-conventional purpose: instead of using it to calculate the bet size relative to the account size, it's being used for ranking strategy parameters under optimization.

Now, having said that, there is nothing in JBT that prevents one from implementing Kelly the way you seem to suggest, namely calculating the position size based on the strategy historical performance. The IB API transmits account information, so it's straightforward to capture it. However, I have no plans for implementing it at that point. 

B

unread,
Sep 27, 2012, 5:07:09 PM9/27/12
to JBookTrader
That's all well and good, and there's nothing about what you wrote
about finding N and K that I disagree with. You're just performing a
search to find what parameters maximize expected returns in a single
asset portfolio. We're in agreement on this point. Parameter
searches can indeed take substantial computing power.

But that has nothing to do with my issues with the use of the kelly
fraction.

The question that the math behind kelly criterion answers is, "If I
have information, how much do I bet?".

That's it. That's all it's designed to do, because the kelly fraction
is a direct consequence when the question above is posed as a
mathematical equation. Given this, the kelly fraction for any given
asset changes when combined in a portfolio with other assets, and
other trading strategies.

What you're doing is using the answer posed by the above question as a
solution to a different question. Namely, "How do I know when I have
information?". And that requires a different set of math, because
it's fundamentally a different question.

I suspect you're using Kelly to gauge the presence of information, and
not as a tool for allocation, which flows from the math.

Now if the motivation behind jbooktrader is to facilitate automated
trading of assets using systems/strategies with positive expectation
of returns for the purpose of maximizing growth of your capital base,
I don't see how the use of kelly criterion to determine position size
could be overlooked, much less deliberately excluded.

Anyway, Ed Thorpe explains it better than I ever could.
http://web.williams.edu/go/math/sjmiller/public_html/341/handouts/Thorpe_KellyCriterion2007.pdf

If there are no plans for implementation, I hope you don't mind if I
fork JBookTrader at some point in the future.

Judson Wilson

unread,
Sep 28, 2012, 1:35:38 AM9/28/12
to jbook...@googlegroups.com
Just from a historical perspective, I can add a few comments. This
might help you understand why kelly isn't generally used to size bets
automatically with JBT.

1) I think Eugene (nonlinear) only trades ES, and JBookTrader is his
project to do this. He has been kind enough to add support for other
instruments, but when you start playing with it, it really is tailored
for ES. For example, for back testing data, JBT assumes a constant
bid/ask spread - something that you only see on the most liquid of
securities, or with the smallest (worst) price unit resolution. I
would argue that this is not a great model for stocks - but great for
ES.

2) Positions in ES are pretty heavy. If memory serves me correctly,
you are trading approximately a $50k position on margin for each
contract - possibly leveraged 5-10x +. For automated sizing based on
kelly to be useful, I would imagine you would need to have the ability
to wield many contracts - something that most of us simply don't have
the ability to do.

I am no expert on this topic, so feel free to correct any of my deductions.

I hope this helps you see "why" things are the way they are.
> --
> You received this message because you are subscribed to the Google Groups "JBookTrader" group.

nonlinear

unread,
Dec 15, 2012, 8:36:44 PM12/15/12
to jbook...@googlegroups.com

On Thursday, September 27, 2012 5:07:10 PM UTC-4, B wrote:

I suspect you're using Kelly to gauge the presence of information, and
not as a tool for allocation, which flows from the math.


In a way, JBT does use Kelly for allocation, but in a binary fashion. Specifically, if JBT optimizer finds 1 million of strategies with a crappy Kelly, I would discard them as the potential candidates for trading. If, on the other hand, JBT optimizer finds a cluster of strategies with a high Kelly, they would be elevated to the top of my list of strategies to trade. 

 
Reply all
Reply to author
Forward
0 new messages