3697.35
3698.69
1.000362
3698.24
3699.81
1.000425
3703.69
3706.23
1.000686
我正在进行回测,我在费用计算方面遇到了问题。
假设费用为0.1%
我已经有了买入/卖出价格,所以我可以检索利润百分比:
地点:
df['Profit'] = ((df['Sells'] - df['Buys']) / df['Buys']) + 1
的例子:
让我们先看看你的公式:
Profit = (Sells - Buys) / Buys + 1
= Sells / Buys - Buys / Buys + 1
= Sells / Buys - 1 + 1
= Sells / Buys
现在,由于交易费用,0.1%从您的销售中扣除,也添加到您的购买中。因此,可以将代码重写为:
fee = 0.001
df['Profit'] = df['Sells'].mul(1 - fee) / df['Buys'].mul(1 + fee)