Hi,

New guy here.  I am writing a first pass algorythm to learn the platform and test some basic ideas.  Is this the right way to initialize my indicator groups?

I have a class called JustSomeIndicators which is a group of indicators.  I have a factory method called CreateIndicatorGroup() which creates instances of the JustSomeIndicators class.  I iterate over this factory method in a loop and hang on to the resulting objects in a dictionary called IndicatorsForEachSymbol.

The trouble is I keep getting exceptions in the OnData callback when I try to index the IndicatorsForEachSymbol dictionary using the symbol obtained from the Slice obect.

Am I going about this the right way?

PS: I have 300 or so lines of code but have shared what I hope is a relevant subset.

 

private Dictionary<Symbol, JustSomeIndicators> IndicatorsForEachSymbol = new Dictionary<Symbol, JustSomeIndicators>();

public override void Initialize()
{
SetWarmUp(TimeSpan.FromDays(Math.Max(SAMPLE_SIZE, 50)));
SetStartDate(2019, 1, 1);
SetEndDate(2020, 1, 1);
SetCash(100000);
ConfigureUniverse();
SetExecution(new ImmediateExecutionModel());
SetPortfolioConstruction(new NullPortfolioConstructionModel());
}

private void ConfigureUniverse()
{
AddUniverse(CoarseSelectionFunction, FineSelectionFunction);
UniverseSettings.Resolution = Resolution.Daily;
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
}

public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
return coarse
.Where(x => x.HasFundamentalData && x.DollarVolume > 10000000 && x.Price > 2)
.OrderByDescending(x => x.DollarVolume)
.Select(x => x.Symbol)
.ToList();
}

public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
return fine
.Where(x => x.MarketCap > 200000000)
.OrderByDescending(x => x.MarketCap)
.Select(x => x.Symbol)
.ToList();
}

public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var security in changes.AddedSecurities)
{
IndicatorsForEachSymbol.Add(security.Symbol, CreateIndicatorGroup(security.Symbol));
}
base.OnSecuritiesChanged(changes);
}

public override void OnData(Slice data)
{
foreach (Symbol symbol in data.Bars.Keys)
{
JustSomeIndicators indicators = IndicatorsForEachSymbol[symbol];
indicators.AddTradeBarToFifo(data.Bars[symbol]);
bool isHeld = false;
if (Portfolio.Securities.ContainsKey(symbol))
isHeld = Portfolio.Securities[symbol].HoldStock;
if (isHeld)
ConsiderSelling(symbol, data.Bars[symbol], indicators);
else
ConsiderBuying(symbol, data.Bars[symbol], indicators);
}
}