简体   繁体   English

使用基于百分比的佣金进行Python回测

[英]Python backtest using percentage based commission

I'm writing a script to backtest some strategies for a set of stocks using the bt framework for python. 我正在编写一个脚本,以使用python的bt框架回测一组股票的某些策略。 In the bt documentation ( backtest module ) it says: 在bt文档(回测模块 )中,它说:

commission (fn(quantity)): The commission function to be used. 佣金(fn(quantity)):要使用的佣金函数。

So when I run my code 所以当我运行我的代码

result = bt.Backtest(strategy, data, initial_capital= 100000.00, commissions=)

I want to pass a function that returns a percentage based commission eg 0.5 % of the transaction. 我想传递一个函数,该函数返回基于百分比的佣金,例如交易的0.5%。 Since I don't know the size of the transactions, is this even possible? 由于我不知道交易的规模,这有可能吗? How would it otherwise be solved, using a set commission? 使用固定佣金将如何解决该问题?

Solved it by creating a function with parameters for quantity and price. 通过创建带有数量和价格参数的函数来解决该问题。 Thus it was easy returning a percentage based on the transaction cost as follows: 因此,很容易根据交易成本返回一个百分比,如下所示:

def my_comm(q, p):
    return abs(q)*p*0.0025

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM