/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using Newtonsoft.Json; using QuantConnect.Util; using System; namespace QuantConnect.Algorithm.Framework.Alphas.Serialization { /// /// DTO used for serializing an insight that was just generated by an algorithm. /// This type does not contain any of the analysis dependent fields, such as scores /// and estimated value /// public class SerializedInsight { private double _createdTime; /// /// See /// public string Id { get; set; } /// /// See /// public string GroupId { get; set; } /// /// See /// public string SourceModel { get; set; } /// /// Pass-through for /// [Obsolete("Deprecated as of 2020-01-23. Please use the `CreatedTime` property instead.")] public double GeneratedTime { get { return _createdTime; } set { _createdTime = value; } } /// /// See /// public double CreatedTime { get { return _createdTime; } set { _createdTime = value; } } /// /// See /// public double CloseTime { get; set; } /// /// See /// The symbol's security identifier string /// public string Symbol { get; set; } /// /// See /// The symbol's ticker at the generated time /// public string Ticker { get; set; } /// /// See /// public InsightType Type { get; set; } /// /// See /// [JsonProperty("reference")] public decimal ReferenceValue { get; set; } /// /// See /// public decimal ReferenceValueFinal { get; set; } /// /// See /// public InsightDirection Direction { get; set; } /// /// See /// public double Period { get; set; } /// /// See /// [JsonConverter(typeof(JsonRoundingConverter))] public double? Magnitude { get; set; } /// /// See /// [JsonConverter(typeof(JsonRoundingConverter))] public double? Confidence { get; set; } /// /// See /// public double? Weight { get; set; } /// /// See /// public bool ScoreIsFinal { get; set; } /// /// See /// [JsonConverter(typeof(JsonRoundingConverter))] public double ScoreMagnitude { get; set; } /// /// See /// [JsonConverter(typeof(JsonRoundingConverter))] public double ScoreDirection { get; set; } /// /// See /// [JsonConverter(typeof(JsonRoundingConverter))] public decimal EstimatedValue { get; set; } /// /// See /// public string Tag { get; set; } /// /// Initializes a new default instance of the class /// public SerializedInsight() { } /// /// Initializes a new instance of the class by copying the specified insight /// /// The insight to copy public SerializedInsight(Insight insight) { Id = insight.Id.ToStringInvariant("N"); SourceModel = insight.SourceModel; GroupId = insight.GroupId?.ToStringInvariant("N"); CreatedTime = Time.DateTimeToUnixTimeStamp(insight.GeneratedTimeUtc); CloseTime = Time.DateTimeToUnixTimeStamp(insight.CloseTimeUtc); Symbol = insight.Symbol.ID.ToString(); Ticker = insight.Symbol.Value; Type = insight.Type; ReferenceValue = insight.ReferenceValue; ReferenceValueFinal = insight.ReferenceValueFinal; Direction = insight.Direction; Period = insight.Period.TotalSeconds; Magnitude = insight.Magnitude; Confidence = insight.Confidence; ScoreIsFinal = insight.Score.IsFinalScore; ScoreMagnitude = insight.Score.Magnitude; ScoreDirection = insight.Score.Direction; EstimatedValue = insight.EstimatedValue; Weight = insight.Weight; Tag = insight.Tag; } #region BackwardsCompatibility [JsonProperty("group-id")] string OldGroupId { set { GroupId = value; } } [JsonProperty("source-model")] string OldSourceModel { set { SourceModel = value; } } /// /// Pass-through for /// [JsonProperty("generated-time")] double OldGeneratedTime { set { GeneratedTime = value; } } /// /// See /// [JsonProperty("created-time")] public double OldCreatedTime { set { CreatedTime = value; } } /// /// See /// [JsonProperty("close-time")] public double OldCloseTime { set { CloseTime = value; } } [JsonProperty("reference-final")] decimal OldReferenceValueFinal { set { ReferenceValueFinal = value; } } [JsonProperty("score-final")] bool OldScoreIsFinal { set { ScoreIsFinal = value; } } [JsonProperty("score-magnitude")] [JsonConverter(typeof(JsonRoundingConverter))] double OldScoreMagnitude { set { ScoreMagnitude = value; } } [JsonProperty("score-direction")] [JsonConverter(typeof(JsonRoundingConverter))] double OldScoreDirection { set { ScoreDirection = value; } } [JsonProperty("estimated-value")] [JsonConverter(typeof(JsonRoundingConverter))] decimal OldEstimatedValue { set { EstimatedValue = value; } } #endregion } }