Securities

Key Concepts

Introduction

A security is an individual financial asset that you might trade on an exchange. LEAN models these unique assets with a Security object, which the AddEquityadd_equity, AddCryptoadd_crypto, and similar methods return. The Securitiessecurities property of the QCAlgorithm class is a dictionary where the keys are Symbol objects and the values are Security objects. The Securitiessecurities dictionary contains all of the securities that have been in the algorithm during its lifetime.

Quote Currency

The quote currency is the currency you must give the seller to buy an asset. For currency trades, the quote currency is the currency ticker on the right side of the currency pair. For other types of assets, the quote currency is usually USD, but the quote currency for India Equities is INR. To get the quote currency of a Security, use the QuoteCurrencyquote_currency property.

var aaplQuoteCurrency = Securities["AAPL"].QuoteCurrency; // USD
var btcusdtQuoteCurrency = Securities["BTCUSDT"].QuoteCurrency; // USDT
aapl_quote_currency = self.securities["AAPL"].quote_currency # USD
btcusdt_quote_currency = self.securities["BTCUSDT"].quote_currency # USDT

The QuoteCurrencyquote_currency is a Cash object, which have the following properties:

You can use the ConversionRateconversion_rate property to calculate the value of the minimum price movement in the account currency

var cfd = Securities["SG30SGD"];
var quoteCurrency = cfd.QuoteCurrency; // SGD
var contractMutiplier = cfd.SymbolProperties.ContractMultiplier;
var minimumPriceVariation = cfd.SymbolProperties.MinimumPriceVariation;

// Value of a pip in account currency
var pip = minimumPriceVariation * contractMutiplier * quoteCurrency.ConversionRate;
cfd = self.securities["SG30SGD"]
quote_currency = cfd.quote_currency # SGD
contract_mutiplier = cfd.symbol_properties.contract_multiplier
minimum_price_variation = cfd.symbol_properties.minimum_price_variation

# Value of a pip in account currency
pip = minimum_price_variation * contract_mutiplier * quote_currency.conversion_rate

Security Listing

The Exchangeexchange property of a Security object contains information about the exchange that lists the security.

var exchange = Securities["SPY"].Exchange;
exchange = self.securities["SPY"].exchange

Security Market

The Market enumeration has the following members:

LEAN groups all of the US Equity exchanges under Market.USA. In live mode, the brokerage routes the orders to the exchange that provides the best price.

Active Securities

The ActiveSecuritiesactive_securities property of the algorithm class contains all of the assets currently in your algorithm. It is a dictionary where the key is a Symbol and the value is a Security. When you remove an asset from a universe, LEAN usually removes the security from the ActiveSecuritiesactive_securities collection and removes the security subscription. However, it won't remove the security in any of the following situations:

  • You own the security.
  • You have an open order for the security.
  • The security wasn't in the universe long enough to meet the MinimumTimeInUniverseminimum_time_in_universe setting.

When LEAN removes the security, the Security object remains in the Securitiessecurities collection for record-keeping purposes, like tracking fees and trading volume.

To get only the assets that are currently in the universe, see Selected Securities.

Tradable Status

The IsTradableis_tradable property shows whether you can trade a security. The property value is true when the security is in the universe, even if the data starts at a later day. Indices, canonical Option securities, and continuous Futures contracts are not tradable. In live mode, custom data objects are also not tradable, even if the custom data represents a tradable asset.

var tradable = Securities["SPY"].IsTradable;
tradable = self.securities["SPY"].is_tradable

Fundamental Data

To get fundamental data for a Security in your algorithm, use its Fundamentalsfundamentals property. The fundamental data represent the company's fundamentals for the current algorithm time.

var fundamentals = Securities[_symbol].Fundamentals;
fundamentals = self.securities[self.symbol].fundamentals

Some assets don't have fundamentals (for example, ETFs) and the Morningstar dataset doesn't provide fundamentals for all US Equities. To check if fundamental data is available for an asset, use the HasFundamentalDatahas_fundamental_data property.

var hasFundamentalData = Securities[_symbol].Fundamentals.HasFundamentalData;
has_fundamental_data = self.securities[self.symbol].fundamentals.has_fundamental_data

For more information about fundamental data, see Corporate Fundamentals.

Linked Custom Data

Linked custom data is custom data that's linked to individual assets. In contrast, unlinked data is not linked to specific assets. An example of an unlinked dataset is the US Regulatory Alerts dataset. LEAN passes custom data objects to the OnDataon_data method. For more information about custom data, see Custom Securities.

Security Types

LEAN uses the SecurityType enumeration as a synonym for asset classes. The SecurityType enumeration has the following members:

The Base type is for non-financial assets like custom and alternative data objects.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: