MCPcopy
hub / github.com/microsoft/qlib / Order

Class Order

qlib/backtest/decision.py:37–151  ·  view source on GitHub ↗

stock_id : str amount : float start_time : pd.Timestamp closed start time for order trading end_time : pd.Timestamp closed end time for order trading direction : int Order.SELL for sell; Order.BUY for buy factor : float presents the weight

Source from the content-addressed store, hash-verified

35
36@dataclass
37class Order:
38 """
39 stock_id : str
40 amount : float
41 start_time : pd.Timestamp
42 closed start time for order trading
43 end_time : pd.Timestamp
44 closed end time for order trading
45 direction : int
46 Order.SELL for sell; Order.BUY for buy
47 factor : float
48 presents the weight factor assigned in Exchange()
49 """
50
51 # 1) time invariant values
52 # - they are set by users and is time-invariant.
53 stock_id: str
54 amount: float # `amount` is a non-negative and adjusted value
55 direction: OrderDir
56
57 # 2) time variant values:
58 # - Users may want to set these values when using lower level APIs
59 # - If users don't, TradeDecisionWO will help users to set them
60 # The interval of the order which belongs to (NOTE: this is not the expected order dealing range time)
61 start_time: pd.Timestamp
62 end_time: pd.Timestamp
63
64 # 3) results
65 # - users should not care about these values
66 # - they are set by the backtest system after finishing the results.
67 # What the value should be about in all kinds of cases
68 # - not tradable: the deal_amount == 0 , factor is None
69 # - the stock is suspended and the entire order fails. No cost for this order
70 # - dealt or partially dealt: deal_amount >= 0 and factor is not None
71 deal_amount: float = 0.0 # `deal_amount` is a non-negative value
72 factor: Optional[float] = None
73
74 # TODO:
75 # a status field to indicate the dealing result of the order
76
77 # FIXME:
78 # for compatible now.
79 # Please remove them in the future
80 SELL: ClassVar[OrderDir] = OrderDir.SELL
81 BUY: ClassVar[OrderDir] = OrderDir.BUY
82
83 def __post_init__(self) -> None:
84 if self.direction not in {Order.SELL, Order.BUY}:
85 raise NotImplementedError("direction not supported, `Order.SELL` for sell, `Order.BUY` for buy")
86 self.deal_amount = 0.0
87 self.factor = None
88
89 @property
90 def amount_delta(self) -> float:
91 """
92 return the delta of amount.
93 - Positive value indicates buying `amount` of share
94 - Negative value indicates selling `amount` of share

Callers 15

test_simulator_stop_twapFunction · 0.90
test_interpreterFunction · 0.90
test_network_sanityFunction · 0.90
get_orderFunction · 0.90
__getitem__Method · 0.90
single_with_simulatorFunction · 0.90
load_ordersFunction · 0.90

Calls

no outgoing calls

Tested by 8

test_simulator_stop_twapFunction · 0.72
test_interpreterFunction · 0.72
test_network_sanityFunction · 0.72
get_orderFunction · 0.72
single_with_simulatorFunction · 0.72