Python backtest using percentage based commission
<p>I'm writing a script to backtest some strategies for a set of stocks using the bt framework for python. In the bt documentation (<a href="http://pmorissette.github.io/bt/bt.html#module-bt.backtest" rel="nofollow">backtest module</a>) it says: </p>

<blockquote>
  <p>commission (fn(quantity)): The commission function to be used.</p>
</blockquote>

<p>So when I run my code </p>

<pre><code>result = bt.Backtest(strategy, data, initial_capital= 100000.00, commissions=)
</code></pre>

<p>I want to pass a function that returns a percentage based commission e.g. 0.5 % of the transaction. Since I don't know the size of the transactions, is this even possible? How would it otherwise be solved, using a set commission?</p>

<p>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:</p>

<pre><code>def my_comm(q, p):
    return abs(q)*p*0.0025
</code></pre>

python pandas stocks back-testing