pmorissette / bt

bt - flexible backtesting for Python
http://pmorissette.github.io/bt
MIT License
2.11k stars 408 forks source link

A few questions #57

Closed J13B closed 8 years ago

J13B commented 8 years ago

Hi Philippe,

First of all : Bonne année 2016 (I guess from your name that you may be speaking French).

I had a lot of fun playing with your project and it actually fits my needs to rapidly prototype some strategies. It also fits my way of thinking about a trading system implementation. I'm pretty new to python, designed my own trading system in C++, and it's a great tool for what I'm intending to achieve: I'll probably build on it for my personal ETF trading.

The way I use Bt today is the following:

In this context, I have a few question:

Thank you very much for your time and help.

Best, Joris

J13B commented 8 years ago

Update: I think I managed to pass a commission function, however, passing None as commissions or passing a function returning 0 give two different results (actually better with the function).

pmorissette commented 8 years ago

Hey @J13B,

Sorry for the late reply and merci!

The commission function defaults to $0.01 per unit with a minimum of $1 per transaction. This was roughly modeled after the Interactive Brokers commission structure. So if you pass in None, it defaults to this. If you pass in a dummy function that always returns 0, then you essentially ignore commissions. The function has two arguments: quantity and price. You can come up with your own function using these two inputs.

As for point 2, yes this is correct. The rebalancing happens on the same day. This basically assumes that you can execute the trade at the same price as you use in your analysis. For the type of backtesting I was doing, this suited my needs. If not, you can always design an Algo to account for this.

Not sure what you mean for point 3. Essentially, you have a given amount of capital at the start and you can allocate it as you wish (by setting the weights). The gains earned by these allocations accrue to the account. The resulting equity curve reflects the equity progression over time. This is essentially what would happen in "real life".

I hope this answers your questions and sorry again for the delay.

Cheers, Phil

J13B commented 8 years ago

No worries with the delay, it was holiday season (+ one can never complain about a free service)

1- commissions : I guess q is quantity traded at that point, not the total position quantity + p is the price traded 2 - perfect, that's what I was looking for + tcosts and market impact can be roughly estimated in the commission function 3 - By cumulated performance, I mean that the same fixed amount is always invested. In your calculations, the PnL is reinvested every day.

Thanks again.

pmorissette commented 8 years ago

Hey @J13B,

Yes q is quantity traded and p is the price. As for your last question, now I get it. You would have to write a custom algo to replace Rebalance. I believe you should be able to achieve your goal with the base parameter in target.rebalance (line 1226 in algo.py).

Cheers, Phil

J13B commented 8 years ago

Will check, thanks.