Skip to content

SecurityHolding

QuantConnect.Securities.SecurityHolding

SecurityHolding(
    security: Security,
    currency_converter: ICurrencyConverter,
)
SecurityHolding(holding: SecurityHolding)

Bases: Object

SecurityHolding is a base class for purchasing and holding a market item which manages the asset portfolio

Signature descriptions:

  • Create a new holding class instance setting the initial properties to $0.

  • Create a new holding class instance copying the initial properties

Parameters:

Name Type Description Default
security Optional[Security]

The security being held

None
currency_converter Optional[ICurrencyConverter]

A currency converter instance

None
holding Optional[SecurityHolding]

The security being held

None

quantity_changed

quantity_changed: _EventContainer[
    Callable[
        [Object, SecurityHoldingQuantityChangedEventArgs],
        Any,
    ],
    Any,
]

Event raised each time the holdings quantity is changed.

security

security: Security

The security being held

This codeEntityType is protected.

target

Gets the current target holdings for this security

average_price

average_price: float

Average price of the security holdings.

quantity

quantity: float

Quantity of the security held.

symbol

symbol: Symbol

Symbol identifier of the underlying security.

type

The security type of the symbol

leverage

leverage: float

Leverage of the underlying security.

holdings_cost

holdings_cost: float

Acquisition cost of the security total holdings in units of the account's currency.

unlevered_holdings_cost

unlevered_holdings_cost: float

Unlevered Acquisition cost of the security total holdings in units of the account's currency.

price

price: float

Current market price of the security.

absolute_holdings_cost

absolute_holdings_cost: float

Absolute holdings cost for current holdings in units of the account's currency.

unlevered_absolute_holdings_cost

unlevered_absolute_holdings_cost: float

Unlevered absolute acquisition cost of the security total holdings in units of the account's currency.

holdings_value

holdings_value: float

Market value of our holdings in units of the account's currency.

absolute_holdings_value

absolute_holdings_value: float

Absolute of the market value of our holdings in units of the account's currency.

hold_stock

hold_stock: bool

Boolean flag indicating if we hold any of the security

invested

invested: bool

Boolean flag indicating if we hold any of the security

total_sale_volume

total_sale_volume: float

The total transaction volume for this security since the algorithm started in units of the account's currency.

total_fees

total_fees: float

Total fees for this company since the algorithm started in units of the account's currency.

total_dividends

total_dividends: float

Total dividends for this company since the algorithm started in units of the account's currency.

is_long

is_long: bool

Boolean flag indicating we have a net positive holding of the security.

is_short

is_short: bool

BBoolean flag indicating we have a net negative holding of the security.

absolute_quantity

absolute_quantity: float

Absolute quantity of holdings of this security

last_trade_profit

last_trade_profit: float

Record of the closing profit from the last trade conducted in units of the account's currency.

profit

profit: float

Calculate the total profit for this security in units of the account's currency.

net_profit

net_profit: float

Return the net for this company measured by the profit less fees in units of the account's currency.

unrealized_profit_percent

unrealized_profit_percent: float

Gets the unrealized profit as a percentage of holdings cost

unrealized_profit

unrealized_profit: float

Unrealized profit of this security when absolute quantity held is more than zero in units of the account's currency.

get_quantity_value

get_quantity_value(
    quantity: float,
) -> ConvertibleCashAmount
get_quantity_value(
    quantity: float, price: float
) -> ConvertibleCashAmount

Gets the total value of the specified quantity of shares of this security in the account currency

Parameters:

Name Type Description Default
quantity float

The quantity of shares

required
price Optional[float]

The current price

None

Returns:

Type Description
ConvertibleCashAmount

The value of the quantity of shares in the account currency.

set_holdings

set_holdings(average_price: float, quantity: int) -> None
set_holdings(average_price: float, quantity: float) -> None

Set the quantity of holdings and their average price after processing a portfolio fill.

add_new_dividend

add_new_dividend(dividend: float) -> None

Adds a new dividend payment to the running total dividend in units of the account's currency.

Parameters:

Name Type Description Default
dividend float
required

add_new_fee

add_new_fee(new_fee: float) -> None

Adds a fee to the running total of total fees in units of the account's currency.

Parameters:

Name Type Description Default
new_fee float
required

add_new_profit

add_new_profit(profit_loss: float) -> None

Adds a profit record to the running total of profit in units of the account's currency.

Parameters:

Name Type Description Default
profit_loss float

The cash change in portfolio from closing a position

required

add_new_sale

add_new_sale(sale_value: float) -> None

Adds a new sale value to the running total trading volume in units of the account's currency.

Parameters:

Name Type Description Default
sale_value float
required

on_quantity_changed

on_quantity_changed(
    previous_average_price: float, previous_quantity: float
) -> None

Event invocator for the quantity_changed event

This codeEntityType is protected.

set_last_trade_profit

set_last_trade_profit(last_trade_profit: float) -> None

Set the last trade profit for this security from a Portfolio.ProcessFill call in units of the account's currency.

Parameters:

Name Type Description Default
last_trade_profit float

Value of the last trade profit

required

to_string

to_string() -> str

Writes out the properties of this instance to string

total_close_profit

total_close_profit(
    include_fees: bool = True,
    exit_price: Optional[float] = None,
    entry_price: Optional[float] = None,
    quantity: Optional[float] = None,
) -> float

Profit if we closed the holdings right now including the approximate fees in units of the account's currency.

update_market_price

update_market_price(closing_price: float) -> None

Update local copy of closing price value.

Parameters:

Name Type Description Default
closing_price float

Price of the underlying asset to be used for calculating market price / portfolio value

required