/// <summary> /// Create a new pair /// </summary> /// <param name="algorithm">The algorithm instance that experienced the change in securities</param> /// <param name="asset1">The first asset's symbol in the pair</param> /// <param name="asset2">The second asset's symbol in the pair</param> /// <param name="period">Period over which this insight is expected to come to fruition</param> /// <param name="threshold">The percent [0, 100] deviation of the ratio from the mean before emitting an insight</param> public PairData(QCAlgorithm algorithm, Symbol asset1, Symbol asset2, TimeSpan period, decimal threshold) { _asset1 = asset1; _asset2 = asset2; _asset1Price = algorithm.Identity(asset1); _asset2Price = algorithm.Identity(asset2); _ratio = _asset1Price.Over(_asset2Price); _mean = new ExponentialMovingAverage(500).Of(_ratio); var upper = new ConstantIndicator <IndicatorDataPoint>("ct", 1 + threshold / 100m); _upperThreshold = _mean.Times(upper, "UpperThreshold"); var lower = new ConstantIndicator <IndicatorDataPoint>("ct", 1 - threshold / 100m); _lowerThreshold = _mean.Times(lower, "LowerThreshold"); _predictionInterval = period; }
public SymbolData(Symbol symbol, QCAlgorithm algorithm) { Symbol = symbol; Security = algorithm.Securities[symbol]; Close = algorithm.Identity(symbol); ADX = algorithm.ADX(symbol, 14); EMA = algorithm.EMA(symbol, 14); MACD = algorithm.MACD(symbol, 12, 26, 9); // if we're receiving daily _algorithm = algorithm; }