public void SurvivesRoundTripCopy() { var time = new DateTime(2000, 01, 02, 03, 04, 05, 06); var original = new Insight(time, Symbols.SPY, Time.OneMinute, InsightType.Volatility, InsightDirection.Up, 1, 2, "source-model"); Insight.Group(original); var copy = original.Clone(); Assert.AreEqual(original.CloseTimeUtc, copy.CloseTimeUtc); Assert.AreEqual(original.Confidence, copy.Confidence); Assert.AreEqual(original.Direction, copy.Direction); Assert.AreEqual(original.EstimatedValue, copy.EstimatedValue); Assert.AreEqual(original.GeneratedTimeUtc, copy.GeneratedTimeUtc); Assert.AreEqual(original.GroupId, copy.GroupId); Assert.AreEqual(original.Id, copy.Id); Assert.AreEqual(original.Magnitude, copy.Magnitude); Assert.AreEqual(original.Period, copy.Period); Assert.AreEqual(original.SourceModel, copy.SourceModel); Assert.AreEqual(original.Score.Direction, copy.Score.Direction); Assert.AreEqual(original.Score.Magnitude, copy.Score.Magnitude); Assert.AreEqual(original.Score.UpdatedTimeUtc, copy.Score.UpdatedTimeUtc); Assert.AreEqual(original.Score.IsFinalScore, copy.Score.IsFinalScore); Assert.AreEqual(original.Symbol, copy.Symbol); Assert.AreEqual(original.Type, copy.Type); }
public void SurvivesRoundTripSerializationUsingJsonConvert() { var time = new DateTime(2000, 01, 02, 03, 04, 05, 06); var insight = new Insight(time, Symbols.SPY, Time.OneMinute, InsightType.Volatility, InsightDirection.Up, 1, 2, "source-model"); Insight.Group(insight); var serialized = JsonConvert.SerializeObject(insight); var deserialized = JsonConvert.DeserializeObject <Insight>(serialized); Assert.AreEqual(insight.CloseTimeUtc, deserialized.CloseTimeUtc); Assert.AreEqual(insight.Confidence, deserialized.Confidence); Assert.AreEqual(insight.Direction, deserialized.Direction); Assert.AreEqual(insight.EstimatedValue, deserialized.EstimatedValue); Assert.AreEqual(insight.GeneratedTimeUtc, deserialized.GeneratedTimeUtc); Assert.AreEqual(insight.GroupId, deserialized.GroupId); Assert.AreEqual(insight.Id, deserialized.Id); Assert.AreEqual(insight.Magnitude, deserialized.Magnitude); Assert.AreEqual(insight.Period, deserialized.Period); Assert.AreEqual(insight.SourceModel, deserialized.SourceModel); Assert.AreEqual(insight.Score.Direction, deserialized.Score.Direction); Assert.AreEqual(insight.Score.Magnitude, deserialized.Score.Magnitude); Assert.AreEqual(insight.Score.UpdatedTimeUtc, deserialized.Score.UpdatedTimeUtc); Assert.AreEqual(insight.Score.IsFinalScore, deserialized.Score.IsFinalScore); Assert.AreEqual(insight.Symbol, deserialized.Symbol); Assert.AreEqual(insight.Type, deserialized.Type); }
public void GroupThrowsExceptionIfInsightAlreadyHasGroupId() { var insight1 = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); Insight.Group(insight1); Assert.That(() => Insight.Group(insight1), Throws.InvalidOperationException); }
public override IEnumerable <Insight> Update(QCAlgorithm algorithm, Slice data) { // Check to make sure all currency symbols are present if (data.QuoteBars.Count < 3) { return(Enumerable.Empty <Insight>()); } // Extract QuoteBars for all three Forex securities var barA = data[_symbols[0]]; var barB = data[_symbols[1]]; var barC = data[_symbols[2]]; // Calculate the triangle exchange rate // Bid(Currency A -> Currency B) * Bid(Currency B -> Currency C) * Bid(Currency C -> Currency A) // If exchange rates are priced perfectly, then this yield 1.If it is different than 1, then an arbitrage opportunity exists var triangleRate = barA.Ask.Close / barB.Bid.Close / barC.Ask.Close; // If the triangle rate is significantly different than 1, then emit insights if (triangleRate > 1.0005m) { return(Insight.Group(new[] { Insight.Price(_symbols[0], _insightPeriod, InsightDirection.Up, 0.0001), Insight.Price(_symbols[1], _insightPeriod, InsightDirection.Down, 0.0001), Insight.Price(_symbols[2], _insightPeriod, InsightDirection.Up, 0.0001) })); } return(Enumerable.Empty <Insight>()); }
public override IEnumerable <Insight> Update(QCAlgorithm algorithm, Slice data) { return(Insight.Group(new[] { Insight.Price(_ultraLong, _period, InsightDirection.Down, _magnitude), Insight.Price(_ultraShort, _period, InsightDirection.Down, _magnitude) })); }
public void GroupAssignsGroupId() { var insight1 = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); var insight2 = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); var groupId = Insight.Group(insight1, insight2); Assert.AreEqual(groupId, insight1.GroupId); Assert.AreEqual(groupId, insight2.GroupId); }
public override IEnumerable <Insight> Update(QCAlgorithmFramework algorithm, Slice data) { // Check to see if either ticker will return a NoneBar, and skip the data slice if so if (data.Bars.Count < 2) { return(Enumerable.Empty <Insight>()); } // If Alpha and Beta haven't been calculated yet, then do so if (_alpha == 0 || _beta == 0) { CalculateAlphaBeta(algorithm); } // Update indicator and Rolling Window for each data slice passed into Update() method if (!UpdateIndicators(data)) { return(Enumerable.Empty <Insight>()); } // Check to see if the portfolio is invested. If no, then perform value comparisons and emit insights accordingly if (!_invested) { //Reset invested boolean _invested = true; if (_positionWindow[0] > _sma) { return(Insight.Group(new[] { Insight.Price(_longSymbol, _insightPeriod, InsightDirection.Down, _insightMagnitude), Insight.Price(_shortSymbol, _insightPeriod, InsightDirection.Up, _insightMagnitude), })); } else { return(Insight.Group(new[] { Insight.Price(_longSymbol, _insightPeriod, InsightDirection.Up, _insightMagnitude), Insight.Price(_shortSymbol, _insightPeriod, InsightDirection.Down, _insightMagnitude), })); } } // If the portfolio is invested and crossed back over the SMA, then emit flat insights else if (_invested && CrossedMean()) { _invested = false; } return(Enumerable.Empty <Insight>()); }
public void GroupAssignsGroupId() { var insight1 = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); var insight2 = Insight.Price(Symbols.SPY, Time.OneMinute, InsightDirection.Up); var group = Insight.Group(insight1, insight2).ToList(); foreach (var member in group) { Assert.IsTrue(member.GroupId.HasValue); } var groupId = insight1.GroupId.Value; foreach (var member in group) { Assert.AreEqual(groupId, member.GroupId); } }