Blogs

Kelly Optimum Leverage For One Stock

This example calculates the optimumum leverage based on Kelly formula for one stock with long only position. 

These libraries will be needed:

import pandas_datareader.data as pdr
import pandas as pd

Get historical prices of a stock:

aapl = pdr.DataReader('AAPL', 'yahoo', start='2018-07-12', end='2022-06-30')

Calculate daily percentage price change:

aapl = aapl[['Adj Close']]
aapl['Change'] = aapl['Adj Close'].pct_change()
aapl.dropna(inplace=True)

 Calculate metrics:

avg_ret = aapl.Change.mean()*252
avg_std = aapl.Change.std()*np.sqrt(252)
riskfree_r = 0.04 # risk free rate at the sample time
excess_ret = (avg_ret - riskfree_r)

kelly = excess_ret / avg_std**2 # Kelly Optimum Leverage
sharpe = excess_ret / avg_std
cagr_levered =  riskfree_r + (sharpe**2)/2
cagr_unlevered = avg_ret - (avg_std**2)/2

The resulted metrics are: