pmorissette / bt

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

Advice on backtesting options with BT #360

Open tamccall opened 2 years ago

tamccall commented 2 years ago

I had read that your previous statement around the topic here:

https://github.com/pmorissette/bt/issues/121

I know you had said that it wasn't designed to work with options, but I guess I wanted to reopen the discussion and see what it would take to actually add the functionality?

I'm assuming some extension of the SecurityBase class is in order here to model the option expiry at a minimum, but I'm guessing that there is more than just that modification needed. Wanted to see if you had any suggestions on how to properly implement.

JordanPlatts commented 2 years ago

I think you could do this a few ways. The simplest way IMO would be to backtest strategies on fixed tte, fixed moneyness implied vol time series. You will need to make assumptions on how you would roll options( like it was a 1 month out 0 moneyness option but time and stock have changed so now it’s 3 weeks out -1 moneyness) and gamma/theta/vanna/Volga pnl effects but after those assumptions you could use BT normally and replace money invested in a strategy with Vega.

You could also change the structure of the code to support derivatives and implement a pricing model for those derivatives with inputs(atm vol, skew, etc…).

timkpaine commented 2 years ago

With the changes to support fixed income, you should be able to implement rolling logic similar to the bonds example: https://github.com/pmorissette/bt/blob/master/examples/fixed_income.ipynb

See added algos here: https://github.com/pmorissette/bt/pull/245/files#diff-ca88adc1ae01d589471f388e66eaa973d7ccd3a4322e5a619b8a56879e0a1cc9

tamccall commented 2 years ago

You could also change the structure of the code to support derivatives and implement a pricing model for those derivatives with inputs(atm vol, skew, etc…)

So at a high level what would be needed for this?