17 using System.Collections.Generic;
21 using static System.FormattableString;
32 private readonly TimeSpan _period;
33 private readonly
double? _magnitude;
34 private readonly
double? _confidence;
35 private readonly
double? _weight;
36 private readonly HashSet<Security> _securities;
37 private readonly Dictionary<Symbol, DateTime> _insightsTimeBySymbol;
46 : this(type, direction, period, null, null)
62 _direction = direction;
66 _magnitude = magnitude;
67 _confidence = confidence;
70 _securities =
new HashSet<Security>();
71 _insightsTimeBySymbol =
new Dictionary<Symbol, DateTime>();
73 Name = $
"{nameof(ConstantAlphaModel)}({type},{direction},{period}";
74 if (magnitude.HasValue)
76 Name += Invariant($
",{magnitude.Value}");
79 if (confidence.HasValue)
81 Name += Invariant($
",{confidence.Value}");
95 foreach (var security
in _securities)
99 if (security.Price != 0
102 yield
return new Insight(security.Symbol, _period, _type, _direction, _magnitude, _confidence, weight: _weight);
117 foreach (var removed
in changes.RemovedSecurities)
119 _insightsTimeBySymbol.Remove(removed.Symbol);
135 DateTime generatedTimeUtc;
136 if (_insightsTimeBySymbol.TryGetValue(symbol, out generatedTimeUtc))
140 if (utcTime - generatedTimeUtc < _period)
148 _insightsTimeBySymbol[symbol] = utcTime;