Skip to content

Insight

QuantConnect.Algorithm.Framework.Alphas.Insight

Insight(
    symbol: Union[Symbol, str, BaseContract],
    period: timedelta,
    type: InsightType,
    direction: InsightDirection,
    tag: str = ...,
)
Insight(
    symbol: Union[Symbol, str, BaseContract],
    period: timedelta,
    type: InsightType,
    direction: InsightDirection,
    magnitude: Optional[float],
    confidence: Optional[float],
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
)
Insight(
    symbol: Union[Symbol, str, BaseContract],
    expiry_func: Callable[[datetime], datetime],
    type: InsightType,
    direction: InsightDirection,
    tag: str = ...,
)
Insight(
    symbol: Union[Symbol, str, BaseContract],
    expiry_func: Callable[[datetime], datetime],
    type: InsightType,
    direction: InsightDirection,
    magnitude: Optional[float],
    confidence: Optional[float],
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
)
Insight(
    generated_time_utc: Union[datetime, date],
    symbol: Union[Symbol, str, BaseContract],
    period: timedelta,
    type: InsightType,
    direction: InsightDirection,
    magnitude: Optional[float],
    confidence: Optional[float],
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
)

Bases: Object

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

Signature descriptions:

  • Initializes a new instance of the Insight class

  • 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:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol this insight is for

required
period Optional[timedelta]

The period over which the prediction will come true

None
type InsightType

The type of insight, price/volatility

required
direction InsightDirection

The predicted direction

required
tag str

The insight's tag containing additional information

...
magnitude Optional[Optional[float]]

The predicted magnitude as a percentage change

None
confidence Optional[Optional[float]]

The confidence in this insight

None
source_model Optional[str]

An identifier defining the model that generated this insight

None
weight Optional[Optional[float]]

The portfolio weight of this insight

None
expiry_func Optional[Callable[[datetime], datetime]]

Func that defines the expiry time

None
generated_time_utc Optional[Union[datetime, date]]

The time this insight was generated in utc

None

id

id: Guid

Gets the unique identifier for this insight

group_id

group_id: Optional[Guid]

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

source_model

source_model: str

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

generated_time_utc

generated_time_utc: datetime

Gets the utc time this insight was generated

close_time_utc

close_time_utc: datetime

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

symbol

symbol: Symbol

Gets the symbol this insight is for

type

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

reference_value

reference_value: float

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

reference_value_final

reference_value_final: float

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

direction

direction: InsightDirection

Gets the predicted direction, down, flat or up

period

period: timedelta

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

magnitude

magnitude: Optional[float]

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

confidence

confidence: Optional[float]

Gets the confidence in this insight

weight

weight: Optional[float]

Gets the portfolio weight of this insight

score

score: InsightScore

Gets the most recent scores for this insight

estimated_value

estimated_value: float

Gets the estimated value of this insight in the account currency

tag

tag: str

The insight's tag containing additional information

compute_close_time

compute_close_time(
    exchange_hours: SecurityExchangeHours,
    generated_time_utc: Union[datetime, date],
    resolution: Resolution,
    bar_count: int,
) -> datetime
compute_close_time(
    exchange_hours: SecurityExchangeHours,
    generated_time_utc: Union[datetime, date],
    period: timedelta,
) -> datetime

Signature descriptions:

  • 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..

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

Parameters:

Name Type Description Default
exchange_hours SecurityExchangeHours

The exchange hours of the insight's security

required
generated_time_utc Union[datetime, date]

The insight's generated time in utc

required
resolution Optional[Resolution]

The resolution used to 'step-through' market hours to compute a reasonable close time

None
bar_count Optional[int]

The number of resolution steps to take

None
period Optional[timedelta]

The insight's period

None

Returns:

Type Description
datetime

The insight's closing time in utc.

group

group(
    *insights: Union[Insight, Iterable[Insight]]
) -> Iterable[Insight]
group(insight: Insight) -> Iterable[Insight]

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

Parameters:

Name Type Description Default
insights Union[Insight, Iterable[Insight]]

The insights to be grouped

()
insight Optional[Insight]

The insight to be grouped

None

price

price(
    symbol: Union[Symbol, str, BaseContract],
    resolution: Resolution,
    bar_count: int,
    direction: InsightDirection,
    magnitude: Optional[float] = None,
    confidence: Optional[float] = None,
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
) -> Insight
price(
    symbol: Union[Symbol, str, BaseContract],
    close_time_local: Union[datetime, date],
    direction: InsightDirection,
    magnitude: Optional[float] = None,
    confidence: Optional[float] = None,
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
) -> Insight
price(
    symbol: Union[Symbol, str, BaseContract],
    period: timedelta,
    direction: InsightDirection,
    magnitude: Optional[float] = None,
    confidence: Optional[float] = None,
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
) -> Insight
price(
    symbol: Union[Symbol, str, BaseContract],
    expiry_func: Callable[[datetime], datetime],
    direction: InsightDirection,
    magnitude: Optional[float] = None,
    confidence: Optional[float] = None,
    source_model: str = None,
    weight: Optional[float] = None,
    tag: str = ...,
) -> Insight

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

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol this insight is for

required
resolution Optional[Resolution]

The resolution used to define the insight's period and also used to determine the insight's close time

None
bar_count Optional[int]

The number of resolution time steps to make in market hours to compute the insight's closing time

None
direction InsightDirection

The predicted direction

required
magnitude Optional[float]

The predicted magnitude as a percent change

None
confidence Optional[float]

The confidence in this insight

None
source_model str

The model generating this insight

None
weight Optional[float]

The portfolio weight of this insight

None
tag str

The insight's tag containing additional information

...
close_time_local Optional[Union[datetime, date]]

The insight's closing time in the security's exchange time zone

None
period Optional[timedelta]

The period over which the prediction will come true

None
expiry_func Optional[Callable[[datetime], datetime]]

Func that defines the expiry time

None

Returns:

Type Description
Insight

A new insight object for the specified parameters.

cancel

cancel(utc_time: Union[datetime, date]) -> None

Cancel this insight

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The algorithm's current time in UTC. See IAlgorithm.UtcTime

required

clone

clone() -> Insight

Creates a deep clone of this insight instance

Returns:

Type Description
Insight

A new insight with identical values, but new instances.

expire

expire(utc_time: Union[datetime, date]) -> None

Expire this insight

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The algorithm's current time in UTC. See IAlgorithm.UtcTime

required

from_serialized_insight

from_serialized_insight(
    serialized_insight: SerializedInsight,
) -> Insight

Creates a new Insight object from the specified serialized form

Parameters:

Name Type Description Default
serialized_insight SerializedInsight

The insight DTO

required

Returns:

Type Description
Insight

A new insight containing the information specified.

is_active

is_active(utc_time: Union[datetime, date]) -> bool

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

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The algorithm's current time in UTC. See IAlgorithm.UtcTime

required

Returns:

Type Description
bool

True if this insight is active, false otherwise.

is_expired

is_expired(utc_time: Union[datetime, date]) -> bool

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

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The algorithm's current time in UTC. See IAlgorithm.UtcTime

required

Returns:

Type Description
bool

True if this insight is expired, false otherwise.

set_period_and_close_time

set_period_and_close_time(
    exchange_hours: SecurityExchangeHours,
) -> None

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

Parameters:

Name Type Description Default
exchange_hours SecurityExchangeHours

The insight's security exchange hours

required

short_to_string

short_to_string() -> str

Returns a short string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.