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 AddEquity
add_equity
, AddCrypto
add_crypto
, and similar methods return. The Securities
securities
property of the QCAlgorithm
class is a dictionary where the keys are Symbol
objects and the values are Security
objects. The Securities
securities
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 QuoteCurrency
quote_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 QuoteCurrency
quote_currency
is a Cash
object, which have the following properties:
You can use the ConversionRate
conversion_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 Exchange
exchange
property of a Security
object contains information about the exchange that lists the security.
var exchange = Securities["SPY"].Exchange;
exchange = self.securities["SPY"].exchange
Active Securities
The ActiveSecurities
active_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 ActiveSecurities
active_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
MinimumTimeInUniverse
minimum_time_in_universe
setting.
When LEAN removes the security, the Security
object remains in the Securities
securities
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 IsTradable
is_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 Fundamentals
fundamentals
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 HasFundamentalData
has_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 OnData
on_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.