Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-230

Transaction Cost Penalty

Problem

Compute the transaction cost of a rebalance.

Return cost_rate * sum(abs(w_new[i] - w_old[i])) over all positions, the proportional cost of the traded notional.

Hint

Transaction costs scale with total turnover.

Test cases

case 1
in: [[0.5,0.5],[0.6,0.4],0.01]
expected: 0.0019999999999999996
case 2
in: [[1,0],[0,1],0.05]
expected: 0.1
case 3
in: [[0.25,0.25,0.5],[0.25,0.25,0.5],0.1]
expected: 0
Starter codePython
def transaction_cost_penalty(w_old, w_new, cost_rate):
    # Your code here
    pass

3 test cases · run your code against them in the editor