Skip to content

Commit

Permalink
🐞 fix: 允许回测时指定本金和佣金
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-yang-biz committed Jan 18, 2024
1 parent 297ea89 commit ad30b91
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions omicron/strategy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(
end: Optional[Frame] = None,
frame_type: Optional[FrameType] = None,
warmup_period: int = 0,
principal: float = 1_000_000,
commission: float = 1.5e-4
):
"""构造函数
Expand All @@ -60,6 +62,8 @@ def __init__(
end: 如果是回测模式,则需要提供回测结束时间
frame_type: 如果是回测模式,则需要提供回测时使用的主周期
warmup_period: 策略执行时需要的最小bar数(以frame_type)计。
principal: 回测时初始资金。默认为100万。实盘时会自动忽略此参数
commission: 回测时的手续费率。默认为0.015%。实盘时会自动忽略此参数
"""
self.ver = ver or "0.1"
self.name = name or self.__class__.__name__.lower() + f"_v{self.ver}"
Expand All @@ -78,6 +82,9 @@ def __init__(
if start is None or end is None or frame_type is None:
raise ValueError("start, end and frame_type must be presented.")

start = tf.floor(start, frame_type)
end = tf.floor(end, frame_type)

self.bs = BacktestState(start, end, None, 0, warmup_period)
self._frame_type = frame_type
self.broker = TraderClient(
Expand All @@ -87,6 +94,8 @@ def __init__(
is_backtest=True,
start=self.bs.start,
end=self.bs.end,
principal=principal,
commission=commission
)
else:
if account is None or token is None:
Expand Down

0 comments on commit ad30b91

Please sign in to comment.