Custom Index¶
A custom index is a proprietary vector of date-value tuples. It can represent a proprietary benchmark, a risk factor, a proxy or any other measure. Even when persisted to your account, it is only available to the account. Custom Indexes are not bind to a workspace, meaning that they can be used globally, no matter the workspace.
We can start using the Custom Index entity by running the following import statement:
-
symbol: Refers to the symbol of the custom index. Unique to the user account, starts with the prefix CUSTOM:. -
name: The name of the custom index. -
description: The description of the custom index. -
tags: The tags of the custom index. -
periodicity: The periodicity of the custom index. -
currency: The currency of the custom index. -
base_price: The base price of the custom index. -
data_type: The data type of the custom index.
Instantiating a Custom Index Entity¶
Below let's instantiate a Custom Index entity and set the most common attributes used:
custom_index = CustomIndex()
custom_index.symbol = 'CUSTOM:INDEX'
custom_index.name = 'Custom Index'
custom_index.description = 'Description'
custom_index.tags = ['tag1', 'tag2']
custom_index.version = '1.0'
custom_index.periodicity = 'M'
custom_index.currency = 'USD'
custom_index.base_price = 1000
custom_index.data_type = 'PRICE'
custom_index.data = [[1, 2, 3], [4, 5, 6]]
Convert Custom Index to a Dictionary¶
Most times when working with entities, there might be a point where we need to convert the entity to a dictionary, and to achieve this we simply use the to_dict() method:
custom_index = CustomIndex()
type(custom_index)
everysk.sdk.entities.custom_index.base.CustomIndex
to_dict = custom_index.to_dict()
type(to_dict)
# dict
Validating a Custom Index Entity¶
For validating a Custom Index entity, we can make use of the validate() method, which will either return a boolean value or raise an exception in the case of an invalid entity, let's use our previous instantiated entity:
If somehow the entity were to be invalid, the validate() method would raise an exception along with the error message indicating the issue.
custom_index = CustomIndex()
custom_index.id = 'invalid id'
# FieldValueError: The value 'invalid id' for field 'symbol' must match with this regex: ^CUSTOM:[A-Z0-9_]*$.