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
public
string
Id
{
get
;
set
; }
35
36
/// <summary>
37
/// See <see cref="Insight.GroupId"/>
38
/// </summary>
39
public
string
GroupId
{
get
;
set
; }
40
41
/// <summary>
42
/// See <see cref="Insight.SourceModel"/>
43
/// </summary>
44
public
string
SourceModel
{
get
;
set
; }
45
46
/// <summary>
47
/// Pass-through for <see cref="CreatedTime"/>
48
/// </summary>
49
[Obsolete(
"Deprecated as of 2020-01-23. Please use the `CreatedTime` property instead."
)]
50
public
double
GeneratedTime
51
{
52
get
{
return
_createdTime; }
53
set
{ _createdTime = value; }
54
}
55
56
/// <summary>
57
/// See <see cref="Insight.GeneratedTimeUtc"/>
58
/// </summary>
59
public
double
CreatedTime
60
{
61
get
{
return
_createdTime; }
62
set
{ _createdTime = value; }
63
}
64
65
/// <summary>
66
/// See <see cref="Insight.CloseTimeUtc"/>
67
/// </summary>
68
public
double
CloseTime
{
get
;
set
; }
69
70
/// <summary>
71
/// See <see cref="Insight.Symbol"/>
72
/// The symbol's security identifier string
73
/// </summary>
74
public
string
Symbol
{
get
;
set
; }
75
76
/// <summary>
77
/// See <see cref="Insight.Symbol"/>
78
/// The symbol's ticker at the generated time
79
/// </summary>
80
public
string
Ticker
{
get
;
set
; }
81
82
/// <summary>
83
/// See <see cref="Insight.Type"/>
84
/// </summary>
85
public
InsightType
Type
{
get
;
set
; }
86
87
/// <summary>
88
/// See <see cref="Insight.ReferenceValue"/>
89
/// </summary>
90
[JsonProperty(
"reference"
)]
91
public
decimal
ReferenceValue
{
get
;
set
; }
92
93
/// <summary>
94
/// See <see cref="Insight.ReferenceValueFinal"/>
95
/// </summary>
96
public
decimal
ReferenceValueFinal
{
get
;
set
; }
97
98
/// <summary>
99
/// See <see cref="Insight.Direction"/>
100
/// </summary>
101
public
InsightDirection
Direction
{
get
;
set
; }
102
103
/// <summary>
104
/// See <see cref="Insight.Period"/>
105
/// </summary>
106
public
double
Period
{
get
;
set
; }
107
108
/// <summary>
109
/// See <see cref="Insight.Magnitude"/>
110
/// </summary>
111
[JsonConverter(typeof(
JsonRoundingConverter
))]
112
public
double
?
Magnitude
{
get
;
set
; }
113
114
/// <summary>
115
/// See <see cref="Insight.Confidence"/>
116
/// </summary>
117
[JsonConverter(typeof(
JsonRoundingConverter
))]
118
public
double
?
Confidence
{
get
;
set
; }
119
120
/// <summary>
121
/// See <see cref="Insight.Weight"/>
122
/// </summary>
123
public
double
?
Weight
{
get
;
set
; }
124
125
/// <summary>
126
/// See <see cref="InsightScore.IsFinalScore"/>
127
/// </summary>
128
public
bool
ScoreIsFinal
{
get
;
set
; }
129
130
/// <summary>
131
/// See <see cref="InsightScore.Magnitude"/>
132
/// </summary>
133
[JsonConverter(typeof(
JsonRoundingConverter
))]
134
public
double
ScoreMagnitude
{
get
;
set
; }
135
136
/// <summary>
137
/// See <see cref="InsightScore.Direction"/>
138
/// </summary>
139
[JsonConverter(typeof(
JsonRoundingConverter
))]
140
public
double
ScoreDirection
{
get
;
set
; }
141
142
/// <summary>
143
/// See <see cref="Insight.EstimatedValue"/>
144
/// </summary>
145
[JsonConverter(typeof(
JsonRoundingConverter
))]
146
public
decimal
EstimatedValue
{
get
;
set
; }
147
148
/// <summary>
149
/// See <see cref="Insight.Tag"/>
150
/// </summary>
151
public
string
Tag
{
get
;
set
; }
152
153
/// <summary>
154
/// Initializes a new default instance of the <see cref="SerializedInsight"/> class
155
/// </summary>
156
public
SerializedInsight
()
157
{
158
}
159
160
/// <summary>
161
/// Initializes a new instance of the <see cref="SerializedInsight "/> class by copying the specified insight
162
/// </summary>
163
/// <param name="insight">The insight to copy</param>
164
public
SerializedInsight
(
Insight
insight)
165
{
166
Id
= insight.
Id
.ToStringInvariant(
"N"
);
167
SourceModel
= insight.
SourceModel
;
168
GroupId
= insight.
GroupId
?.ToStringInvariant(
"N"
);
169
CreatedTime
=
Time
.
DateTimeToUnixTimeStamp
(insight.
GeneratedTimeUtc
);
170
CloseTime
=
Time
.
DateTimeToUnixTimeStamp
(insight.
CloseTimeUtc
);
171
Symbol
= insight.
Symbol
.
ID
.
ToString
();
172
Ticker
= insight.
Symbol
.
Value
;
173
Type
= insight.
Type
;
174
ReferenceValue
= insight.
ReferenceValue
;
175
ReferenceValueFinal
= insight.
ReferenceValueFinal
;
176
Direction
= insight.
Direction
;
177
Period
= insight.
Period
.TotalSeconds;
178
Magnitude
= insight.
Magnitude
;
179
Confidence
= insight.
Confidence
;
180
ScoreIsFinal
= insight.
Score
.
IsFinalScore
;
181
ScoreMagnitude
= insight.
Score
.
Magnitude
;
182
ScoreDirection
= insight.
Score
.
Direction
;
183
EstimatedValue
= insight.
EstimatedValue
;
184
Weight
= insight.
Weight
;
185
Tag
= insight.
Tag
;
186
}
187
188
#region BackwardsCompatibility
189
[JsonProperty(
"group-id"
)]
190
string
OldGroupId
191
{
192
set
193
{
194
GroupId
= value;
195
}
196
}
197
198
[JsonProperty(
"source-model"
)]
199
string
OldSourceModel
200
{
201
set
202
{
203
SourceModel
= value;
204
}
205
}
206
207
/// <summary>
208
/// Pass-through for <see cref="CreatedTime"/>
209
/// </summary>
210
[JsonProperty(
"generated-time"
)]
211
double
OldGeneratedTime
212
{
213
set
214
{
215
GeneratedTime
= value;
216
}
217
}
218
219
/// <summary>
220
/// See <see cref="Insight.GeneratedTimeUtc"/>
221
/// </summary>
222
[JsonProperty(
"created-time"
)]
223
public
double
OldCreatedTime
224
{
225
set
226
{
227
CreatedTime
= value;
228
}
229
}
230
231
/// <summary>
232
/// See <see cref="Insight.CloseTimeUtc"/>
233
/// </summary>
234
[JsonProperty(
"close-time"
)]
235
public
double
OldCloseTime
236
{
237
set
238
{
239
CloseTime
= value;
240
}
241
}
242
243
[JsonProperty(
"reference-final"
)]
244
decimal OldReferenceValueFinal
245
{
246
set
247
{
248
ReferenceValueFinal
= value;
249
}
250
}
251
252
[JsonProperty(
"score-final"
)]
253
bool
OldScoreIsFinal
254
{
255
set
256
{
257
ScoreIsFinal
= value;
258
}
259
}
260
261
[JsonProperty(
"score-magnitude"
)]
262
[JsonConverter(typeof(
JsonRoundingConverter
))]
263
double
OldScoreMagnitude
264
{
265
set
266
{
267
ScoreMagnitude
= value;
268
}
269
}
270
271
[JsonProperty(
"score-direction"
)]
272
[JsonConverter(typeof(
JsonRoundingConverter
))]
273
double
OldScoreDirection
274
{
275
set
276
{
277
ScoreDirection
= value;
278
}
279
}
280
281
[JsonProperty(
"estimated-value"
)]
282
[JsonConverter(typeof(
JsonRoundingConverter
))]
283
decimal OldEstimatedValue
284
{
285
set
286
{
287
EstimatedValue
= value;
288
}
289
}
290
#endregion
291
}
292
}
Common
Algorithm
Framework
Alphas
Serialization
SerializedInsight.cs
Generated by
1.8.17