Strategy Interface

generate_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
generate_action
vector<Action> Strategy::generate_action(
	const map<symbol_t, quantity_t> &original_position,
	price_t manageable_money,
	timestamp_t current_time,
	data_provider::DataProvider& provider
);
position = {
  META: 10,
  AAPL: 5,
  GOOG: 3,
  META: 0
}
money = 1000
Strategy::Strategy(nlohmann::json state);

strategy configuration, not resources

generate_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
generate_action
Action::AdjustPosition
symbol
expected_quantity
price_low, price_high
Action::MakeLimitOrder
symbol
quantity (+/-)
price
callback (bool -> void)
Action::KeepOrder
symbol
quantity (+/-)
price
Action::priority (int)

        Execution priority if resource is insufficient

AdjustPosition

AAPL+1, [220, 225]

AdjustPosition

GOOG-1, [180, 190]

AdjustPosition

META+1, [660, 670]

AdjustPosition

AAPL+1, [215, 220]

canceled
generate_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
generate_action
try 216.66
...

OrderExecutor [AAPL]

try 220
Timeout
try 221.66
Timeout
try 215
Timeout
try 190
Timeout
try 186.66
Timeout

OrderExecutor [GOOG]

AdjustPosition

META+2, [670, 675]

try 660
Timeout
try 667.22
Timeout
try 663.33
Timeout

OrderExecutor [META]

try 669.81
Action::AdjustPosition

For each symbol:

  • One Adjustment at a time
  • No action = No adjustment

 

OrderExecutor strategy:

  • Limit orders with timeout
  • \(current = \frac{2}{3}current + \frac{1}{3}boundary\)
MakeLimitOrder

AAPL, +1, 220

generate_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
generate_action
Filled
callback(true)
Canceled/Rejected
callback(false)
MakeLimitOrder

AAPL, +1, 220

MakeLimitOrder

AAPL, +1, 220, <id>

CancelLimitOrder
<id>
canceled
Action::MakeLimitOrder

Life cycle

  • Creation: returned from strategy
  • Deletion: callback function executed or canceled by Action::CancelLimitOrder

 

  • Attach order id if it might be canceled in the future
KeepOrder

AAPL, +1, 220

generate_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
take_action
generate_action
Filled
KeepOrder

GOOG, +1, 220

KeepOrder

META, +1, 220

canceled
generate_action(current_orders)
KeepOrder

GOOG, +1, 220

KeepOrder

META, +1, 220

generate_action(current_orders)
KeepOrder

GOOG, +1, 220

Canceled/Rejected
generate_action(current_orders)
Action::KeepOrder
  • Re-execute generate_action once a limit order is concluded
  • Executor pass currently pending limit orders to generate_action
  • Those in current_orders but not in returned actions will be canceled

Executor & Strategy

Strategy

Resource Manager

money

positions

Actions

generate_actions

Order Executor

put_order
callback()

Executor

Order System

Notes

  • Market is asynchronous: canceled order might still be executed

Strategy Interface

By thomaswang2003

Strategy Interface

  • 156