Python for Options Trading (3): A Trade with 100% Probability of Profit

Roberto Gomes, PhD
6 min readOct 29, 2023

--

Image by OpenClipart-Vectors from Pixabay

EDIT: OptionLab is undergoing extensive modifications to its source code, which impliest that the example showcased in this article does not work with the latest version. You can access the source code of the old library here. It is also possible to install the old version using pip, as shown below.

In this brief article, I showcase an options trading strategy with a Probability of Profit (PoP) of 100%. And this is not really surprising, as you, my esteemed reader, will discover in the following paragraphs. This possibility becomes quite obvious when you understand the conditions necessary to achieve such a remarkable outcome.

What is truly important in this article is to showcase another feature of my Python library, OptionLab, which brings a lot of flexibility to those studying options trading from a quantitative perspective.

EDITED: This article has garnered numerous comments, consistently leaning towards the negative. These comments are from individuals who either failed to comprehend the content or were expecting another article featuring a “Get Rich Quick” strategy, which is not the focus of this piece. If your intention is not to carefully read the article and understand its implications, please refrain from proceeding further.

On the contrary, if you are eager to learn something that may be valuable for your exploration of options trading using Python (as the purpose of this article is educational), feel free to continue. It’s worth noting that the strategy presented is not an entirely new concept; adjustments in winning long calls have been discussed elsewhere, and you can easily find examples through a Google search. Additionally, many readers asked about what happens when the price of the underlying moves to the other side. To address this scenario, I recently published this article.

For those choosing to proceed, enjoy the read. I am always open to discussions, but I want to make it clear that I will no longer respond to comments that are disrespectful or lacking in substance.

If you haven’t already done so and have installed a Python framework like Anaconda Python, you should, first and foremost, install OptionLab as usual with pip install optionlab==0.2.0. The source code of the library is also available on the project's GitHub page. Giving the project a star is always welcome.

OptionLab is free, open source code and is provided as is, with no guarantee that its results are accurate. As such, I am not responsible for any losses caused by the use of the code. I am open to hearing any questions, corrections, comments or suggestions about the code. You can also reach me on Linkedin.

Bugs can be reported as issues on the project’s GitHub page above.

Before we proceed, please bear in mind that options trading is a highly risky activity and should be approached with due diligence, as it can lead to significant losses. The content of this article is not a recommendation and is purely for educational purposes.

As in this article and in this article, the underlying asset in this study is Nvidia stock (ticker: NVDA), traded on January 16, 2023, at $168.99. The strategy is constructed as follows: 100 call options with a strike price of $165.00 were purchased, and 100 call options with a strike price of $170.00 were sold, with both legs of the strategy expiring on February 17, 2023. In principle, this strategy may appear to resemble a call spread, which would typically result in a debit in the trader’s account, as they are selling options with a higher strike price than the options they are buying. As you are well aware, such a strategy certainly does not have a PoP of 100%.

However, there is a very special circumstance in which this call spread does, indeed, become a strategy with a 100% PoP. This may occur when you enter the long and short positions at different times. Let’s say you purchased these 100 call options at some point before January 16, 2023, when these options were OTM (meaning Nvidia’s stock price was below $165.00), and you paid $7.50 each for them. This implies that $750.00 left your account.

If the stock price rose to $168.99 on January 16, 2023, it means that those call options became ITM, and consequently their price increased. In fact, they were trading at $12.65 each on that day. On the other hand, the premium of the $170.00 strike call options was $9.90 each. Therefore, by selling these options, you would collect $990.00. With these cards on the table, what would be the worst-case scenario?

Since we are talking about call options where the long leg has a lower strike price than the short leg, the worst-case scenario would be Nvidia’s stock price falling below the strike of the long leg at expiration. In this situation, the value of these options would vanish, as they would possess no time value and would be out of the money. The final outcome of this trade would be the amount of money collected from selling the higher strike call options minus the cost of the lower strike call options. If this call spread consisted of positions entered at the same time, it would inevitably result in a loss.

Nonetheless, because you entered the long position when these options had a lower price than the options you sold, the outcome in the worst-case scenario would still yield a profit of $240.00! In the end, you paid $750.00 for the call options you purchased but received $990.00 for the ones you sold.

You can see below the profit/loss diagram of this strategy as computed by OptionLab.

Profit/loss diagram of the strategy.

Built in this way, the price range of the underlying asset for which this strategy is profitable spans from zero to infinity. On the other hand, as you can also see, the maximum profit is limited to $740.00 and is reached when the price of the underlying asset goes above the strike of the options that were sold.

The following Python code snippet illustrates how to use OptionLab to generate this profit/loss diagram.

from optionlab.strategy import Strategy

st=Strategy()

# Input data (Nvidia, NVDA)
stockprice=168.99
volatility=0.483
startdate="2023-01-16"
targetdate="2023-02-17"
interestrate=0.045
minstock=stockprice-100.0
maxstock=stockprice+100.0

# The strategy is defined. Pay attention to the 'prevpos' key in the first dictionary
strategy=[{"type":"call","strike":165.0,"premium":12.65,"n":100,"action":"buy","prevpos":7.5},
{"type":"call","strike":170.0,"premium":9.9,"n":100,"action":"sell"}]

# Input data is provided and the calculations are performed
st.getdata(stockprice=stockprice,startdate=startdate,
targetdate=targetdate,volatility=volatility,
interestrate=interestrate,minstock=minstock,
maxstock=maxstock,strategy=strategy)

out=st.run()

# Display the profit/loss diagram
st.plotPL()

At first glance, it might not seem particularly interesting to use Python code, no matter how simple it is, to arrive at the conclusion that it is indeed possible to have a strategy resembling a call spread with a 100% PoP. However, as I mentioned at the beginning of this article, what truly matters is to illustrate, through an example, a feature of the OptionLab library that can be highly valuable in the construction of complex options strategies.

In accordance with OptionLab syntax, a strategy is defined as a list in which each leg of the strategy is represented by a dictionary. In the first leg of the strategy that we used as an example, there is a key, prevpos, which informs OptionLab that this leg of the strategy corresponds to a position that was already open. If the value of this key is positive, it indicates that this position will remain open. This is the case in the example provided in this article. If this value were negative, it would imply that the position would be closed, and its outcome (profit or loss) should be considered in the payoff calculation.

Most of the options strategies taught out there are static. In other words, the positions corresponding to the legs of the strategy, even if they have different expirations (as in a calendar spread), are opened simultaneously and the strategy remains unchanged until a target date, when all legs are closed.

Nevertheless, in real-world scenarios, a trader may wish to adjust these positions over time by closing some and/or opening others based on market movements. These adjustments lead to the creation of dynamic strategies that offer more flexibility to the trader, albeit at the cost of greater complexity when compared to their static counterparts.

Primarily an educational tool, OptionLab, through prevpos, provides users with the ability to assess dynamic strategies in ways that would not be possible without the use of computational algorithms.

--

--

Roberto Gomes, PhD

I am a Professor of Materials Engineering specialized in computational research in materials science, physics, and engineering. Also interested in finance.