Any chance to use backtrader to back test call / put option trade ?
I'm new to python and backtrader. Played around awhile, it is indeed a very complete and good tool, albeit still need some time to know how to use it.
Googled around, but can't find anything about using the backtrader to back test call / put option. Is there any easy way to do or just simulate ?
Thanks in advance.
You need to elaborate on what you want to do. Simulating Call and Put options as an
OHLCseries is obviously supported.
You can also add extra information to any data feed, which may be entra information you want to add to the option.
But it all boils down to what you exactly want to do.
Thank you very much for the prompt reply. Yes, based on daily OHLC.
What I want to do is to backtest a strategy not using the equity price, but using option. As it looks complicated to find market data about the option value corresponding to the equity, even if i can find data, there are just too many data including expiry, in-at-out of money, which will be troublesome to add to data feed and operate on. I think it may be easier to simulate the invested value based on the black scholes model.
Suppose using BS formula to calculate the option price, I don't know how to place an order, when the equity reach or beyond (in a jump) the target value, it then charge me the money required for that option. Sure the order instruction will include more information (target, size, type = call / put, at the money / how much away from the target, expire this month / next month, valid), upon execution, it will return the incurred cost. Upon liquidation or expiry, the account will lost the money or get credit. Of course can concurrently have different combination of trade on hand.
May be those are simple in backtrader, but I'm new and couldn't find any example.
You don't simply want to test OHLC. From all that you have written just a sample:
Upon liquidation or expiry, the account will lost the money or get credit
You obviously are considering different options and keep on trading with others after expiry.
No. It is not your platform.
Thank you for the sharp reply.
Curious to what you mean initially that simulating call and put options as an OHLC series is obviously supported ?
You want for example to jump from option to option using expiry dates and not simply look for price patterns in a particular OHLC series.
Same as trying to backtest the SP500 from the beginning of time, where some companies are added/removed to the system.
This is not something backtrader is well suited for, because when it calls your
next(method with logic) the guarantee is that all buffers (data, indicators) have something. But you want some options only from a given point in time, breaking the entire system.
Thank you for the clarification.
I don't mean so automatic to renew the option. The renewal should be taken care via coding in the strategy. Just don't know how to do option trading in backtest.
Anyhow, I will use other tools to do what I intended to do.
andrei last edited by
@backtrader "because when it calls your next (method with logic) the guarantee is that all buffers (data, indicators) have something. But you want some options only from a given point in time, breaking the entire system."
why should that be the case? NaN / missing values could be added into a series that spans 3 months across your 10 years worth of data. then you really may have multiple such data feeds that would be "active" / providing value just for a sub-set of your timeline. still, some built-in / helper functionality would be useful in "homogenizing" all these small time-span option series. would this be possible?