Back

Problems with history and alphas

I'm trying to use a custom indicator with an alpha, and no matter how I try to do it it gives me a data mismatch. I've been spinning my wheels for days but there doesn't seem to be much out there.

in the alpha OnSecurityChanged event, I have 

// Initialize data for added securities
var symbols = changes.AddedSecurities.Select(x => x.Symbol);

algorithm.History(symbols, _numberOfBarsNeededForHistory, _resolution).PushThroughConsolidators(symbol =>
{
SymbolData symbolData;
if (!_symbolDataBySymbol.TryGetValue(symbol, out symbolData))
{
symbolData = new SymbolData(algorithm, symbol, _consolidatorTimeSpan);
_symbolDataBySymbol[symbol] = symbolData;
}

return symbolData.GetConsolidator();
});

In the SymbolData class

private class SymbolData
{
private readonly Symbol _symbol;
private readonly IDataConsolidator _consolidator;

private Tdi _tdiIndicator { get; }



public SymbolData(QCAlgorithm algorithm, Symbol symbol, TimeSpan consolidatorResolution)
{
_symbol = symbol;
_tdiIndicator = new Tdi();

_consolidator = algorithm.ResolveConsolidator(symbol, consolidatorResolution);
algorithm.RegisterIndicator(symbol, _tdiIndicator, _consolidator);
}

public bool IsReady {
get
{
return _tdiIndicator.IsReady;
}
}

internal void RemoveConsolidators(QCAlgorithm algorithm)
{
algorithm.SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
}

internal IDataConsolidator GetConsolidator()
{
return _consolidator;
}
}

And in the custom indicator class

public class Tdi : BarIndicator, IIndicatorWarmUpPeriodProvider
{

and

protected override decimal ComputeNextValue(IBaseDataBar input)
{

The error I get when I try to run this is 

System.ArgumentException: IndicatorBase.Update() 'input' expected to be of type QuantConnect.Indicators.IndicatorDataPoint but is of type QuantConnect.Data.Market.TradeBar
at QuantConnect.Indicators.IndicatorBase`1[T].Update (QuantConnect.Data.IBaseData input) [0x000aa] in <7096479a1e444df4a9f2ad9c767cb7f0>:0
at QuantConnect.Indicators.Tdi.ComputeNextValue (QuantConnect.Data.Market.IBaseDataBar input) [0x00001] in :0
at QuantConnect.Indicators.IndicatorBase`1[T].ValidateAndComputeNextValue (T input) [0x00000] in <7096479a1e444df4a9f2ad9c767cb7f0>:0
at QuantConnect.Indicators.IndicatorBase`1[T].Update (QuantConnect.Data.IBaseData input) [0x000bc] in <7096479a1e444df4a9f2ad9c767cb7f0>:0
at QuantConnect.Algorithm.QCAlgorithm+<>c__DisplayClass552_0`1[T].b__1 (System.Object sender, QuantConnect.Data.IBaseData consolidated) [0x0000e] in <48c39c54657e4638b08952dba8212e4d>:0
at QuantConnect.Data.Consolidators.DataConsolidator`1[TInput].OnDataConsolidated (QuantConnect.Data.IBaseData consolidated) [0x0000a] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.Consolidators.PeriodCountConsolidatorBase`2[T, TConsolidated].OnDataConsolidated (TConsolidated e) [0x00000] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.Consolidators.PeriodCountConsolidatorBase`2[T, TConsolidated].Update (T data) [0x001e0] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.Consolidators.DataConsolidator`1[TInput].Update (QuantConnect.Data.IBaseData data) [0x00037] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.SliceExtensions+<>c__DisplayClass10_0.b__0 (QuantConnect.Data.BaseData data) [0x0001b] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.SliceExtensions.PushThrough (System.Collections.Generic.IEnumerable`1[T] slices, System.Action`1[T] handler) [0x00095] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Data.SliceExtensions.PushThroughConsolidators (System.Collections.Generic.IEnumerable`1[T] slices, System.Func`2[T, TResult] consolidatorsProvider) [0x0000d] in <9974326b8fbc4e48acebad4ed7c9c9e4>:0
at QuantConnect.Algorithm.CSharp.Alphas.TDIAlphaModel.OnSecuritiesChanged (QuantConnect.Algorithm.QCAlgorithm algorithm, QuantConnect.Data.UniverseSelection.SecurityChanges changes) [0x000c5] in :0
at QuantConnect.Algorithm.QCAlgorithm.OnFrameworkSecuritiesChanged (QuantConnect.Data.UniverseSelection.SecurityChanges changes) [0x00030] in <48c39c54657e4638b08952dba8212e4d>:0
at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.ISynchronizer synchronizer, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions,

Any help would be very much appreciated.

 

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Is the history.pushthrough or history.pushthroughconsolidator needed when working with alphas and universe selection, or does the warmup period in the indicator automatically take care of the historical data? i.e. When a security is added to the universe and the symboldata is created including the initialization of the indicator, is the historical data automatically requested through the indicator warmup period or does it have to be pushed through by manually calling history and getting that information?

0

Hi Sam Smucker ,

As far as I can tell, the implementation looks right.
Could you please share an algorithm that reproduces the issue so that we can debug it?

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed