mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-14 16:26:55 +08:00
update Order with dataclass
This commit is contained in:
@@ -1,30 +1,35 @@
|
|||||||
# Copyright (c) Microsoft Corporation.
|
# Copyright (c) Microsoft Corporation.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
import pandas as pd
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Order:
|
class Order:
|
||||||
|
"""
|
||||||
SELL = 0
|
stock_id : str
|
||||||
BUY = 1
|
amount : float
|
||||||
|
start_time : pd.Timestamp
|
||||||
def __init__(self, stock_id, amount, start_time, end_time, direction, factor):
|
closed start time for order generation
|
||||||
"""Parameter
|
end_time : pd.Timestamp
|
||||||
direction : Order.SELL for sell; Order.BUY for buy
|
closed end time for order generation
|
||||||
stock_id : str
|
direction : Order.SELL for sell; Order.BUY for buy
|
||||||
amount : float
|
factor : float
|
||||||
trade_date : pd.Timestamp
|
|
||||||
factor : float
|
|
||||||
presents the weight factor assigned in Exchange()
|
presents the weight factor assigned in Exchange()
|
||||||
"""
|
"""
|
||||||
# check direction
|
stock_id : str
|
||||||
if direction not in {Order.SELL, Order.BUY}:
|
amount : float
|
||||||
|
start_time : pd.Timestamp
|
||||||
|
end_time : pd.Timestamp
|
||||||
|
direction : int
|
||||||
|
factor : float
|
||||||
|
deal_amount : float = field(init=False)
|
||||||
|
SELL : ClassVar[int] = 0
|
||||||
|
BUY : ClassVar[int] = 1
|
||||||
|
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if self.direction not in {Order.SELL, Order.BUY}:
|
||||||
raise NotImplementedError("direction not supported, `Order.SELL` for sell, `Order.BUY` for buy")
|
raise NotImplementedError("direction not supported, `Order.SELL` for sell, `Order.BUY` for buy")
|
||||||
self.stock_id = stock_id
|
|
||||||
# amount of generated orders
|
|
||||||
self.amount = amount
|
|
||||||
# amount of successfully completed orders
|
|
||||||
self.deal_amount = 0
|
self.deal_amount = 0
|
||||||
self.start_time = start_time
|
|
||||||
self.end_time = end_time
|
|
||||||
self.direction = direction
|
|
||||||
self.factor = factor
|
|
||||||
|
|||||||
Reference in New Issue
Block a user