Skip to content

InsightManager

QuantConnect.Algorithm.Framework.Alphas.Analysis.InsightManager

InsightManager(algorithm: IAlgorithm)

Bases: InsightCollection

Encapsulates the storage of insights.

Creates a new instance

Parameters:

Name Type Description Default
algorithm IAlgorithm

The associated algorithm instance

required

count

count: int

The open insight count

total_count

total_count: int

The total insight count

cancel

cancel(symbols: List[Symbol]) -> None
cancel(insights: List[Insight]) -> None

Signature descriptions:

  • Cancel the insights of the given symbols

  • Cancel the given insights

Parameters:

Name Type Description Default
symbols Optional[List[Symbol]]

Symbol we want to cancel insights for

None
insights Optional[List[Insight]]

Insights to cancel

None

expire

expire(symbols: List[Symbol]) -> None
expire(insights: List[Insight]) -> None

Signature descriptions:

  • Expire the insights of the given symbols

  • Expire the given insights

Parameters:

Name Type Description Default
symbols Optional[List[Symbol]]

Symbol we want to expire insights for

None
insights Optional[List[Insight]]

Insights to expire

None

set_insight_score_function

set_insight_score_function(
    insight_score_function: Any,
) -> None
set_insight_score_function(
    insight_score_function: IInsightScoreFunction,
) -> None

Sets the insight score function to use

Parameters:

Name Type Description Default
insight_score_function Any | IInsightScoreFunction

Model that scores insights

required

step

step(utc_now: Union[datetime, date]) -> None

Process a new time step handling insights scoring

Parameters:

Name Type Description Default
utc_now Union[datetime, date]

The current utc time

required

get_insights

get_insights(filter: Any) -> List[Insight]
get_insights(
    filter: Callable[[Insight], bool] = None,
) -> List[Insight]

Will return insights from the complete insight collection

Parameters:

Name Type Description Default
filter Any | Callable[[Insight], bool]

The function that will determine which insight to return

None

Returns:

Type Description
List[Insight]

A new list containing the selected insights.

__contains__

__contains__(
    symbol: Union[Symbol, str, BaseContract],
) -> bool

Determines whether insights exist in this collection for the specified symbol

Parameters:

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

The symbol key

required

Returns:

Type Description
bool

True if there are insights for the symbol in this collection.

__getitem__

__getitem__(
    symbol: Union[Symbol, str, BaseContract],
) -> List[Insight]

Dictionary accessor returns a list of insights for the specified symbol

Parameters:

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

The symbol key

required

Returns:

Type Description
List[Insight]

List of insights for the symbol.

__iter__

__iter__() -> Iterator[Insight]

__len__

__len__() -> int

__setitem__

__setitem__(
    symbol: Union[Symbol, str, BaseContract],
    value: List[Insight],
) -> None

Dictionary accessor returns a list of insights for the specified symbol

Parameters:

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

The symbol key

required

Returns:

Type Description
None

List of insights for the symbol.

add

add(item: Insight) -> None

Adds an item to the System.Collections.Generic.ICollection`1.

Parameters:

Name Type Description Default
item Insight

The object to add to the System.Collections.Generic.ICollection`1.

required

add_range

add_range(insights: List[Insight]) -> None

Adds each item in the specified enumerable of insights to this collection

Parameters:

Name Type Description Default
insights List[Insight]

The insights to add to this collection

required

clear

clear(symbols: List[Symbol]) -> None

Removes the symbol and its insights

Parameters:

Name Type Description Default
symbols List[Symbol]

List of symbols that will be removed

required

contains

contains(item: Insight) -> bool

Determines whether the System.Collections.Generic.ICollection`1 contains a specific value.

Parameters:

Name Type Description Default
item Insight

The object to locate in the System.Collections.Generic.ICollection`1.

required

Returns:

Type Description
bool

true if item is found in the System.Collections.Generic.ICollection`1; otherwise, false.

contains_key

contains_key(
    symbol: Union[Symbol, str, BaseContract],
) -> bool

Determines whether insights exist in this collection for the specified symbol

Parameters:

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

The symbol key

required

Returns:

Type Description
bool

True if there are insights for the symbol in this collection.

get_active_insights

get_active_insights(
    utc_time: Union[datetime, date],
) -> ICollection[Insight]

Gets the last generated active insight

Returns:

Type Description
ICollection[Insight]

Collection of insights that are active.

get_enumerator

get_enumerator() -> IEnumerator[Insight]

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[Insight]

A System.Collections.Generic.IEnumerator`1 that can be used to iterate through the collection.

get_next_expiry_time

get_next_expiry_time() -> Optional[datetime]

Gets the next expiry time UTC

has_active_insights

has_active_insights(
    symbol: Union[Symbol, str, BaseContract],
    utc_time: Union[datetime, date],
) -> bool

Returns true if there are active insights for a given symbol and time

Parameters:

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

The symbol key

required
utc_time Union[datetime, date]

Time that determines whether the insight has expired

required

remove

remove(item: Insight) -> bool

Removes the first occurrence of a specific object from the System.Collections.Generic.ICollection`1.

Parameters:

Name Type Description Default
item Insight

The object to remove from the System.Collections.Generic.ICollection`1.

required

Returns:

Type Description
bool

true if item was successfully removed from the System.Collections.Generic.ICollection1; otherwise, false. This method also returns false if item is not found in the original System.Collections.Generic.ICollection1.

remove_expired_insights

remove_expired_insights(
    utc_time: Union[datetime, date],
) -> ICollection[Insight]

Remove all expired insights from the collection and retuns them

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

Time that determines whether the insight has expired

required

Returns:

Type Description
ICollection[Insight]

Expired insights that were removed.

remove_insights

remove_insights(filter: Callable[[Insight], bool]) -> None

Will remove insights from the complete insight collection

Parameters:

Name Type Description Default
filter Callable[[Insight], bool]

The function that will determine which insight to remove

required

try_get_value

try_get_value(
    symbol: Union[Symbol, str, BaseContract],
    insights: Optional[List[Insight]],
) -> Tuple[bool, List[Insight]]

Attempts to get the list of insights with the specified symbol key

Parameters:

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

The symbol key

required
insights Optional[List[Insight]]

The insights for the specified symbol, or null if not found

required

Returns:

Type Description
Tuple[bool, List[Insight]]

True if insights for the specified symbol were found, false otherwise.