Module engine
Classes
class Account (initial_cash: float = 100000, allow_debt: bool = False)-
Object representing the bank account of the strategy. This object keeps track of the cash available in the account, the collateral used in the account and the transactions made by the strategy.
Attributes
available_cash- The amount of cash available in the account. This is the amount of cash that can be used to buy securities.
collateral- The amount of money that is currently being used as collateral.
transactions- The transactions made by the strategy.
Static methods
def load_state(dict_data: dict)-
This method load a Account object from a dictionary.
Args:
dict_data: The dictionary to load fromReturns:
- The Account object
Methods
def add_collateral(self, amount: float, dt: datetime.datetime, message: str = 'Sold short')-
Adds collateral to the account. This is the amount of money held as collateral and cannot be used. This method could be used when selling short a position.
Args:
amount: Value of collateral.
dt: datetime of the update
message: Reason of the update. Can be, for example: "Step update", "Enter short position for {ticker}", etc.Returns:
- None
Raises:
RuntimeError: If the amount of collateral is bigger than the current cash in the account. def get_cash(self)-
The amount of cash available in the account. This is the amount of cash that can be used to buy securities. total_cash - collateral = cash
Returns:
- available cash
def get_state(self) ‑> dict-
This method export the account object to a JSONable dictionary.
Returns:
- The object state as a dictionary
def get_total_cash(self)-
The total amount of cash in the account. Not deducing collateral. This include cash that cannot be used to buy securities.
Returns:
- Total cash
def get_transactions(self)-
Return a deepcopy of the transactions list.
Returns:
- The transactions list
def remove_collateral(self, amount: float, dt: datetime.datetime, message: str = 'Bought back short')-
Removes collateral from the account. This is the amount of money held as collateral and cannot be used. This method could be used when buying back a short position.
Args:
amount: Value of collateral.
dt: datetime of the update
message: Reason of the update. Can be, for example: "Step update", "Enter short position for {ticker}", etc.Returns:
- None
Raises:
RuntimeError: If the amount of collateral is bigger than the current cash in the account. def update_collateral(self, amount: float, dt: datetime.datetime, message: str = 'Step update')-
Updates the amount of collateral in the account. This is the amount of money held as collateral and cannot be used. This should be updated at each steps because it should be dependent to the current value of the assets. Raise a RuntimeError if the amount of collateral is bigger than the current worth of the account.
Args:
amount: Value of collateral.
dt: datetime of the update
message: Reason of the update. Can be, for example: "Step update", "Enter short position for {ticker}", etc.Returns:
- None
class CollateralUpdate (amount: float, dt: datetime.datetime, message: str, collateral_update_type: CollateralUpdateType)-
Data class holding info about a collateral update
Args:
amount: The amount frozen in the account as collateral (Cannot be used to buy securities)
dt: The datetime of the update.
message: A message explaining the reason of the update. (Useful for debugging the strategy)
collateral_update_type: The type of update. Can be ADD, REMOVE or UPDATEStatic methods
def load(data: dict)-
This method load a CollateralUpdate object from a dictionary.
Args:
data: The dictionary to load fromReturns:
- The CollateralUpdate object
Methods
def export(self) ‑> dict-
This method export the trade order object to a JSONable dictionary.
Returns:
- The object's state as a dictionary
class CollateralUpdateType (*args, **kwds)-
[Enum] The type of collateral update. Can be:
- ADD
- REMOVE
- UPDATE
Parent
- enum.Enum
Class variables
var ADDvar REMOVEvar UPDATE