Beispiel #1
0
        /// <summary>
        /// Determines whether or not this context/insight can be analyzed for the specified score type
        /// </summary>
        /// <param name="scoreType">The type of insight score</param>
        /// <returns>True to proceed with analyzing this insight for the specified score type, false to skip analysis of the score type</returns>
        public bool ShouldAnalyze(InsightScoreType scoreType)
        {
            if (scoreType == InsightScoreType.Magnitude)
            {
                return(Insight.Magnitude.HasValue);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether or not this context/insight can be analyzed for the specified score type
        /// </summary>
        /// <param name="scoreType">The type of insight score</param>
        /// <returns>True to proceed with analyzing this insight for the specified score type, false to skip analysis of the score type</returns>
        public bool ShouldAnalyze(InsightScoreType scoreType)
        {
            if (scoreType == InsightScoreType.Magnitude)
            {
                return(Insight.Magnitude.HasValue);
            }
            else if (scoreType == InsightScoreType.Direction)
            {
                return(Insight.Direction != InsightDirection.Flat);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the specified score
        /// </summary>
        /// <param name="type">The type of score to get, Direction/Magnitude</param>
        /// <returns>The requested score</returns>
        public double GetScore(InsightScoreType type)
        {
            switch (type)
            {
            case InsightScoreType.Direction:
                return(Direction);

            case InsightScoreType.Magnitude:
                return(Magnitude);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Beispiel #4
0
        public void IgnoresFlatInsightsWithScore(InsightScoreType scoreType, InsightType insightType, double?magnitude)
        {
            var time              = new DateTime(2000, 01, 01);
            var stats             = new StatisticsInsightManagerExtension(new TestAccountCurrencyProvider());
            var insight           = new Insight(Symbols.SPY, TimeSpan.FromDays(1), insightType, InsightDirection.Flat, magnitude, null);
            var spySecurityValues = new SecurityValues(insight.Symbol, time, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), 100m, 1m, 125000, 1m);
            var context           = new InsightAnalysisContext(insight, spySecurityValues, insight.Period);

            context.Score.SetScore(InsightScoreType.Direction, .55, time);
            context.Score.SetScore(InsightScoreType.Magnitude, .25, time);
            stats.OnInsightAnalysisCompleted(context);
            Assert.AreEqual(0.0, stats.Statistics.RollingAveragedPopulationScore.Direction);
            Assert.AreEqual(0.0, stats.Statistics.RollingAveragedPopulationScore.Magnitude);
        }
        public void ShouldAnalyzeInsight(InsightScoreType scoreType,
                                         InsightType insightType,
                                         double?magnitude)
        {
            var context = new InsightAnalysisContext(
                new Insight(Symbols.SPY,
                            TimeSpan.FromDays(1),
                            insightType,
                            InsightDirection.Flat,
                            magnitude,
                            null),
                new SecurityValues(Symbols.SPY,
                                   new DateTime(2013, 1, 1),
                                   SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork),
                                   1, 1, 1, 1),
                TimeSpan.FromDays(1));

            Assert.AreEqual(false, context.ShouldAnalyze(scoreType));
        }
Beispiel #6
0
        /// <summary>
        /// Sets the specified score type with the value
        /// </summary>
        /// <param name="type">The score type to be set, Direction/Magnitude</param>
        /// <param name="value">The new value for the score</param>
        /// <param name="algorithmUtcTime">The algorithm's utc time at which time the new score was computed</param>
        internal void SetScore(InsightScoreType type, double value, DateTime algorithmUtcTime)
        {
            if (IsFinalScore)
            {
                return;
            }

            UpdatedTimeUtc = algorithmUtcTime;

            switch (type)
            {
            case InsightScoreType.Direction:
                Direction = Math.Max(0, Math.Min(1, value));
                break;

            case InsightScoreType.Magnitude:
                Magnitude = Math.Max(0, Math.Min(1, value));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Beispiel #7
0
        /// <inheritdoc />
        public double Evaluate(InsightAnalysisContext context, InsightScoreType scoreType)
        {
            var insight = context.Insight;

            var startingValue = context.InitialValues.Get(insight.Type);
            var currentValue  = context.CurrentValues.Get(insight.Type);

            switch (insight.Direction)
            {
            case InsightDirection.Down:
                return(currentValue < startingValue ? 1 : 0);

            case InsightDirection.Flat:
                // can't really do percent changes with zero
                if (startingValue == 0)
                {
                    return(currentValue == startingValue ? 1 : 0);
                }

                // TODO : Re-evaluate flat predictions, potentially adding Insight.Tolerance to say 'how flat'
                var deltaPercent = Math.Abs(currentValue - startingValue) / startingValue;
                if (insight.Magnitude.HasValue)
                {
                    return(Math.Abs(deltaPercent) < (decimal)Math.Abs(insight.Magnitude.Value) ? 1 : 0);
                }

                // this is pretty much impossible, I suppose unless the ticks are large and/or volumes are small
                return(currentValue == startingValue ? 1 : 0);

            case InsightDirection.Up:
                return(currentValue > startingValue ? 1 : 0);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #8
0
 /// <inheritdoc />
 public IInsightScoreFunction GetScoreFunction(InsightType insightType, InsightScoreType scoreType)
 {
     return(Function);
 }