Asset
Overview¶
The Asset class is the fundamental building block for representing financial instruments in roboquant. Every tradable instrument — whether a stock, option, forex pair, or cryptocurrency — is modeled as a specialized subclass of Asset.
Overview¶
All asset types extend the common base class, Asset, which provides:
A symbol (ticker)
The currency the asset is denoted in
Calculation of the contract value
Serialization and de-serialization (used for example to store prices in databases)
Subclasses can add type-specific attributes and methods.
The symbol should be unique accross all assets.
If you deal with scenarios where there are conflicting symbol names, a solution is to extend the symbol name. For example, you want to differentiate between crypto-pairs on different exchanges, add the exchange name to the symbol name:
from roboquant import Crypto, USD
asset1 = Crypto("BTCUSD.KRAKEN", USD)
asset2 = Crypto("BTCUSD.BINANCE", USD)
assert asset1 != asset2For assets to function correctly, it is important that (next to the unique symbol name):
The currency is set correctly so conversions happen is required.
The
value()is be correctly calculated, especially if an asset class has different contract sizes like is the case with stock options and forex.
Asset Classes¶
roboquant supports the following asset types out of the box:
| Asset Type | Subclass | Typical Use Case |
|---|---|---|
STOCK | Stock | Stocks, ETFs, ADRs |
OPTION | Option | Equity & index options |
FOREX | Forex | Currency pairs (EUR/USD) |
CRYPTO | Crypto | Crypto spot (BTC/USDT) |
You add your own asset classes by extending Asset class.
Instantiation¶
Although most commonly the Assets are created by the Feed you use, you
can also create your own instances.
import pprint
from roboquant import Asset, Stock, Crypto, Forex, Option, EUR
# Create a simple stock with the default currency (USD)
aapl = Stock("AAPL")
print(aapl)
# Create a Banco Santander (Spain) stock in Euro
san = Stock("SAN", EUR)
print(san)
# use a static method to derive the currency
# from the symbol name
eurusd = Forex.from_symbol("EUR/USD")
print(eurusd)
btc = Crypto.from_symbol("BTC/USDT")
print(btc)
# Options using the OCC notation
option = Option("TSLA250228C00100000")
pprint.pp(option.decode_occ_symbol())Output
Stock(symbol='AAPL', currency='USD', info=None)
Stock(symbol='SAN', currency='EUR', info=None)
Forex(symbol='EUR/USD', currency='USD', info=None, contract_size=Decimal('1'))
Crypto(symbol='BTC/USDT', currency='USDT', info=None, contract_size=Decimal('1'))
{'underlying': 'TSLA',
'expiration': datetime.date(2025, 2, 28),
'option_type': 'C',
'strike': 100.0}
Register an Asset¶
You can register an Asset upfront. Feeds will then pick the registered asset to publish events rather then their own logic.
import roboquant as rq
# Ensure that YahooFeed will use
# the asset with the currency set to EUR and
# named just plain ASML instead of ASML.AS
Stock("ASML", EUR).register("ASML.AS")
feed = rq.feeds.YahooFeed("ASML.AS")
print(feed.assets()){Stock(symbol='ASML', currency='EUR', info=None)}