# Code for a trading strategy with a 0.75 Sharpe

# Code for a trading strategy with a 0.75 Sharpe

In today’s guest post by QuantConnect, we build a trading strategy using exponential moving average crossover (EMAC) trend filters and carry forecasts.

Trading strategies based on trends are divergent in nature, while carry strategies are convergent.

Integrating both divergent and convergent strategies into a single algorithm allows for factor exposure diversification and enhances risk-adjusted returns.

Let’s jump in!

## Code for a trading strategy with a 0.75 Sharpe

The adjusted price of a Future, which represents the continuous contract price, does not precisely align with the underlying spot price.

This discrepancy arises because the adjusted price incorporates both returns from fluctuations in the underlying spot price and returns attributable to carry.

What makes up the carry return depends on what kind of asset you're trading.

To figure out the carry, think about a trade that would mimic owning the Future. For instance, if you want to mimic owning an S&P 500 Index Future, you'd need to borrow money to buy all the stocks in that Index.

You'd also get dividends as a plus. So, the carry would be the expected dividends you'd get before the Future runs out, minus the interest you'd pay on the borrowed money.

For example, in Forex, carry is the deposit rate minus the borrowing rate. For agricultural goods, carry is the convenience yield minus the sum of borrowing and storage costs.

Another way to figure out carry is by looking at the prices of two contracts that expire one after the other.

Let's say you're trading a Future with contracts that expire every month. The contract ending today costs $100, the next one costs $99, and the one after that costs $98.

If you buy the $99 contract and the main spot price stays the same, you can expect the contract to be worth $100 when it expires. This would give you a carry, or extra earning, of $1.

Positive carry exists because if you buy a Future with positive expected carry, you are essentially being rewarded for providing insurance against price depreciation in the underlying asset.

We can use the expected carry of a Future to produce forecasts in a trading strategy.

The strategy we’ll look at uses two parts: one is a trend forecast using EMAC, which is divergent in style, and the other is a smoothed carry forecast, which is convergent in style. Each part comes in different versions, like EMAC(16, 64), EMAC(64, 256), Carry(5), and Carry(20).

Using 40% of the convergent style and 60% of the divergent style, and giving equal importance to each version within those styles, gives the best Sharpe ratio.

After combining these forecasts with a 60%-40% mix, we adjust them with a multiplier to keep the average forecast at 10.

We then limit the final number to be between -20 and 20.

Get a look at the full code then backtest and deploy the strategy in a few minutes on the QuantConnect platform.