Lean
$LEAN_TAG$
SerializedInsight.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
using
Newtonsoft.Json;
17
using
QuantConnect
.
Util
;
18
using
System;
19
20
namespace
QuantConnect.Algorithm.Framework.Alphas.Serialization
21
{
22
/// <summary>
23
/// DTO used for serializing an insight that was just generated by an algorithm.
24
/// This type does not contain any of the analysis dependent fields, such as scores
25
/// and estimated value
26
/// </summary>
27
public
class
SerializedInsight
28
{
29
private
double
_createdTime;
30
31
/// <summary>
32
/// See <see cref="Insight.Id"/>
33
/// </summary>
34
[JsonProperty(
"id"
)]
35
public
string
Id
{
get
;
set
; }
36
37
/// <summary>
38
/// See <see cref="Insight.GroupId"/>
39
/// </summary>
40
[JsonProperty(
"group-id"
)]
41
public
string
GroupId
{
get
;
set
; }
42
43
/// <summary>
44
/// See <see cref="Insight.SourceModel"/>
45
/// </summary>
46
[JsonProperty(
"source-model"
)]
47
public
string
SourceModel
{
get
;
set
; }
48
49
/// <summary>
50
/// Pass-through for <see cref="CreatedTime"/>
51
/// </summary>
52
[Obsolete(
"Deprecated as of 2020-01-23. Please use the `CreatedTime` property instead."
)]
53
[JsonProperty(
"generated-time"
)]
54
public
double
GeneratedTime
55
{
56
get
{
return
_createdTime; }
57
set
{ _createdTime = value; }
58
}
59
60
/// <summary>
61
/// See <see cref="Insight.GeneratedTimeUtc"/>
62
/// </summary>
63
[JsonProperty(
"created-time"
)]
64
public
double
CreatedTime
65
{
66
get
{
return
_createdTime; }
67
set
{ _createdTime = value; }
68
}
69
70
/// <summary>
71
/// See <see cref="Insight.CloseTimeUtc"/>
72
/// </summary>
73
[JsonProperty(
"close-time"
)]
74
public
double
CloseTime
{
get
;
set
; }
75
76
/// <summary>
77
/// See <see cref="Insight.Symbol"/>
78
/// The symbol's security identifier string
79
/// </summary>
80
[JsonProperty(
"symbol"
)]
81
public
string
Symbol
{
get
;
set
; }
82
83
/// <summary>
84
/// See <see cref="Insight.Symbol"/>
85
/// The symbol's ticker at the generated time
86
/// </summary>
87
[JsonProperty(
"ticker"
)]
88
public
string
Ticker
{
get
;
set
; }
89
90
/// <summary>
91
/// See <see cref="Insight.Type"/>
92
/// </summary>
93
[JsonProperty(
"type"
)]
94
public
InsightType
Type
{
get
;
set
; }
95
96
/// <summary>
97
/// See <see cref="Insight.ReferenceValue"/>
98
/// </summary>
99
[JsonProperty(
"reference"
)]
100
public
decimal
ReferenceValue
{
get
;
set
; }
101
102
/// <summary>
103
/// See <see cref="Insight.ReferenceValueFinal"/>
104
/// </summary>
105
[JsonProperty(
"reference-final"
)]
106
public
decimal
ReferenceValueFinal
{
get
;
set
; }
107
108
/// <summary>
109
/// See <see cref="Insight.Direction"/>
110
/// </summary>
111
[JsonProperty(
"direction"
)]
112
public
InsightDirection
Direction
{
get
;
set
; }
113
114
/// <summary>
115
/// See <see cref="Insight.Period"/>
116
/// </summary>
117
[JsonProperty(
"period"
)]
118
public
double
Period
{
get
;
set
; }
119
120
/// <summary>
121
/// See <see cref="Insight.Magnitude"/>
122
/// </summary>
123
[JsonProperty(
"magnitude"
)]
124
[JsonConverter(typeof(
JsonRoundingConverter
))]
125
public
double
?
Magnitude
{
get
;
set
; }
126
127
/// <summary>
128
/// See <see cref="Insight.Confidence"/>
129
/// </summary>
130
[JsonProperty(
"confidence"
)]
131
[JsonConverter(typeof(
JsonRoundingConverter
))]
132
public
double
?
Confidence
{
get
;
set
; }
133
134
/// <summary>
135
/// See <see cref="Insight.Weight"/>
136
/// </summary>
137
[JsonProperty(
"weight"
)]
138
public
double
?
Weight
{
get
;
set
; }
139
140
/// <summary>
141
/// See <see cref="InsightScore.IsFinalScore"/>
142
/// </summary>
143
[JsonProperty(
"score-final"
)]
144
public
bool
ScoreIsFinal
{
get
;
set
; }
145
146
/// <summary>
147
/// See <see cref="InsightScore.Magnitude"/>
148
/// </summary>
149
[JsonProperty(
"score-magnitude"
)]
150
[JsonConverter(typeof(
JsonRoundingConverter
))]
151
public
double
ScoreMagnitude
{
get
;
set
; }
152
153
/// <summary>
154
/// See <see cref="InsightScore.Direction"/>
155
/// </summary>
156
[JsonProperty(
"score-direction"
)]
157
[JsonConverter(typeof(
JsonRoundingConverter
))]
158
public
double
ScoreDirection
{
get
;
set
; }
159
160
/// <summary>
161
/// See <see cref="Insight.EstimatedValue"/>
162
/// </summary>
163
[JsonProperty(
"estimated-value"
)]
164
[JsonConverter(typeof(
JsonRoundingConverter
))]
165
public
decimal
EstimatedValue
{
get
;
set
; }
166
167
/// <summary>
168
/// See <see cref="Insight.Tag"/>
169
/// </summary>
170
[JsonProperty(
"tag"
)]
171
public
string
Tag
{
get
;
set
; }
172
173
/// <summary>
174
/// Initializes a new default instance of the <see cref="SerializedInsight"/> class
175
/// </summary>
176
public
SerializedInsight
()
177
{
178
}
179
180
/// <summary>
181
/// Initializes a new instance of the <see cref="SerializedInsight "/> class by copying the specified insight
182
/// </summary>
183
/// <param name="insight">The insight to copy</param>
184
public
SerializedInsight
(
Insight
insight)
185
{
186
Id
= insight.
Id
.ToStringInvariant(
"N"
);
187
SourceModel
= insight.
SourceModel
;
188
GroupId
= insight.
GroupId
?.ToStringInvariant(
"N"
);
189
CreatedTime
=
Time
.
DateTimeToUnixTimeStamp
(insight.
GeneratedTimeUtc
);
190
CloseTime
=
Time
.
DateTimeToUnixTimeStamp
(insight.
CloseTimeUtc
);
191
Symbol
= insight.
Symbol
.
ID
.
ToString
();
192
Ticker
= insight.
Symbol
.
Value
;
193
Type
= insight.
Type
;
194
ReferenceValue
= insight.
ReferenceValue
;
195
ReferenceValueFinal
= insight.
ReferenceValueFinal
;
196
Direction
= insight.
Direction
;
197
Period
= insight.
Period
.TotalSeconds;
198
Magnitude
= insight.
Magnitude
;
199
Confidence
= insight.
Confidence
;
200
ScoreIsFinal
= insight.
Score
.
IsFinalScore
;
201
ScoreMagnitude
= insight.
Score
.
Magnitude
;
202
ScoreDirection
= insight.
Score
.
Direction
;
203
EstimatedValue
= insight.
EstimatedValue
;
204
Weight
= insight.
Weight
;
205
Tag
= insight.
Tag
;
206
}
207
}
208
}
Common
Algorithm
Framework
Alphas
Serialization
SerializedInsight.cs
Generated by
1.8.17