Supported Indicators

Sortino Ratio

Introduction

Calculation of the Sortino Ratio, a modification of the . Reference: https://www.cmegroup.com/education/files/rr-sortino-a-sharper-ratio.pdf Formula: S(x) = (R - T) / TDD Where: S(x) - Sortino ratio of x R - the average period return T - the target or required rate of return for the investment strategy under consideration. In Sortino’s early work, T was originally known as the minimum acceptable return, or MAR. In his more recent work, MAR is now referred to as the Desired Target Return. TDD - the target downside deviation.

Create Manual Indicators

You can manually create a SortinoRatio indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the SortinoRatio constructor.

SortinoRatio()1/2

            SortinoRatio QuantConnect.Indicators.SortinoRatio (
     string   name,
     int      period,
     *double  minimumAcceptableReturn
   )
        

Creates a new Sortino Ratio indicator using the specified periods.

SortinoRatio()2/2

            SortinoRatio QuantConnect.Indicators.SortinoRatio (
     int      period,
     *double  minimumAcceptableReturn
   )
        

Creates a new SortinoRatio indicator using the specified periods.

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.


private SortinoRatio _sortino;

// In Initialize()
_sortino = new SortinoRatio(name, period);
_sortino.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _sortino, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_sortino.IsReady)
{
    var indicatorValue = _sortino.Current.Value;
}
    
# In Initialize()
self.sortino = SortinoRatio(name, period)
self.sortino.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.sortino, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.sortino.IsReady:
    indicator_value = self.sortino.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update method with time/decimal pair. The indicator will only be ready after you prime it with enough data.

    
private SortinoRatio _sortino;
private Symbol symbol;

// In Initialize()
_sortino = new SortinoRatio(period);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.ContainsKey(_symbol))
{
    _sortino.Update(data[symbol].EndTime, data[symbol].High);
}
if (_sortino.IsReady)
{
    var indicatorValue = _sortino.Current.Value;
}
    
# In Initialize()
self.sortino = SortinoRatio(period)
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.ContainsKey(self.symbol):
    self.sortino.Update(data[self.symbol].EndTime, data[self.symbol].High)
if self.sortino.IsReady:
    indicator_value = self.sortino.Current.Value

Create Automatic Indicators

The SORTINO method creates an SortinoRatio indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the SORTINO method:

SORTINO()1/1

            SortinoRatio QuantConnect.Algorithm.QCAlgorithm.SORTINO (
    Symbol                           symbol,
    Int32                            sortinoPeriod,
    *Double                          minimumAcceptableReturn,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new Sortino indicator.


If you don't provide a resolution, it defaults to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private SortinoRatio _sortino;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_sortino = SORTINO(symbol, sortinoPeriod);

// In OnData()
if (_sortino.IsReady)
{
    var current = _sortino.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.sortino = self.SORTINO(symbol, sortinoPeriod)

# In OnData()
if self.sortino.IsReady:
    current = self.sortino.Current.Value

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: