Lean  $LEAN_TAG$
QuantConnect.Algorithm.Framework.Alphas.Insight Class Reference

Defines a alpha prediction for a single symbol generated by the algorithm More...

Public Member Functions

bool IsExpired (DateTime utcTime)
 Determines whether or not this insight is considered expired at the specified utcTime More...
 
bool IsActive (DateTime utcTime)
 Determines whether or not this insight is considered active at the specified utcTime More...
 
void Expire (DateTime utcTime)
 Expire this insight More...
 
void Cancel (DateTime utcTime)
 Cancel this insight More...
 
 Insight (Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction, string tag="")
 Initializes a new instance of the Insight class More...
 
 Insight (Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction, double? magnitude, double? confidence, string sourceModel=null, double? weight=null, string tag="")
 Initializes a new instance of the Insight class More...
 
 Insight (Symbol symbol, Func< DateTime, DateTime > expiryFunc, InsightType type, InsightDirection direction, string tag="")
 Initializes a new instance of the Insight class More...
 
 Insight (Symbol symbol, Func< DateTime, DateTime > expiryFunc, InsightType type, InsightDirection direction, double? magnitude, double? confidence, string sourceModel=null, double? weight=null, string tag="")
 Initializes a new instance of the Insight class More...
 
 Insight (DateTime generatedTimeUtc, Symbol symbol, TimeSpan period, InsightType type, InsightDirection direction, double? magnitude, double? confidence, string sourceModel=null, double? weight=null, string tag="")
 Initializes a new instance of the 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. More...
 
void SetPeriodAndCloseTime (SecurityExchangeHours exchangeHours)
 Sets the insight period and close times if they have not already been set. More...
 
virtual Insight Clone ()
 Creates a deep clone of this insight instance More...
 
override string ToString ()
 Returns a string that represents the current object. More...
 
string ShortToString ()
 Returns a short string that represents the current object. More...
 

Static Public Member Functions

static Insight Price (Symbol symbol, Resolution resolution, int barCount, InsightDirection direction, double? magnitude=null, double? confidence=null, string sourceModel=null, double? weight=null, string tag="")
 Creates a new insight for predicting the percent change in price over the specified period More...
 
static Insight Price (Symbol symbol, DateTime closeTimeLocal, InsightDirection direction, double? magnitude=null, double? confidence=null, string sourceModel=null, double? weight=null, string tag="")
 Creates a new insight for predicting the percent change in price over the specified period More...
 
static Insight Price (Symbol symbol, TimeSpan period, InsightDirection direction, double? magnitude=null, double? confidence=null, string sourceModel=null, double? weight=null, string tag="")
 Creates a new insight for predicting the percent change in price over the specified period More...
 
static Insight Price (Symbol symbol, Func< DateTime, DateTime > expiryFunc, InsightDirection direction, double? magnitude=null, double? confidence=null, string sourceModel=null, double? weight=null, string tag="")
 Creates a new insight for predicting the percent change in price over the specified period More...
 
static IEnumerable< InsightGroup (params Insight[] insights)
 Creates a new, unique group id and sets it on each insight More...
 
static IEnumerable< InsightGroup (Insight insight)
 Creates a new, unique group id and sets it on each insight More...
 
static Insight FromSerializedInsight (SerializedInsight serializedInsight)
 Creates a new Insight object from the specified serialized form More...
 
static DateTime ComputeCloseTime (SecurityExchangeHours exchangeHours, DateTime generatedTimeUtc, Resolution resolution, int barCount)
 Computes the insight closing time from the given generated time, resolution and bar count. This will step through market hours using the given resolution, respecting holidays, early closes, weekends, etc.. More...
 
static DateTime ComputeCloseTime (SecurityExchangeHours exchangeHours, DateTime generatedTimeUtc, TimeSpan period)
 computs the insight closing time from the given generated time and period More...
 

Properties

Guid Id [get, protected set]
 Gets the unique identifier for this insight More...
 
Guid? GroupId [get, protected set]
 Gets the group id this insight belongs to, null if not in a group More...
 
string SourceModel [get, set]
 Gets an identifier for the source model that generated this insight. More...
 
DateTime GeneratedTimeUtc [get, set]
 Gets the utc time this insight was generated More...
 
DateTime CloseTimeUtc [get, set]
 Gets the insight's prediction end time. This is the time when this insight prediction is expected to be fulfilled. This time takes into account market hours, weekends, as well as the symbol's data resolution More...
 
Symbol Symbol [get]
 Gets the symbol this insight is for More...
 
InsightType Type [get]
 Gets the type of insight, for example, price insight or volatility insight More...
 
decimal ReferenceValue [get, set]
 Gets the initial reference value this insight is predicting against. The value is dependent on the specified InsightType More...
 
decimal ReferenceValueFinal [get, set]
 Gets the final reference value, used for scoring, this insight is predicting against. The value is dependent on the specified InsightType More...
 
InsightDirection Direction [get]
 Gets the predicted direction, down, flat or up More...
 
TimeSpan Period [get, set]
 Gets the period over which this insight is expected to come to fruition More...
 
double? Magnitude [get]
 Gets the predicted percent change in the insight type (price/volatility) More...
 
double? Confidence [get]
 Gets the confidence in this insight More...
 
double? Weight [get]
 Gets the portfolio weight of this insight More...
 
InsightScore Score [get, protected set]
 Gets the most recent scores for this insight More...
 
decimal EstimatedValue [get, set]
 Gets the estimated value of this insight in the account currency More...
 
string Tag [get, protected set]
 The insight's tag containing additional information More...
 

Detailed Description

Defines a alpha prediction for a single symbol generated by the algorithm

Serialization of this type is delegated to the InsightJsonConverter which uses the SerializedInsight as a model.

Definition at line 32 of file Insight.cs.

Constructor & Destructor Documentation

◆ Insight() [1/5]

QuantConnect.Algorithm.Framework.Alphas.Insight.Insight ( Symbol  symbol,
TimeSpan  period,
InsightType  type,
InsightDirection  direction,
string  tag = "" 
)

Initializes a new instance of the Insight class

Parameters
symbolThe symbol this insight is for
periodThe period over which the prediction will come true
typeThe type of insight, price/volatility
directionThe predicted direction
tagThe insight's tag containing additional information

Definition at line 178 of file Insight.cs.

Here is the caller graph for this function:

◆ Insight() [2/5]

QuantConnect.Algorithm.Framework.Alphas.Insight.Insight ( Symbol  symbol,
TimeSpan  period,
InsightType  type,
InsightDirection  direction,
double?  magnitude,
double?  confidence,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)

Initializes a new instance of the Insight class

Parameters
symbolThe symbol this insight is for
periodThe period over which the prediction will come true
typeThe type of insight, price/volatility
directionThe predicted direction
magnitudeThe predicted magnitude as a percentage change
confidenceThe confidence in this insight
sourceModelAn identifier defining the model that generated this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information

Definition at line 195 of file Insight.cs.

◆ Insight() [3/5]

QuantConnect.Algorithm.Framework.Alphas.Insight.Insight ( Symbol  symbol,
Func< DateTime, DateTime >  expiryFunc,
InsightType  type,
InsightDirection  direction,
string  tag = "" 
)

Initializes a new instance of the Insight class

Parameters
symbolThe symbol this insight is for
expiryFuncFunc that defines the expiry time
typeThe type of insight, price/volatility
directionThe predicted direction
tagThe insight's tag containing additional information

Definition at line 223 of file Insight.cs.

◆ Insight() [4/5]

QuantConnect.Algorithm.Framework.Alphas.Insight.Insight ( Symbol  symbol,
Func< DateTime, DateTime >  expiryFunc,
InsightType  type,
InsightDirection  direction,
double?  magnitude,
double?  confidence,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)

Initializes a new instance of the Insight class

Parameters
symbolThe symbol this insight is for
expiryFuncFunc that defines the expiry time
typeThe type of insight, price/volatility
directionThe predicted direction
magnitudeThe predicted magnitude as a percentage change
confidenceThe confidence in this insight
sourceModelAn identifier defining the model that generated this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information

Definition at line 240 of file Insight.cs.

◆ Insight() [5/5]

QuantConnect.Algorithm.Framework.Alphas.Insight.Insight ( DateTime  generatedTimeUtc,
Symbol  symbol,
TimeSpan  period,
InsightType  type,
InsightDirection  direction,
double?  magnitude,
double?  confidence,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)

Initializes a new instance of the 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.

Parameters
generatedTimeUtcThe time this insight was generated in utc
symbolThe symbol this insight is for
periodThe period over which the prediction will come true
typeThe type of insight, price/volatility
directionThe predicted direction
magnitudeThe predicted magnitude as a percentage change
confidenceThe confidence in this insight
sourceModelAn identifier defining the model that generated this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information

Definition at line 260 of file Insight.cs.

Member Function Documentation

◆ IsExpired()

bool QuantConnect.Algorithm.Framework.Alphas.Insight.IsExpired ( DateTime  utcTime)

Determines whether or not this insight is considered expired at the specified utcTime

Parameters
utcTimeThe algorithm's current time in UTC. See IAlgorithm.UtcTime
Returns
True if this insight is expired, false otherwise

Definition at line 133 of file Insight.cs.

Here is the caller graph for this function:

◆ IsActive()

bool QuantConnect.Algorithm.Framework.Alphas.Insight.IsActive ( DateTime  utcTime)

Determines whether or not this insight is considered active at the specified utcTime

Parameters
utcTimeThe algorithm's current time in UTC. See IAlgorithm.UtcTime
Returns
True if this insight is active, false otherwise

Definition at line 143 of file Insight.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Expire()

void QuantConnect.Algorithm.Framework.Alphas.Insight.Expire ( DateTime  utcTime)

Expire this insight

Parameters
utcTimeThe algorithm's current time in UTC. See IAlgorithm.UtcTime

Definition at line 152 of file Insight.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cancel()

void QuantConnect.Algorithm.Framework.Alphas.Insight.Cancel ( DateTime  utcTime)

Cancel this insight

Parameters
utcTimeThe algorithm's current time in UTC. See IAlgorithm.UtcTime

Definition at line 165 of file Insight.cs.

Here is the call graph for this function:

◆ SetPeriodAndCloseTime()

void QuantConnect.Algorithm.Framework.Alphas.Insight.SetPeriodAndCloseTime ( SecurityExchangeHours  exchangeHours)

Sets the insight period and close times if they have not already been set.

Parameters
exchangeHoursThe insight's security exchange hours

Definition at line 309 of file Insight.cs.

◆ Clone()

virtual Insight QuantConnect.Algorithm.Framework.Alphas.Insight.Clone ( )
virtual

Creates a deep clone of this insight instance

Returns
A new insight with identical values, but new instances

Definition at line 323 of file Insight.cs.

Here is the call graph for this function:

◆ Price() [1/4]

static Insight QuantConnect.Algorithm.Framework.Alphas.Insight.Price ( Symbol  symbol,
Resolution  resolution,
int  barCount,
InsightDirection  direction,
double?  magnitude = null,
double?  confidence = null,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)
static

Creates a new insight for predicting the percent change in price over the specified period

Parameters
symbolThe symbol this insight is for
resolutionThe resolution used to define the insight's period and also used to determine the insight's close time
barCountThe number of resolution time steps to make in market hours to compute the insight's closing time
directionThe predicted direction
magnitudeThe predicted magnitude as a percent change
confidenceThe confidence in this insight
sourceModelThe model generating this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information
Returns
A new insight object for the specified parameters

Definition at line 352 of file Insight.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Price() [2/4]

static Insight QuantConnect.Algorithm.Framework.Alphas.Insight.Price ( Symbol  symbol,
DateTime  closeTimeLocal,
InsightDirection  direction,
double?  magnitude = null,
double?  confidence = null,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)
static

Creates a new insight for predicting the percent change in price over the specified period

Parameters
symbolThe symbol this insight is for
closeTimeLocalThe insight's closing time in the security's exchange time zone
directionThe predicted direction
magnitudeThe predicted magnitude as a percent change
confidenceThe confidence in this insight
sourceModelThe model generating this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information
Returns
A new insight object for the specified parameters

Definition at line 375 of file Insight.cs.

Here is the call graph for this function:

◆ Price() [3/4]

static Insight QuantConnect.Algorithm.Framework.Alphas.Insight.Price ( Symbol  symbol,
TimeSpan  period,
InsightDirection  direction,
double?  magnitude = null,
double?  confidence = null,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)
static

Creates a new insight for predicting the percent change in price over the specified period

Parameters
symbolThe symbol this insight is for
periodThe period over which the prediction will come true
directionThe predicted direction
magnitudeThe predicted magnitude as a percent change
confidenceThe confidence in this insight
sourceModelThe model generating this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information
Returns
A new insight object for the specified parameters

Definition at line 394 of file Insight.cs.

Here is the call graph for this function:

◆ Price() [4/4]

static Insight QuantConnect.Algorithm.Framework.Alphas.Insight.Price ( Symbol  symbol,
Func< DateTime, DateTime >  expiryFunc,
InsightDirection  direction,
double?  magnitude = null,
double?  confidence = null,
string  sourceModel = null,
double?  weight = null,
string  tag = "" 
)
static

Creates a new insight for predicting the percent change in price over the specified period

Parameters
symbolThe symbol this insight is for
expiryFuncFunc that defines the expiry time
directionThe predicted direction
magnitudeThe predicted magnitude as a percent change
confidenceThe confidence in this insight
sourceModelThe model generating this insight
weightThe portfolio weight of this insight
tagThe insight's tag containing additional information
Returns
A new insight object for the specified parameters

Definition at line 418 of file Insight.cs.

Here is the call graph for this function:

◆ Group() [1/2]

static IEnumerable<Insight> QuantConnect.Algorithm.Framework.Alphas.Insight.Group ( params Insight[]  insights)
static

Creates a new, unique group id and sets it on each insight

Parameters
insightsThe insights to be grouped

Definition at line 427 of file Insight.cs.

◆ Group() [2/2]

static IEnumerable<Insight> QuantConnect.Algorithm.Framework.Alphas.Insight.Group ( Insight  insight)
static

Creates a new, unique group id and sets it on each insight

Parameters
insightThe insight to be grouped

◆ FromSerializedInsight()

static Insight QuantConnect.Algorithm.Framework.Alphas.Insight.FromSerializedInsight ( SerializedInsight  serializedInsight)
static

Creates a new Insight object from the specified serialized form

Parameters
serializedInsightThe insight DTO
Returns
A new insight containing the information specified

Definition at line 458 of file Insight.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeCloseTime() [1/2]

static DateTime QuantConnect.Algorithm.Framework.Alphas.Insight.ComputeCloseTime ( SecurityExchangeHours  exchangeHours,
DateTime  generatedTimeUtc,
Resolution  resolution,
int  barCount 
)
static

Computes the insight closing time from the given generated time, resolution and bar count. This will step through market hours using the given resolution, respecting holidays, early closes, weekends, etc..

Parameters
exchangeHoursThe exchange hours of the insight's security
generatedTimeUtcThe insight's generated time in utc
resolutionThe resolution used to 'step-through' market hours to compute a reasonable close time
barCountThe number of resolution steps to take
Returns
The insight's closing time in utc

Definition at line 513 of file Insight.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeCloseTime() [2/2]

static DateTime QuantConnect.Algorithm.Framework.Alphas.Insight.ComputeCloseTime ( SecurityExchangeHours  exchangeHours,
DateTime  generatedTimeUtc,
TimeSpan  period 
)
static

computs the insight closing time from the given generated time and period

Parameters
exchangeHoursThe exchange hours of the insight's security
generatedTimeUtcThe insight's generated time in utc
periodThe insight's period
Returns
The insight's closing time in utc

Definition at line 543 of file Insight.cs.

Here is the call graph for this function:

◆ ToString()

override string QuantConnect.Algorithm.Framework.Alphas.Insight.ToString ( )

Returns a string that represents the current object.

Returns
A string that represents the current object.

<filterpriority>2</filterpriority>

Definition at line 591 of file Insight.cs.

◆ ShortToString()

string QuantConnect.Algorithm.Framework.Alphas.Insight.ShortToString ( )

Returns a short string that represents the current object.

Returns
A string that represents the current object.

Definition at line 600 of file Insight.cs.

Property Documentation

◆ Id

Guid QuantConnect.Algorithm.Framework.Alphas.Insight.Id
getprotected set

Gets the unique identifier for this insight

Definition at line 39 of file Insight.cs.

◆ GroupId

Guid? QuantConnect.Algorithm.Framework.Alphas.Insight.GroupId
getprotected set

Gets the group id this insight belongs to, null if not in a group

Definition at line 44 of file Insight.cs.

◆ SourceModel

string QuantConnect.Algorithm.Framework.Alphas.Insight.SourceModel
getset

Gets an identifier for the source model that generated this insight.

Definition at line 49 of file Insight.cs.

◆ GeneratedTimeUtc

DateTime QuantConnect.Algorithm.Framework.Alphas.Insight.GeneratedTimeUtc
getset

Gets the utc time this insight was generated

The algorithm framework handles setting this value appropriately. If providing custom Insight implementation, be sure to set this value to algorithm.UtcTime when the insight is generated.

Definition at line 59 of file Insight.cs.

◆ CloseTimeUtc

DateTime QuantConnect.Algorithm.Framework.Alphas.Insight.CloseTimeUtc
getset

Gets the insight's prediction end time. This is the time when this insight prediction is expected to be fulfilled. This time takes into account market hours, weekends, as well as the symbol's data resolution

Definition at line 66 of file Insight.cs.

◆ Symbol

Symbol QuantConnect.Algorithm.Framework.Alphas.Insight.Symbol
get

Gets the symbol this insight is for

Definition at line 71 of file Insight.cs.

◆ Type

InsightType QuantConnect.Algorithm.Framework.Alphas.Insight.Type
get

Gets the type of insight, for example, price insight or volatility insight

Definition at line 76 of file Insight.cs.

◆ ReferenceValue

decimal QuantConnect.Algorithm.Framework.Alphas.Insight.ReferenceValue
getset

Gets the initial reference value this insight is predicting against. The value is dependent on the specified InsightType

Definition at line 81 of file Insight.cs.

◆ ReferenceValueFinal

decimal QuantConnect.Algorithm.Framework.Alphas.Insight.ReferenceValueFinal
getset

Gets the final reference value, used for scoring, this insight is predicting against. The value is dependent on the specified InsightType

Definition at line 86 of file Insight.cs.

◆ Direction

InsightDirection QuantConnect.Algorithm.Framework.Alphas.Insight.Direction
get

Gets the predicted direction, down, flat or up

Definition at line 91 of file Insight.cs.

◆ Period

TimeSpan QuantConnect.Algorithm.Framework.Alphas.Insight.Period
getset

Gets the period over which this insight is expected to come to fruition

Definition at line 96 of file Insight.cs.

◆ Magnitude

double? QuantConnect.Algorithm.Framework.Alphas.Insight.Magnitude
get

Gets the predicted percent change in the insight type (price/volatility)

Definition at line 101 of file Insight.cs.

◆ Confidence

double? QuantConnect.Algorithm.Framework.Alphas.Insight.Confidence
get

Gets the confidence in this insight

Definition at line 106 of file Insight.cs.

◆ Weight

double? QuantConnect.Algorithm.Framework.Alphas.Insight.Weight
get

Gets the portfolio weight of this insight

Definition at line 111 of file Insight.cs.

◆ Score

InsightScore QuantConnect.Algorithm.Framework.Alphas.Insight.Score
getprotected set

Gets the most recent scores for this insight

Definition at line 116 of file Insight.cs.

◆ EstimatedValue

decimal QuantConnect.Algorithm.Framework.Alphas.Insight.EstimatedValue
getset

Gets the estimated value of this insight in the account currency

Definition at line 121 of file Insight.cs.

◆ Tag

string QuantConnect.Algorithm.Framework.Alphas.Insight.Tag
getprotected set

The insight's tag containing additional information

Definition at line 126 of file Insight.cs.


The documentation for this class was generated from the following file: