股票市场计算费用

Fees on stock market calculation

我正在进行回测,我在费用计算方面遇到了问题。

假设手续费是 0.1%

而且我已经有了 buy/sell 价格,所以我可以检索利润百分比:

其中:

df['Profit'] = ((df['Sells'] - df['Buys']) / df['Buys']) + 1

示例:

Buys Sells Profit
3697.35 3698.69 1.000362
3698.24 3699.81 1.000425
3703.69 3706.23 1.000686

所以没有费用的return是

returns = df.Profit.cumprod()

如何计算实际 return(含费用)?

我们先看看你的公式:

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)