Asset

An asset object represents securities such as stocks or options in Lumibot. Attributes that are tracked for assets are:

  • symbol(str): Ticker symbol representing the stock or underlying for options. So for example if trading IBM calls the symbol would just be IBM.

  • asset_type(str): Asset type can be either stock, option, future, forex. default: stock

  • name(str): Optional to add in the name of the corporation for logging or printout.

Options Only

  • expiration (str): Expiration of the options contract. Format is datetime.date().

  • strike(float): Contract strike price.

  • right(str): May enter call or put.

  • multiplier(float): Contract multiplier to the underlying. (default: 1)

Futures Only

Set up a futures contract using the following:

  • symbol(str): Ticker symbol for the contract, > eg: ES

  • asset_type(str): “future”

  • nexpiration(str): Expiry added as datetime.date() So June 2021 would be datetime.date(2021, 6, 18)`

Forex Only

  • symbol(str): Currency base: eg: EUR

  • currency(str): Conversion currency. eg: GBP

  • asset_type(str): “forex”

When creating a new security there are two options.

  1. Security symbol: It is permissible to use the security symbol only when trading stocks. Lumibot will convert the ticker symbol to an asset behind the scenes.

  2. Asset object: Asset objects may be created at anytime for stocks or options. For options, futures, or forex asset objects are mandatory due to the additional details required to identify and trade these securities.

Assets may be created using the Asset() method as follows: Asset(symbol, asset_type=option, **kwargs) * see attributes above.

Examples:

For stocks:

from lumibot.entities import Asset

asset = Asset('SPY', asset_type="stock")
order = self.create_order(asset, 10, "buy")
self.submit_order(order)

For futures:

from lumibot.entities import Asset

asset = Asset(
'ES', asset_type="future", expiration=datetime.date(2021, 6, 18)
)
order = self.create_order(asset, 10, "buy")
self.submit_order(order)

Documentation

class entities.asset.Asset(*, symbol: str, asset_type: str = 'stock', expiration: datetime.date = None, strike: str = '', right: str = None, multiplier: int = 1, currency: str = 'USD')

Bases: pydantic.main.BaseModel

This is a base class for Assets including stocks, futures, options and forex.

symbolstr

Symbol of the stock or underlying in case of futures/options.

asset_typestr

Type of the asset. Asset types are only ‘stock’, ‘option’, ‘future’, ‘forex’ default : ‘stock’

expirationdatetime.date

Option or futures expiration. The datetime.date will be converted to broker specific formats. IB Format: for options “YYYYMMDD”, for futures “YYYYMM”

strikestr

Options strike as string.

rightstr

‘CALL’ or ‘PUT’ default : “”

multiplierint

Price multiplier. default : 1

currencystr

Base currency, (default=None)

symbolstring (required)

The symbol used to retrieve stock quotes if stock. The underlying symbol if option. For Forex: The base currency.

asset_type (string, default: stock)

One of the following: - ‘stock’ - ‘option’ - ‘future’ - ‘forex’

expirationdatetime.date (required if asset_type is ‘option’ or ‘future’)

Contract expiration dates for futures and options.

strikefloat (required if asset_type is ‘option’)

Contract strike price.

rightstr (required if asset_type is ‘option’)

Option call or put.

multiplierint (required if asset_type is ‘forex’)

Contract leverage over the underlying.

currencystring (required if asset_type is ‘forex’)

Conversion currency.

_asset_typeslist of str

Acceptable asset types.

_rightlist of str

Acceptable values for right.

asset_type_must_be_one_of(@”asset_type”)

validates asset types.

right_must_be_one_of(@”right”)

validates rights types.

>>> # Create an Asset object for a stock.
>>> from lumibot.entities import Asset
>>> asset = Asset(symbol="AAPL")
>>> # Create an Asset object for a futures contract.
>>> from lumibot.entities import Asset
>>> asset = Asset(symbol="ES", asset_type='future', expiration=datetime.date(2021, 12, 17))
>>> # Create an Asset object for an options contract.
>>> from lumibot.entities import Asset
>>> asset = Asset(
>>>     symbol="AAPL",
>>>     asset_type='option',
>>>     expiration=datetime.date(2021, 11, 26),
>>>     strike=155,
>>>     right= 'CALL',
>>>     multiplier=100,
>>>     currency="USD"
>>> )

<<<<<<< HEAD

>>> # Create an Asset object for a forex contract.
>>> from lumibot.entities import Asset
>>> asset = Asset(symbol="USD", asset_type='forex', currency="EUR")
>>> self.create_order(asset, 1, "buy", "market")
>>> order = self.create_order(asset, 100, 'BUY')
>>> self.submit_order(order)

>>>>>>> master

asset_type: str
classmethod asset_type_must_be_one_of(v)
currency: Optional[str]
expiration: Optional[datetime.date]
multiplier: int
right: Optional[str]
classmethod right_must_be_one_of(v)
strike: Optional[str]
symbol: str
class entities.asset.AssetsMapping(mapping)

Bases: collections.UserDict