Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConstantAlphaModel"/> class
        /// </summary>
        /// <param name="type">The type of insight</param>
        /// <param name="direction">The direction of the insight</param>
        /// <param name="period">The period over which the insight with come to fruition</param>
        /// <param name="magnitude">The predicted change in magnitude as a +- percentage</param>
        /// <param name="confidence">The confidence in the insight</param>
        public ConstantAlphaModel(InsightType type, InsightDirection direction, TimeSpan period, double?magnitude, double?confidence)
        {
            _type      = type;
            _direction = direction;
            _period    = period;

            // Optional
            _magnitude  = magnitude;
            _confidence = confidence;

            _securities           = new HashSet <Security>();
            _insightsTimeBySymbol = new Dictionary <Symbol, DateTime>();

            Name = $"{nameof(ConstantAlphaModel)}({type},{direction},{period}";
            if (magnitude.HasValue)
            {
                Name += $",{magnitude.Value}";
            }

            if (confidence.HasValue)
            {
                Name += $",{confidence.Value}";
            }

            Name += ")";
        }
Пример #2
0
        /// <summary>
        /// Private constructor used to keep track of how a user defined the insight period.
        /// </summary>
        /// <param name="symbol">The symbol this insight is for</param>
        /// <param name="periodSpec">A specification defining how the insight's period was defined, via time span, via resolution/barcount, via close time</param>
        /// <param name="type">The type of insight, price/volatility</param>
        /// <param name="direction">The predicted direction</param>
        /// <param name="magnitude">The predicted magnitude as a percentage change</param>
        /// <param name="confidence">The confidence in this insight</param>
        /// <param name="sourceModel">An identifier defining the model that generated this insight</param>
        /// <param name="weight">The portfolio weight of this insight</param>
        private Insight(Symbol symbol, IPeriodSpecification periodSpec, InsightType type, InsightDirection direction, double?magnitude, double?confidence, string sourceModel = null, double?weight = null)
        {
            Id          = Guid.NewGuid();
            Score       = new InsightScore();
            SourceModel = sourceModel;

            Symbol    = symbol;
            Type      = type;
            Direction = direction;

            // Optional
            Magnitude  = magnitude;
            Confidence = confidence;
            Weight     = weight;

            _periodSpecification = periodSpec;

            // keep existing behavior of Insight.Price such that we set the period immediately
            var period = (periodSpec as TimeSpanPeriodSpecification)?.Period;

            if (period != null)
            {
                Period = period.Value;
            }
        }
