Sharpe and Calmar Ratio

This entry is part 13 of 23 in the series Numpy Strategies

My publisher and others frown upon my tendency to write dirty finance examples. Of course, we wouldn’t want to corrupt young minds under any circumstance. So to satisfy my urges I am just writing here in my little corner on the Net. Let’s keep it quiet! Shhh shh …

You might have heard of the Sharpe ratio, which is presumably one of the most common metrics used to pick stocks. Unfortunately, this metric assumes a normal distribution and therefore doesn’t take into account tail risk, Black Swans etc. Another ratio, called the Calmar ratio, is more robust in this respect. It is similar to the Sharpe ratio, but uses the maximum returns drawdown instead of the standard deviation. The maximum drawdown is the largest drop of returns, when considering sequential tops and bottoms. It is the largest peak to through decline. The following NumPy code calculates both ratios for a number of high dividend ETFs, that I selected from http://finviz.com/screener.ashx?v=111&f=fa_div_high,ind_exchangetradedfund,sh_avgvol_o50,sh_opt_option and writes the results to a file. So these are optionable (for hedging) ETFs with a bit more then minimal volume. I also computed the ratios for SPY as a benchmark. Also note that I am cutting corners here and not bothering with the risk free rate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import sys
from scipy.signal import argrelmin, argrelmax
import csv
 
...
data download code omitted
...
 
c = df['Close']
rets = np.diff(np.log(c))
 
#convert to simple returns
rets = np.exp(rets) - 1
 
sharpe = rets.mean()/rets.std()
 
mins = np.ravel(argrelmin(rets))
maxs = np.ravel(argrelmax(rets))
extrema = np.concatenate((mins, maxs))
extrema.sort()
calmar = -rets.mean()/np.diff(rets[extrema]).min()
 
with open('out/ratios.csv', 'a') as fp:
    writer = csv.writer(fp, delimiter=',')
    row = [sys.argv[1], round(sharpe, 4), round(calmar, 4)]
    writer.writerow(row)

And I get the following table:

symbol,Sharpe,Calmar
SPY,0.0284,0.0014
AMLP,0.0267,0.0024
CVY,0.0078,0.0006
DWX,-0.0047,-0.0005
EDIV,-0.0267,-0.0041
EMLC,-0.0129,-0.0018
HYD,0.0213,0.0017
HYG,-0.0012,-0.0001
HYLD,0.0142,0.0009
IFGL,-0.0061,-0.0005
JNK,-0.0008,-0.0
MDIV,0.0301,0.0048
PCEF,0.001,0.0001
PFF,-0.0003,-0.0
PGF,0.0008,0.0001
PGX,-0.0032,-0.0002
PSP,-0.0055,-0.0004
REM,-0.0282,-0.0027
SDIV,0.0018,0.0003
SJNK,0.0347,0.0046

Clearly just a handful of the selected ETFs have a performance that is comparable to the SPY benchmark.

Series Navigation
By the author of NumPy Beginner's Guide, NumPy Cookbook and Instant Pygame. If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Share
This entry was posted in programming. Bookmark the permalink.