algo_engine.strategy

The strategy layer provides the framework for building and running trading strategies.

Strategy Engine

class algo_engine.strategy.StrategyEngine(position_tracker: PositionManagementService, **kwargs)[source]
__init__(position_tracker: PositionManagementService, **kwargs)[source]
add_handler(**kwargs)[source]
remove_handler(**kwargs)[source]
add_handler_safe(**kwargs)[source]
remove_handler_safe(**kwargs)[source]
attach_strategy(strategy: object)[source]
subscribe(ticker: str)[source]
on_market_data(market_data: MarketData, **kwargs)[source]
on_report(report: TradeReport, **kwargs)[source]
on_order(order: TradeInstruction, **kwargs)[source]
register(event_engine=None, topic_set=None, auto_register: bool = True)[source]

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

unregister(event_engine=None, topic_set=None, auto_unregister: bool = True)[source]
cancel(ticker: str, side: TransactionSide = None, algo_id: str = None, order_id: str = None, **kwargs)[source]
stop()[source]
unwind_pos(ticker: str, volume: float, side: TransactionSide = None, limit_price: float = None, algo: str = None, safe=True, **kwargs) tuple[float, float][source]

unwind method provide a safe way to unwind position of given ticker.

Parameters:
  • ticker – the given exposure

  • volume – the target unwinding volume, should be a positive number

  • side – the trade action side, e.g. if strategy wishes to sell (in order to unwind long position), then side = TransactionSide.Sell_to_Unwind

  • limit_price – Optional, a limit price

  • algo – Optional the algo to be used to execute unwinding action

  • safe – True -> unwind volume should not exceed the exposed volume; False -> can flip position. Default is safe=True

  • kwargs – other kwargs passing to algo.launch

Returns:

executed volume, remaining volume

open_pos(ticker: str, volume: float, side: TransactionSide = None, limit_price: float = None, algo: str = None, **kwargs)[source]

a method to open position :param ticker: the given ticker :param volume: the target open volume :param side: trade side :param limit_price: Optional limit :param algo: Optional the specified algo :param kwargs: other keyword used in algo :return:

eod(market_date: date, **kwargs)[source]
bod(market_date: date, **kwargs)[source]
back_test(start_date: date, end_date: date, data_loader: Callable, **kwargs)[source]
back_test_lite(start_date: date, end_date: date, data_loader: Callable, **kwargs)[source]
reset()[source]
property algos

Singletons

algo_engine.strategy.STRATEGY_ENGINE = <algo_engine.strategy.strategy_engine.StrategyEngine object>
algo_engine.strategy.BALANCE = <Balance>{id=140092664108704}

Balance handles mapping of PositionTracker <-> Strategy

algo_engine.strategy.DMA = <OrderHandler>(cd=None, id=140092664109376)
algo_engine.strategy.POSITION_TRACKER = <algo_engine.engine.trade_engine.PositionManagementService object>

Position Module controls the position of a single strategy,

The tracker provides basic tracing of PnL, exposure, holding time and interface with risk monitor module The Strategy should interface with Position module, not the algo

a range of easy method is provided to facilitate development

algo_engine.strategy.INVENTORY = <Inventory>{id=140092664106352}

Inventory stores the info of security lending

algo_engine.strategy.RISK_PROFILE = <RiskProfile>{id=140092664109040}

Event DMA

class algo_engine.strategy.EventDMA(mds: MarketDataService, risk_profile: RiskProfile, event_engine=None, cool_down: float = None)[source]
__init__(mds: MarketDataService, risk_profile: RiskProfile, event_engine=None, cool_down: float = None)[source]