US Equity

Requesting Data

Introduction

Request US Equity data in your algorithm to receive a feed of asset prices in the OnData method. For more information about the specific dataset we use for backtests, see the US Equities dataset listing.

Create Subscriptions

To create an Equity subscription, in the Initialize method, call the AddEquity method. The AddEquity method returns an Equity object, which contains a Symbol. Save a reference to the Symbol so you can use it in OnData to access the security data in the Slice.

_symbol = AddEquity("SPY").Symbol;
self.symbol = self.AddEquity("SPY").Symbol

The AddEquity method creates a subscription for a single Equity asset and adds it to your user-defined universe. To create a dynamic universe of Equities, add an Equity universe or an Equity Universe Selection model.

To view the supported assets in the US Equities dataset, see the Data Explorer.

Resolutions

The following table shows the available resolutions and data formats for Equity subscriptions:

ResolutionTradeBarQuoteBarTrade TickQuote Tick
Tickgreen checkgreen check
Secondgreen checkgreen check
Minutegreen checkgreen check
Hourgreen check
Dailygreen check

The default resolution for Equity subscriptions is Resolution.Minute. To change the resolution, pass a resolution argument to the AddEquity method.

_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol

To create custom resolution periods, see Consolidating Data.

Asset Primary Exchange

When a stock like Apple is listed, it’s listed on Nasdaq. The open auction tick on Nasdaq is the price that’s used as the official open of the day. NYSE, BATS, and other exchanges also have opening auctions, but the only official opening price for Apple is the opening auction on the exchange where it was listed.

Supported Markets

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.

To set the market for a security, pass a market argument to the AddEquity method.

_symbol = AddEquity("SPY", market: Market.USA).Symbol;
self.symbol = self.AddEquity("SPY", market=Market.USA).Symbol

The brokerage models have a default market for each asset class. If you set a brokerage model, you may not need to specify the market to use.

Margin and Leverage

LEAN models buying power and margin calls to ensure your algorithm stays within the margin requirements. In backtests, the default leverage for margin accounts is 2x leverage and leverage is not available for cash accounts. To change the amount of leverage you can use for a security, pass a leverage argument to the AddEquity method.

_symbol = AddEquity("SPY", leverage: 3).Symbol;
self.symbol = self.AddEquity("SPY", leverage=3).Symbol

In live trading, the brokerage determines how much leverage you may use. For more information about the leverage they provide, see Brokerages.

Data Normalization

The data normalization mode defines how historical data is adjusted for corporate actions. The data normalization mode affects the data that LEAN passes to OnData and the data from history requests. By default, LEAN adjusts US Equity data for splits and dividends to produce a smooth price curve, but the following data normalization modes are available:

We use the entire split and dividend history to adjust historical prices. This process ensures you get the same adjusted prices, regardless of the backtest end date.

To set the data normalization mode for a security, pass a dataNormalizationMode argument to the AddEquity method.

_symbol = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
self.symbol = self.AddEquity("SPY", dataNormalizationMode=DataNormalizationMode.Raw).Symbol

To set the data normalization mode for all securities in an algorithm, set the DataNormalizationMode universe setting before you create the security subscriptions.

UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw

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: