Supported Indicators

Target Downside Deviation

Introduction

This indicator computes the n-period target downside deviation. The target downside deviation is defined as the root-mean-square, or RMS, of the deviations of the realized return’s underperformance from the target return where all returns above the target return are treated as underperformance of 0. Reference: https://www.cmegroup.com/education/files/rr-sortino-a-sharper-ratio.pdf

Create Manual Indicators

You can manually create a TargetDownsideDeviation 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 TargetDownsideDeviation constructor.

TargetDownsideDeviation()1/2

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

return are treated as underperformance of 0.

TargetDownsideDeviation()2/2

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

return are treated as underperformance of 0.

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 TargetDownsideDeviation _tdd;

// In Initialize()
_tdd = new TargetDownsideDeviation(name, period);
_tdd.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _tdd, Resolution.Daily);

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

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

# In IndicatorUpdateMethod()
if self.tdd.IsReady:
    indicator_value = self.tdd.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 TargetDownsideDeviation _tdd;
private Symbol symbol;

// In Initialize()
_tdd = new TargetDownsideDeviation(period);
symbol = AddEquity("SPY").Symbol;

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

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

Create Automatic Indicators

The TDD method creates an TargetDownsideDeviation 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 TDD method:

TDD()1/1

            TargetDownsideDeviation QuantConnect.Algorithm.QCAlgorithm.TDD (
    Symbol                           symbol,
    Int32                            period,
    *Double                          minimumAcceptableReturn,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new TargetDownsideDeviation indicator. The target downside deviation is defined as the root-mean-square, or RMS, of the deviations of the realized return’s underperformance from the target return where all returns above the target return are treated as underperformance of 0.


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 TargetDownsideDeviation _tdd;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_tdd = TDD(symbol, period);

// In OnData()
if (_tdd.IsReady)
{
    var current = _tdd.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.tdd = self.TDD(symbol, period)

# In OnData()
if self.tdd.IsReady:
    current = self.tdd.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: