1

I'm writing a script to backtest some strategies for a set of stocks using the bt framework for python. In the bt documentation (backtest module) it says:

commission (fn(quantity)): The commission function to be used.

So when I run my code

result = bt.Backtest(strategy, data, initial_capital= 100000.00, commissions=)

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?

simtaxman
  • 613
  • 2
  • 11
  • 18
  • Just a wild guess, but unless the price varies too much, a commission on quantity should have the same effect as a commission on price. – IanS Oct 18 '16 at 14:29
  • I'm using data since the beginning of 2000 so price will vary quite a lot. But I'm not managing on basing it on the quantity either, how to I now the quantity of the transactions? – simtaxman Oct 18 '16 at 14:34

1 Answers1

0

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:

def my_comm(q, p):
    return abs(q)*p*0.0025
simtaxman
  • 613
  • 2
  • 11
  • 18
  • do you know whether it is possible to get a time series of (exact) commissions paid per transaction? i realise commissions are taken into account when one calculates `res.display()`. The same with outstanding cash, do we have a time series of outstanding cash at all points in time? – Zhubarb Jan 31 '18 at 14:59