certis.core module

class certis.core.Account(margin: float, market_info: MarketInfo)[source]

Bases: object

Certis Account Object

deposit(size: float) object[source]
property info: Dict[str, Any]

gives position info as dictionary

Returns

position info as dictionary

property margin: float

current margin left

Returns

self._margin

property position: Position

current position object

Returns

self._position

update_portfolio_value(price: float) object[source]

updates portfolio value updates unrealized pnl

Parameters

price – current price

Returns

self

update_position(price: float, size: float, side: int)[source]

updates position with new transaction

Parameters
  • price – price of transaction

  • size – quantity of transaction

  • side – side of transaction

  • market_info – MarketInfo object

Returns

realized profit and loss (p&L)

class certis.core.Broker(market_info: MarketInfo, initial_margin: float)[source]

Bases: object

Virtual Broker object for Certis

property account_info

account information

Returns

self._account.info

apply_actions(actions: List[Action], price: float) None[source]

applies actions, which is List of Order / OrderCancellation Objects

Parameters
  • actions – list of actions (Order / OrderCancellation Objects)

  • price – current price

Returns

None

fill_pending_orders(timestamp: int, open_price: float, high_price: float, low_price: float) object[source]

executes orders in order queue

Parameters
  • timestamp – current timestamp

  • open_price – current open price

  • high_price – current high price

  • low_price – current low price

Returns

self

class certis.core.Engine(data: DataFrame, initial_margin: float, market_info: MarketInfo, strategy_cls: type, strategy_config: Dict[str, Any])[source]

Bases: object

Engine Object

property logger
run(use_tqdm=True, use_margin_call=False)[source]

runs backtest

Parameters

use_tqdm – use tqdm progressbar or not

Returns

Logger object

class certis.core.MarketInfo(maker_fee: float, taker_fee: float, slippage: float, tick_size: float, minimum_order_size: float, **kwargs)[source]

Bases: object

takes & contains all these market information we need

apply_slippage(price: float, side: int) float[source]

applies slippage for given price and side for side: long -> higher price for side: short -> lower price

Parameters
  • price – order price

  • side – order side

Returns

slippage-applied order price

property maker_fee
Returns

maker fee, fee for market orders. 1% = 0.01

property minimum_order_size

minimum order size for this data.

Returns

self._minimum_order_size

property slippage

slippage for market orders. 1% = 0.01

Returns

self._slippage

property taker_fee
Returns

taker fee, fee for limit orders. 1% = 0.01

property tick_size

tick size for this data. in other words, minimum change unit. like (123.123, 12.124, 12.122 … ), tick size is 0.001

Returns

self._tick_size

trim_order_price(price: float) float[source]

trims order price by doing (price // tick size) * tick size

Parameters

price – ordered price

Returns

trimmed order price

trim_order_size(size: Optional[float]) Optional[float][source]

trims order size by doing (size // minimum order size) * minimum order size

Parameters

size – order’s quantity

Returns

order size, trimmed by minimum order size

class certis.core.Order(order_side=None, order_quantity=None, order_type: Optional[str] = None, order_price: Optional[float64] = None, reduce_only: bool = False)[source]

Bases: Action

Order object in Certis

check_order_price_validity(market_price: float) None[source]

checks order price’s validity for certain cases that could raise “Order Could Execute Immediately” Error in live trading.

Parameters

market_price – market price (newest close price in this case)

Returns

None

property id: str

order’s id

Returns

self._id

is_fillable_at(account_info: Dict[str, Any], market_info: MarketInfo, open_price: float, high_price: float, low_price: float) bool[source]
property price: float

order’s price required in LIMIT, STOP_MARKET (stop price) orders

Returns

self._price

property quantity: float

order’s quantity

Returns

self._quantity

property reduce_only: bool

if order is reduce-only order or not

Returns

self._reduce_only

set_id(id: int)[source]
property side: int

order side defined in certis.core.OrderSide required in every orders except for STOP_LOSS_MARKET & TAKE_PROFIT_MARKET orders

Returns

self._side

trim(market_info: MarketInfo) Action[source]

trims order itself

Parameters

market_info – market info Object for this backtest

Returns

self

property type: str

order’s type defined in certis.constants.OrderType

Returns

class certis.core.OrderCancellation(id)[source]

Bases: Action

order cancellation object

property id: str

id for order to cancel if id == “all”: cancels all order

Returns

class certis.core.Position[source]

Bases: object

property avg_price: float

average entry price for this position

Returns

self._avg_price

property info: Dict[str, Any]

position as dict object

Returns

update(price: float, size: float, side: int, market_info: MarketInfo) float[source]

updates position with new transaction

Parameters
  • price – price of transaction

  • size – quantity of transaction

  • side – side of transaction

  • market_info – MarketInfo object

Returns

realized profit and loss (p&L)

update_unrealized_pnl(price: float) None[source]

updates unrealized pnl

Parameters

price – current price

Returns

None