Back to Community
Options in Quantopian

A lot of people have been asking how I've been testing option-based algorithms on Quantopian, so I've decided to share this with you all; it is a work around until Quantopian adds option capabilities to their pipeline.

I didn't comment this, but I don't think it is too hard to follow...

I've created a virtual cash balance that is just an integer variable (defaulted to $1 million). I then use the Black Scholes model to find the price of the option (or a close estimate thereof). When an option is purchased the price determined by Black Scholes is deducted from the virtual cash balance. When the option is sold, the fmv of the option is added back to this virtual cash balance. When the option is about to expire, the program automatically makes the appropriate decision for the investor and adjusts the virtual cash balance as needed.

The fmv of the virtual portfolio is shown each trading morning in the log. Unfortunately, there is no way that I know of to automatically export this data to a csv or excel via Quantopian. This can, however be done relatively quickly via a copy, paste.

Please let me know if you have any questions.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59377de9516a426dee602d37
There was a runtime error.
10 responses

That's pretty nifty. Thank you for sharing it.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank you! I didn't spend too much time on this (as I don't do much with options) and am currently working on other projects, but if people are interested I could touch this up a bit and turn it into a python library that is seamless and easy to use.

I've been interested in this for awhile. Isn't the black-scholes equation for European options? Or is the difference small enough to be negligible if the option is exercised near expiry?

i like your concept of a work around. but there is a major flow with what you are doing. it lies in the actual Implied Volatility input. when you use the BS model you are making the assumption that there is no skew (that all strikes have the same vol) and also making the assumption that volatility and the skew is constant. so unless you are getting very specific strike by strike vols you have a very large flaw in your testing.

I bring this up from experience in trying the same thing. testing results were in the "too good to be true" realm. good luck finding an "easy" solution.

Tim-you're right, this does not take into account volatility skew, don't think it is impossible to do so.

But I think you're missing the point of this tool; I am trying to create a close estimate of option prices so Quantopian users can start writing and testing their option-based algos so they can try to find something that works. Thus, users will be able to begin writing option algos before Quantopian adds option trading capabilities to their pipeline.

Volatility skew does not have a huge impact on the overall price of the options, especially if you are trading basket indices like the SPY (which I assume to be popular here). And, as Ranuka said,the black-scholes formula calculates the price of a European option. But most consider it a good estimate of an american option as there is often no reason to exercise it before expiration. Thus this work around will only provide close estimates of option prices. And close estimates should be enough for users to begin using options. When quantopian releases options these users will be able to quickly transfer and trade on their algos.

Another major flaw is bid-ask spread. In options per contract the bid-ask can be as wide as $1-$4/share or $100-$400 per contract. Any model will need a huge slippage model otherwise it will be easy to trade fair options all the time.

If we talk about the SPY mentioned above, usual bid-ask spread is 1 cent, which corresponds to $1 in 1 contract

Yeah I thought of the bid ask spread and almost included a formula that estimated spreads based on volume, but didn't think it was necessary for this. Remember tool is just an estimation so we can start thinking of option algos now and not have to wait for Qunatopian to release this capability. And if just test the black-scholes and pricing part of the above algorithm, I think you'll see the resulting prices are really good estimations in most cases. As Louri said spreads on SPY options are negligible.

I don't think missed the point. I applaud the effort. It's a good idea. Something I hacked quickly together using Bloomberg before I got something together with actual historical prices. And even that is a clunky hack.

"Scott Merrill said

skew does not have a huge impact on the overall price of the options, especially if you are trading basket indices like the SPY "

I disagree. It may not be huge but For sure it can take a nice strategy with a hypothetical 1.5-2.0 Sharpe to nearly zero.

You idea is doable and on track. But my point is that there are very nuanced pitfalls to that approach. Any code needs to specifically reference a strike, grab the implied vol for that exact strike on trade date, (again assuming you are getting accurate vols prints). And if it's a stock with all the dividend and + or - interest rate a stock has at the time (which is usually only available from a clearing firm and may or may not be historically tracked) and then grab implied vol for that same strike on exit.

There is a significant difference in actual p/l vs hypothetical p/l if you are off even by a couple strikes. I've got plenty of strategies from my initial tests that are great when just using raw ATM vols that were mediocre at best when actual vols were used.

Another thing to consider is you have to be using the exact same version of the BS model as where you are grabbing your vols. Just do a quick double check that you are generating option prices with your test that actually correspond to values that traded (or were quoted) in the market on a specific day.

I was going to bring up Bid/ask spread. But since there isn't one anymore (relative to 2000-2010 pre penny Increments) on the tier 1 liquid names I figured I'd let it go. But you would be surprised out much even a .05 per contract spread can eat at anything you create that has scale.

Good luck.

On Thu, Jun

I totally disagree.

anyone knows when will the option released ?