用交易成本计算 returns

Calculating returns with trading costs

这可能是在计算交易 returns 的同时包含交易成本的过度简化。我做了一些假设——投资和提取投资的佣金分别为 1% 和 2%。佣金在交易期间不变,在本例中为 5 个时间步长。我使用 Python 代码来执行计算。

给定资产在 5 个时间步长内的一组正负百分比变化为 {0.031% , 0.00121% , 0.0231% , -0.0213% , -0.0121%}

进入投资的佣金是投资金额的1%,退出投资的佣金是投资金额现值的2%。

如果我在这个资产上投资 1 欧元,以下是正确的吗?

1.

如果我在 $t=5$ 之前不交易投资,则最终投资金额为: $t=5$ 时的最终百分比变化量为 'initial invested amount' + '% change' - 'commission to enter' - 'commission to exit',因此:

initial_investment_amt = 1

comission_in_amt = 1

comission_out_amt = 2

price_change = -.0121

return_amt = (initial_investment_amt + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100) = 0.97 which represents a loss of 1 - .97 = .03

2.

如果我在每个时间步进行投资直到$t=5$,最终投资金额为:

initial_investment_amt = 1

comission_in_amt = 1

comission_out_amt = 2

price_change = .031

return_amt_1 = (initial_investment_amt + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100)

price_change = .00121

return_amt_2 = (return_amt_1 + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100)

price_change = .0231

return_amt_3 = (return_amt_2 + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100)

price_change = -.0213

return_amt_4 = (return_amt_3 + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100)

price_change = -.0121

return_amt_5 = (return_amt_4 + (price_change / 100)) - (comission_in_amt / 100) - (comission_out_amt / 100)

print(return_amt_1)
print(return_amt_2)
print(return_amt_3)
print(return_amt_4)
print(return_amt_5)

打印:

0.97031
0.9403220999999999
0.9105530999999999
0.8803400999999998
0.8502190999999998

表示损失 $1 - 0.85 = 0.15$。

首先,我不得不恭敬地不同意您对案例 1 的结论:

The final investment amount if I do not trade the investment until $t=5$ is: the final percentage change amount at $t=5$ which is 'initial invested amount' + '% change' - 'commission to enter' - 'commission to exit

我认为最终值的正确公式是

((initial investment amount - commission to enter) * (1 + % change)) - commission-to-exit. The main difference being the fact that the commission to enter/investment fee is taken out of circulation before the return on investment can be earned. This makes for a significant difference over time.

假设我是正确的,下面是我建议的代码。为了便于参考,我冒昧地更改了一些术语,但您显然可以将其更改为适合您的任何内容:

p_changes = [0.03100, 0.00121, 0.02310, 0.02130, -0.01210]
initial_investment_amt = 100 #I used a larger initial investment; otherwise, the fees would have eaten you alive...
invest_fee = 1
sell_fee = 2

def periodic_ret(amount,change,reinv):

    if reinv == 0:
        if ind + 1 == 1: #for the initial period
            forward = (amount-invest_fee)*(1+change)      
        if ind +1 == len(p_changes): #for the final period
            forward = (amount*(1+change))-sell_fee
        else:
            forward = (amount*(1+change))
    else:
        forward = (amount-invest_fee)*(1+change)-sell_fee
    print(forward)
    return forward    

for i in range(len(p_changes)):
    reinv = 1 #1 if an invest and sell fee are paid each period, or 0, if an invest fee is paid once upfront and sell fee is paid once at the end
    if i == 0: #for the initial period
        cur = periodic_ret(initial_investment_amt, p_changes[0], reinv)
    else:
        cur = periodic_ret(cur,p_changes[i], reinv)

输出(w/reinv = 1):

100.06899999999999
97.18887348999998
96.41083646761896
95.44308728437926
91.30032592823827

佣金和价格变化均以百分比形式给出。这意味着投资后账户中的金额立即为:

initial_investment_amt*(1-commission_in_amt/100)

_amt 后缀可能令人困惑,但佣金在问题中表示为 %。

在第一个投资期后账户的金额为:

initial_investment_amt*(1-commission_in_amt/100)*(1-price_change/100)

最后在退出后客户端收到:

initial_investment_amt*(1-commission_in_amt/100)(1-price_change/100)(1-commission_out_amt/100)

我认为模式很明确,因此您只需插入更多 price_changes 以获得更长的投资,如果您撤资并再投资,您将需要支付更多的佣金。 希望这没问题 - 抱歉没有代码 - 但这样看起来更清晰并使用问题符号。