问答交流

HF Trade模块期货回测如何实现无杠杆交易?

由franklili创建,最终由small_q 被浏览 15 用户

我使用HF Trade模块进行期货回测,不想使用杠杆,即100%保证金交易,如何设置限制呢?

如果在初始函数中使用context.set_max_leverage(1),运行时会报错:

2023-02-24 17:23:17.721561 strategy strategy exception:Traceback (most recent call last): File "bigtrader/strategy/engine.py", line 715, in bigtrader2.bigtrader.strategy.engine.StrategyEngine._call_strategy_func File "bigtrader/strategy/strategy_base.py", line 2169, in bigtrader2.bigtrader.strategy.strategy_base.StrategyBase.call_on_init File "<ipython-input-58-37caf9b99a13>", line 283, in m42_initialize_bigquant_run context.set_max_leverage(1) AttributeError: 'StrategyEx' object has no attribute 'set_max_leverage'

\

标签

回测期货交易
评论
  • 在初始化函数里设置这个方法 set_margin(symbol, margin_ratio, account_id='') Set the margin ratio for the symbol. ``` Parameters ---------- symbol : the symbol code of future. margin_ratio : the margin ratio of the corresponding future security. float or dict dict example: margin_ratio = {'long_margin_ratio_by_money': 0.07, 'short_margin_ratio_by_money': 0.07} ``` \
  • 我按照你的方法设置了,但是运行回测后,持仓记录中显示持仓保证金为0,成交后剩余资金等于资产总值,不对呀。 ![{w:100}](/wiki/api/attachments.redirect?id=39629234-a13e-47cc-b9b4-44f2052a93e3) ![{w:100}](/wiki/api/attachments.redirect?id=3458b186-141f-4ae8-9daf-b257faf018db)/
{link}