Welcome to certis’s documentation!

certis package

Submodules

certis.base module

class certis.base.Action[source]

Bases: object

Abstract class for Order, OrderCancellation

class certis.base.Logger[source]

Bases: object

Logger Object

property account_infos: List[Dict[str, Any]]

account infos during the backtest. recorded interval-by-interval

Returns

self._account_infos

add_account_info(account_info: Dict[str, Any]) None[source]

adds account info

Parameters

account_info – account info

Returns

None

add_transaction(transactions: List[Dict[str, Any]]) None[source]

adds transactions

Parameters

transactions – transactions

Returns

None

add_unfilled_orders(unfilled_orders: Dict[str, Any]) None[source]

adds unfilled orders

Parameters

unfilled_orders – unfilled orders

Returns

None

to_json(target_directory: str) None[source]

writes logger to json

Parameters

target_directory – target directory to write

Returns

None

property transactions: List[Dict[str, Any]]

list of transactions during the backtest. each transaction is generated when order fills

Returns

self._transactions

property unfilled_orders: List[Dict[str, Any]]

unfilled orders during the backtest. recorded interval-by-interval

Returns

self._unfilled_orders

class certis.base.Strategy(config, name='CertisStrategy')[source]

Bases: object

Abstract method for generating user-defined trading strategies with certis

calculate(data: DataFrame)[source]
execute(state_dict: Dict[str, Any]) List[Action][source]

certis.constants module

class certis.constants.OrderSide[source]

Bases: object

OrderSide Object

LONG: betting for upside SHORT: betting for downside

LONG = 1
SHORT = -1
SIDES = [-1, 1]
class certis.constants.OrderType[source]

Bases: object

OrderType Object. Supported types are

MARKET, LIMIT, STOP_MARKET, STOP_LOSS_MARKET, TAKE_PROFIT_MARKET

LIMIT = 'LIMIT'
LIMIT_ORDERS = ['LIMIT']
MARKET = 'MARKET'
MARKET_ORDERS = ['MARKET', 'STOP_MARKET']
ORDERS = ['MARKET', 'LIMIT', 'STOP_MARKET', 'STOP_LOSS_MARKET', 'TAKE_PROFIT_MARKET']
STOP_LOSS_MARKET = 'STOP_LOSS_MARKET'
STOP_MARKET = 'STOP_MARKET'
STOP_ORDERS = ['STOP_MARKET']
TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET'

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

certis.util module

certis.util.dataframe_as_list_of_dict(df: DataFrame) List[Dict[str, float]][source]

converts dataframe to list of dictionaries

Parameters

df – target dataframe to convert

Returns

list of dictionaries, which is generated by given dataframe

certis.util.generate_random_string(N: int = 10) str[source]

generates random string

Parameters

N – random string’s length

Returns

random string

Module contents

Indices and tables