A Dead-Simple Hedge Ratio API

As the title suggests, I created a dead simple hedge ratio API called Risk Hedger. Also its free and the Python client is open source. So if you’re in to that kind of thing feel free to read on:

What is a Hedge Ratio?

Traders and investors buy/sell hedges when they want to reduce the risk of their portfolio. Additionally, certain strategies such as Pairs Trading rely on accurate estimation of hedge ratios for profitability.

What does the Risk Hedger do? And what do u mean simple?

Its an API with two main functions:

  • get_hedges( base ) : returns the current best symbols to use as hedges for a given base symbol
  • get_ratio( base , hedge) : returns the current hedge ratio for the given pair (base vs hedge) using a Kalman Filter pairs trading model.


Before I joined the startup game, way back as a European-shift trader, I used to spend a lot of time and effort making sure our hedge ratios were accurate and up to date. After I grew up I taught my junior traders in the dark arts of generating hedge ratios. But it was still a task that took time away from trading to implement and was prone to disastrous error.

Sometimes a trader would leave the CSV file holding the ratios open on their personal computer and the guy running the script wouldn’t notice. I’d come back from vacation and notice that our hedge ratios were a week old… Needless to say we traders have bigger fish to fry than thinking about our hedge ratio pipeline. Traders just want the hedge ratios to work so we can get to trading!

Moreover, this is something that everyone needs, whether your a pairs trading / stat arb guy or are trying to hedge a long portfolio. So everyone is constantly reinventing the wheel internally to every time they need a hedge. Or worse. Some just aren’t doing it right at all: I’ve met people running a prop desk (who have traded SIZE) who still get their beta’s from, gasp, Yahoo! Finance.

So how do I get it?

I’m a Python guy, so I created a Python client first.

You can install the Risk Hedger Python SDK using pip:

pip install risk_hedger

Feel free to let me know if you’re interested in contributing an R client or another language as you so choose. I’m making the client open source, just like slicematrixIO-python.

Then its only a matter of importing the package and creating a client. Remember to replace your API key in the code below. Get a free Risk Hedger API key.

import risk_hedger
io = risk_hedger.HedgeIO(api_key)

Now suppose we are interested in the hedge ratio between AAPL and GOOG:

io.get_ratio(base = "AAPL", hedge = "GOOG")
# output:{u'hedge_ratio': 0.3433113731632244}

Or maybe we want to find the best hedges for Agilent Technologies (A):


Which outputs a pandas dataframe like:

TMO   0.134141
PKI   0.161531
WAT   0.177464
ITW   0.177488
SWK   0.179677
RSG   0.220079
ADI   0.220296
MSFT  0.220570
CVX   0.220989
BBT   0.221543

The hedges are ranked by their distance from the base (or target) symbol. This distance is calculated from the similarity between their historic price returns.

The API key comes with up to 100 free requests per month. Assuming there are about 20 trading days in a month you can get the dynamic hedge ratios for 5 pairs on a daily basis, or any combination of pairs up to the free-tier limit.

Got any features you want to see added to the API???

Feel free to reach out at support@slicematrix.com. Just to let you know, I built the Risk Hedger API in less than 24 hours using two models from SliceMatrix-IO. For anyone interested, I’d be happy to teach you how you can build your own version of Risk Hedger, that way you can customize anyway you want, such as using your own data, or dynamically generating intraday hedge ratios, or generating trading signals / alerts.

*Note: the amazing picture used as the cover to this article comes from instagram user urari1224. Make sure to check out their profile for more awesome architecture shots in 日本.

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s