# Trading futures? Consider the Calmar ratio for performance analysis

# Trading futures? Consider the Calmar ratio for performance analysis

Trading futures is hard.

Especially when you have several systematic strategies to choose from.

When investors and traders have to allocate capital to their own portfolios, or invest with Commodity Trading Advisors (CTAs), they need a good way to compare performance.

Today, you'll get code to compute the Calmar ratio which is used just for this purpose.

## Trading futures? Consider the Calmar ratio for performance analysis

The Calmar ratio is a performance metric used to evaluate the risk-adjusted return of an investment strategy.

It was developed by Terry W. Young in 1991 and named after California Managed Accounts Research Inc. (Calmar), where Young was a principal.

The ratio is calculated by dividing the annualized return of an investment strategy by its maximum drawdown.

Professionals in the finance industry use the Calmar ratio to compare the performance of different investment strategies and to assess the risk-adjusted return of a single strategy.

By understanding the Calmar ratio, investors can make more informed decisions about which investment strategies to pursue and how to allocate their capital.

And the best part?

You can easily calculate the Calmar ratio using Python.

## Imports and set up

First, import the libraries you’ll use. You can get continuous futures data from the OpenBB SDK. We’ll use Numpy for the math.

```
1from openbb_terminal.sdk import openbb
2
3import numpy as np
```

From there, set up a few mock portfolios. For this example, I’ll build an under leveraged futures portfolio and a leveraged futures portfolio. This will demonstrate the effect leverage has on risk.

```
1data = openbb.futures.historical(
2 ["ES", "YM", "NQ"],
3 start_date="2020-01-01",
4 end_date="2022-12-31"
5)
6
7futs = data['Adj Close'].pct_change().dropna()
```

This code get continuous futures data for the E-Mini S&P 500 Index, E-Mini Dow Jones Industrial Average, and E-Mini Nasdaq 100. The settlement price is returned in the “Adj Close” column. Use it to compute the daily returns.

Let’s create two mock portfolios.

```
1port_1 = futs.ES * 0.60 + futs.YM * 0.10 + futs.NQ * 0.10
2
3port_2 = futs.ES * 0.90 + futs.YM * 0.15 + futs.NQ * 0.15
```

Apply a weighting to each of the symbols. Note the weights add up to less that 1 for port_1 and greater than 1 for port_2. This is an easy way to replicate an under- and over-leveraged portfolio. Also note that the weights for port_2 are 1.5x that of port_1.

## Compute the Calmar ratio

Next, write a function that computes the Calmar ratio.

```
1def ann_return(returns):
2 ending_value = (returns + 1).prod()
3 num_years = len(returns) / 252 # daily returns
4 ann_return = ending_value ** (1/num_years) - 1
5 return ann_return
6
7
8def calmar_ratio(returns):
9
10 # cumulative returns
11 cumulative_returns = (returns + 1).cumprod() * 100
12
13 # max drawdown
14 max_return = np.fmax.accumulate(cumulative_returns)
15 max_dd = ((cumulative_returns - max_return) / max_return).min()
16
17 # annualized return
18 ann_ret = ann_return(returns)
19
20 return ann_ret / abs(max_dd)
```

First, write a helper function to compute the annual returns. Since we’re dealing with daily return data, use 252 to represent the number of trading days. To annualize the portfolio return, raise the final return to 1 divided by the years in the market and subtract 1.

In the function for the Calmar ratio, generate the cumulative returns of the daily portfolio returns. Use that to compute the maximum drawdown. np.fmax.accumulate keeps track of the maximum value of a time series. Then, find the largest negative percent change from the cumulative returns and the maximum return.

The Calmar ratio is the annual return divided by the max drawdown.

## Compare portfolio performance

Check out the results.

```
1# port1
2ret = ann_return(port_1)
3p1 = calmar_ratio(port_1)
4
5# port2
6ret = ann_return(port_2)
7p2 = calmar_ratio(port_2)
```

You should see that even though the second portfolio has a greater return, it has a lower Calmar ratio. That tells you that you’re taking on a higher risk (larger drawdown) in the second portfolio.

The Calmar ratio is commonly used by professional investors to assess the performance of CTAs.

Now you can use it too.