Пример #3
0
        public void AddConsumer(InsightType insightType, IAnalysisConsumer analysisConsumer, ConsumeOptions options)
        {
            switch (insightType)
            {
            case InsightType.PartitionInsight:
                if (this.partitionInsightGenerator != null)
                {
                    this.partitionInsightGenerator.AddConsumer(analysisConsumer, options);
                }

                break;

            case InsightType.ReplicaInsight:
                break;

            case InsightType.CodePackageInsight:
                break;

            case InsightType.NodeInsight:
                break;

            case InsightType.ClusterInsight:
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Insight Type '{0}' is currently not supported", insightType));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConstantAlphaModel"/> class
        /// </summary>
        /// <param name="type">The type of insight</param>
        /// <param name="direction">The direction of the insight</param>
        /// <param name="period">The period over which the insight with come to fruition</param>
        /// <param name="magnitude">The predicted change in magnitude as a +- percentage</param>
        /// <param name="confidence">The confidence in the insight</param>
        public ConstantAlphaModel(InsightType type, InsightDirection direction, TimeSpan period, double?magnitude, double?confidence)
        {
            _type      = type;
            _direction = direction;
            _period    = period;

            // Optional
            _magnitude  = magnitude;
            _confidence = confidence;

            _securities           = new HashSet <Security>();
            _insightsTimeBySymbol = new Dictionary <Symbol, DateTime>();
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Insight"/> class
        /// </summary>
        /// <param name="symbol">The symbol this insight is for</param>
        /// <param name="type">The type of insight, price/volatility</param>
        /// <param name="direction">The predicted direction</param>
        /// <param name="period">The period over which the prediction will come true</param>
        /// <param name="magnitude">The predicted magnitude as a percentage change</param>
        /// <param name="confidence">The confidence in this insight</param>
        public Insight(Symbol symbol, InsightType type, InsightDirection direction, TimeSpan period, double?magnitude, double?confidence)
        {
            Id    = Guid.NewGuid();
            Score = new InsightScore();

            Symbol    = symbol;
            Type      = type;
            Direction = direction;
            Period    = period;

            // Optional
            Magnitude  = magnitude;
            Confidence = confidence;
        }
Пример #7
0
        /// <summary>
        /// Gets the security value corresponding to the specified insight type
        /// </summary>
        /// <param name="type">The insight type</param>
        /// <returns>The security value for the specified insight type</returns>
        public decimal Get(InsightType type)
        {
            switch (type)
            {
            case InsightType.Price:
                return(Price);

            case InsightType.Volatility:
                return(Volatility);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Insight"/> class
        /// </summary>
        /// <param name="symbol">The symbol this insight is for</param>
        /// <param name="period">The period over which the prediction will come true</param>
        /// <param name="type">The type of insight, price/volatility</param>
        /// <param name="direction">The predicted direction</param>
        /// <param name="magnitude">The predicted magnitude as a percentage change</param>
        /// <param name="confidence">The confidence in this insight</param>
        /// <param name="sourceModel">An identifier defining the model that generated this insight</param>
        public Insight(Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction, double? magnitude, double? confidence, string sourceModel = null)
        {
            Id = Guid.NewGuid();
            Score = new InsightScore();
            SourceModel = sourceModel;

            Symbol = symbol;
            Type = type;
            Direction = direction;
            Period = period;

            // Optional
            Magnitude = magnitude;
            Confidence = confidence;

            _periodSpecification = new TimeSpanPeriodSpecification(period);
        }
        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));
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Insight"/> class
 /// </summary>
 /// <param name="symbol">The symbol this insight is for</param>
 /// <param name="period">The period over which the prediction will come true</param>
 /// <param name="type">The type of insight, price/volatility</param>
 /// <param name="direction">The predicted direction</param>
 public Insight(Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction)
     : this(symbol, period, type, direction, null, null)
 {
 }
Пример #11
0
 /// <inheritdoc />
 public IInsightScoreFunction GetScoreFunction(InsightType insightType, InsightScoreType scoreType)
 {
     return(Function);
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantAlphaModel"/> class
 /// </summary>
 /// <param name="type">The type of insight</param>
 /// <param name="direction">The direction of the insight</param>
 /// <param name="period">The period over which the insight with come to fruition</param>
 public ConstantAlphaModel(InsightType type, InsightDirection direction, TimeSpan period)
     : this(type, direction, period, null, null)
 {
 }
Пример #13
0
        public InsightsMetadata CreateInsightsMetadata(string messageName, string mappingId, InsightType insightType)
        {
            var millisecondsSinceEpoch = _unixTimestampGenerator.GenerateTimestamp();

            return(new InsightsMetadata
            {
                Name = messageName,
                InsightMappingId = mappingId,
                InsightType = insightType,
                Tags = new Dictionary <string, string>
                {
                    { "language", "csharp" }
                },
                Timestamp = millisecondsSinceEpoch
            });
        }
Пример #14
0
 public AlphaStreamInsight(DateTime generatedTimeUtc, Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction,
                           double?magnitude, double?confidence, string sourceModel = null, double?weight = null) :
     base(generatedTimeUtc, symbol, period, type, direction, magnitude, confidence, sourceModel, weight)
 {
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Insight"/> class.
 /// This constructor is provided mostly for testing purposes. When running inside an algorithm,
 /// the generated and close times are set based on the algorithm's time.
 /// </summary>
 /// <param name="generatedTimeUtc">The time this insight was generated in utc</param>
 /// <param name="symbol">The symbol this insight is for</param>
 /// <param name="type">The type of insight, price/volatility</param>
 /// <param name="direction">The predicted direction</param>
 /// <param name="period">The period over which the prediction will come true</param>
 /// <param name="magnitude">The predicted magnitude as a percentage change</param>
 /// <param name="confidence">The confidence in this insight</param>
 public Insight(DateTime generatedTimeUtc, Symbol symbol, InsightType type, InsightDirection direction, TimeSpan period, double?magnitude, double?confidence)
     : this(symbol, type, direction, period, magnitude, confidence)
 {
     GeneratedTimeUtc = generatedTimeUtc;
     CloseTimeUtc     = generatedTimeUtc + period;
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Insight"/> class
 /// </summary>
 /// <param name="symbol">The symbol this insight is for</param>
 /// <param name="expiryFunc">Func that defines the expiry time</param>
 /// <param name="type">The type of insight, price/volatility</param>
 /// <param name="direction">The predicted direction</param>
 /// <param name="magnitude">The predicted magnitude as a percentage change</param>
 /// <param name="confidence">The confidence in this insight</param>
 /// <param name="sourceModel">An identifier defining the model that generated this insight</param>
 /// <param name="weight">The portfolio weight of this insight</param>
 public Insight(Symbol symbol, Func <DateTime, DateTime> expiryFunc, InsightType type, InsightDirection direction, double?magnitude, double?confidence, string sourceModel = null, double?weight = null)
     : this(symbol, new FuncPeriodSpecification(expiryFunc), type, direction, magnitude, confidence, sourceModel, weight)
 {
 }
 public DerivedInsight(Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction)
     : base(symbol, period, type, direction)
 {
 }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Insight"/> class.
 /// This constructor is provided mostly for testing purposes. When running inside an algorithm,
 /// the generated and close times are set based on the algorithm's time.
 /// </summary>
 /// <param name="generatedTimeUtc">The time this insight was generated in utc</param>
 /// <param name="symbol">The symbol this insight is for</param>
 /// <param name="period">The period over which the prediction will come true</param>
 /// <param name="type">The type of insight, price/volatility</param>
 /// <param name="direction">The predicted direction</param>
 /// <param name="magnitude">The predicted magnitude as a percentage change</param>
 /// <param name="confidence">The confidence in this insight</param>
 /// <param name="sourceModel">An identifier defining the model that generated this insight</param>
 public Insight(DateTime generatedTimeUtc, Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction, double? magnitude, double? confidence, string sourceModel = null)
     : this(symbol, period, type, direction, magnitude, confidence, sourceModel)
 {
     GeneratedTimeUtc = generatedTimeUtc;
     CloseTimeUtc = generatedTimeUtc + period;
 }
Пример #19
0
 public ConstantFutureContractAlphaModel(InsightType type, InsightDirection direction, TimeSpan period)
     : base(type, direction, period)
 {
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Insight"/> class
 /// </summary>
 /// <param name="symbol">The symbol this insight is for</param>
 /// <param name="expiryFunc">Func that defines the expiry time</param>
 /// <param name="type">The type of insight, price/volatility</param>
 /// <param name="direction">The predicted direction</param>
 public Insight(Symbol symbol, Func <DateTime, DateTime> expiryFunc, InsightType type, InsightDirection direction)
     : this(symbol, expiryFunc, type, direction, null, null)
 {
 }