My next step is to quantify it, and run a test against a real trade distribution to see what it produces.
Okay, here is the quantification. I'll try to be very precise and detailed, to avoid any ambiguities, so that the results can be reproduced by anyone who wishes to try.
Let R be a series of trade returns:
R: {r(1), r(2), r(3), ..., r(N)},
where N is the number of trades,
r(
i) is the return on the
ith trade
Each trade return r is:
r = (S - B) / B,
where B is the price at which an instrument was bought,
and S is the price at which an instrument was sold.
(we'll ignore the commissions for simplicity).
For example, if we bought at $100 and sold at $110, then
r = (S - B) / B = (110 - 100) / 100 = 0.1
Notice that this formula is exactly the same for short and long trades. For example, if we sold short at $110, and bought back at $100, then this trade return r is
r = (S - B) / B = (110 - 100) / 100 = 0.1
Next, we define leveraged cumulative log return CR(L) as the sum up all individual leveraged returns in R as follows:
CR(L) = log(1 + L * r(1)) + log(1 + L * r(2)) + ... + log(1 + L * r(N)) [formula 1]
where log() is the natural logarithm,
L is leverage, L >= 0.
The reason for using log-returns instead of regular returns is that it's computationally more efficient. The result is the same as multiplying the returns, which gives us the total compounded return. The resulting quantity CR(L) is our terminal gain, given leverage L.
Next, we apply [formula 1] to all leverage levels, from L=0 to some arbitrary high leverage. Since CR(L) is convex, it will peak sooner or later. Now, we have a special value, max[CR(L)], which corresponds to the maximum gain, and the corresponding Kelly leverage KL, which is the level of L where CR(L) peaks. This is the
red point on the graph in my previous post.
Now, we can identify the thick red "identity line", which goes from [0,0] to [KL, CR(KL)]. The slope of that line is simply:
slope = CR(KL) / KL
With that, we can identify every point of the red line as:
CR(L) = L * slope
So, now we have a value of every point of the red line, and a value of every point of the blue line. With that, we can identify leverage L where the difference between the blue line and the red line reaches its largest value. That is, we want to maximize this delta D with respect to L:
D = CR(L) - (L * slope)
By maximizing D, we find what we were looking for: the
green point on the graph, which corresponds to the "optimal leverage" OL.
Now, let's do a sanity test by computing KL and OL for a well studied example, from
https://en.wikipedia.org/wiki/Kelly_criterion
There is a game where you have a 60% chance of winning, and 40% chance of losing. If you win, you get 100% of your bet (in addition to getting your bet back). If you lose, you lose your bet. How much do you bet? The wikipedia article says, "bet 20% of your bankroll at each opportunity".
Let's verify this by using the numerical methodology above (rather than the analytical solution provided by wikipedia).
Here is the (Java) code:
Code:
/**
* @author nonlinear5
*/
public class OptimalLeverageCalculator {
private final List<Double> tradeReturns;
private OptimalLeverageCalculator(List<Double> tradeReturns) {
this.tradeReturns = tradeReturns;
}
public static void main(String[] args) {
List<Double> tradeReturns = new ArrayList<>();
tradeReturns.add(1.0);
tradeReturns.add(1.0);
tradeReturns.add(1.0);
tradeReturns.add(1.0);
tradeReturns.add(1.0);
tradeReturns.add(1.0);
tradeReturns.add(-1.0);
tradeReturns.add(-1.0);
tradeReturns.add(-1.0);
tradeReturns.add(-1.0);
OptimalLeverageCalculator optimalLeverageCalculator = new OptimalLeverageCalculator(tradeReturns);
optimalLeverageCalculator.evaluateOptimalLeverage();
}
private double getGain(double leverage) {
double gain = 0;
for (double tradeReturn : tradeReturns) {
double leveragedReturn = leverage * tradeReturn;
double logLeveragedReturn = leveragedReturn > -1 ? Math.log1p(leveragedReturn) : Double.NEGATIVE_INFINITY;
gain += logLeveragedReturn;
}
return gain;
}
private void evaluateOptimalLeverage() {
double maxGain = 0, maxLeverage = 0, optimalLeverage = 0, deltaLeverage = 0.01;
for (double leverage = 0; leverage <= 2; leverage += deltaLeverage) {
double gain = getGain(leverage);
if (gain >= maxGain) {
maxGain = gain;
maxLeverage = leverage;
} else {
break;
}
}
double slope = maxGain / maxLeverage;
double maxDistance = 0;
for (double leverage = 0; leverage <= maxLeverage; leverage += deltaLeverage) {
double gain = getGain(leverage);
double identityGain = leverage * slope;
double distance = gain - identityGain;
if (distance >= maxDistance) {
maxDistance = distance;
optimalLeverage = leverage;
} else {
break;
}
}
System.out.println("Kelly leverage: " + maxLeverage);
System.out.println("Optimal leverage: " + optimalLeverage);
}
}
The output of running this code is:
Kelly leverage: 0.2
Optimal leverage: 0.1
So, my proposed numerical method agrees fully with the wikipedia's analytical solution (Kelly leverage = 0.2), and it also calculates the
green point (optimal leverage = 0.1), which is, logically enough, between L=0 and L=KL.
I welcome you to use this numerical solution, and to apply it to any given return distribution. I'd be interested to see if the results make sense for a wide variety of return distributions.