1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-06 20:41:09 +08:00

supporting seperated buy and sell price

This commit is contained in:
Young
2021-07-06 06:28:14 +00:00
parent cb72857710
commit bdac9f4dda
3 changed files with 75 additions and 35 deletions

View File

@@ -2,7 +2,7 @@
# Licensed under the MIT License.
from __future__ import annotations
import copy
from typing import Union, TYPE_CHECKING
from typing import List, Tuple, Union, TYPE_CHECKING
from .account import Account
@@ -35,7 +35,7 @@ def get_exchange(
min_cost=5.0,
trade_unit=None,
limit_threshold=None,
deal_price=None,
deal_price: Union[str, Tuple[str], List[str]] = None,
):
"""get_exchange
@@ -54,8 +54,15 @@ def get_exchange(
min transaction cost.
trade_unit : int
100 for China A.
deal_price: str
dealing price type: 'close', 'open', 'vwap'.
deal_price: Union[str, Tuple[str], List[str]]
The `deal_price` supports following two types of input
- <deal_price> : str
- (<buy_price>, <sell_price>): Tuple[str] or List[str]
<deal_price>, <buy_price> or <sell_price> := <price>
<price> := str
- for example '$close', '$open', '$vwap' ("close" is OK. `Exchange` will help to prepend
"$" to the expression)
limit_threshold : float
limit move 0.1 (10%) for example, long and short with same limit.
@@ -69,13 +76,8 @@ def get_exchange(
trade_unit = C.trade_unit
if limit_threshold is None:
limit_threshold = C.limit_threshold
if deal_price is None:
deal_price = C.deal_price
if exchange is None:
logger.info("Create new exchange")
# handle exception for deal_price
if deal_price[0] != "$":
deal_price = "$" + deal_price
exchange = Exchange(
freq=freq,