Expected profit (or loss) from an options trading strategy

Using Python with OptionLab to compute expected values

Roberto Gomes, PhD
6 min readOct 6, 2023
Photo by Elena Koycheva on Unsplash

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.

This is the sixth article I’m posting on Medium, all related to how to use OptionLab to quickly evaluate options trading strategies. Check out this article for a quick introduction to the library. OptionLab is easy to use, as you can see in articles where I covered popular options trading strategies like call spreads and covered calls with just a few lines of code.

Previously, the focus was on estimating the Probability of Profit (PoP) in options trading strategies, which is certainly important for an options trader, even though it’s limited by the simplifications and assumptions of the Black-Scholes model.

In another article, I discussed an additional capability of the library, which is to estimate the probabilities of reaching and surpassing a profit target and/or a loss limit.

In this article, there’s another valuable piece of information for traders that we’ll address by using a practical case study. It answers the following question: For a specific strategy, if my trade results in a positive return, what is the conditional expected value of that return, i.e., the expected value of the profit? Conversely, what would be the expected value of the loss for trades with a negative return?

Both the expected profit and expected loss represent the averages of the profits and losses, respectively, taken from the same options trading strategy being repeated a large number of times. One method to compute those expected values, which can be quite tedious and susceptible to being statistically flawed (in my opinion), is to resort to backtesting using market data for stocks and options. Another approach, much more straightforward, involves generating a significant quantity of terminal prices for the underlying asset using a well-established, yet approximate, model. In the case of OptionLab, one such model employed is the Black-Scholes model, where the future price S(T) of the stock at time T (in years), considering the current price S0, is calculated as follows:

In this equation, r is the annualized risk-free interest rate, σ is the annualized volatility of the underlying stock and Z is a standard normally distributed random variable.

By default, OptionLab generates 100,000 terminal prices of the stock using the equation above. For each price generated for the stock at time T, OptionLab checks whether this price is within the price range (or ranges) for which the strategy is profitable (i.e., generates a return of at least $0.01). The strategy’s return is then calculated and added to the other positive returns, and the average is obtained, representing the expected return of the strategy when it is profitable. Similarly, the expected loss is calculated as an average but when the strategy’s return is less than or equal to -$0.01.

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.

For the purpose of illustration, the strategy to be analyzed is a short straddle. This strategy is implemented with the trader selling a certain number of calls and the same number of puts, all options having the same strike price and maturity.

Just like in the last article I posted here, I will consider that the underlying asset is Nvidia stock (ticker: NVDA). Perhaps things have changed by the time you are reading these lines, and you may not remember this, but as of the moment I am writing this article, Nvidia, the manufacturer of GPUs that enable the development of advanced machine learning models, is the prominent company in focus.

In this example, 100 call options and 100 put options were sold, all with the same strike price of $170.00 and expiration on February 17, 2023. The chosen strike price was the closest to the spot price of the stock, which was $168.99 on January 16, 2023, the date when the short straddle was created. Premiums of $9.90 and $10.20 were collected for each call and put option, respectively.

The evaluation of this strategy using OptionLab is, as usual, straightforward, as the reader can see in the Python code snippet below. Please note the compute_expectation argument of the get_data() method, which gathers the necessary data for simulating the strategy. It should be set to True to instruct OptionLab to calculate the expected profit and loss.

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
compute_expectation=True # Necessary to compute average profit and loss

# The short straddle strategy is defined
strategy=[{"type":"call","strike":170.0,"premium":9.9,"n":100,"action":"sell"},
{"type":"put","strike":170.0,"premium":10.2,"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,
compute_expectation=compute_expectation)

out=st.run()

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

# Print useful information on screen
print("Strategy credit: %.2f" % out["StrategyCost"])
print("Stock price profitable range at maturity: %.2f -> %.2f" %
(out["ProfitRanges"][0][0],out["ProfitRanges"][0][1]))
print("Maximum profit: %.2f" % out["MaximumReturnInTheDomain"])
print("Maximum loss: %.2f" % (abs(out["MinimumReturnInTheDomain"])))
print("Probability of profit: %.1f%%" % (out["ProbabilityOfProfit"]*100.0))
print("Expected profit: %.2f" % out["AverageProfitFromMC"])
print("Expected loss: %.2f" % abs(out["AverageLossFromMC"]))

When you execute this code, the first thing you will see is the strategy’s profit/loss (P/L) diagram. In this diagram, the vertical dashed green line represents the spot price position of Nvidia stock on January 16, 2023. The red arrows pointing to the right and left correspond to the strike positions of the sold calls and sold puts, respectively. Since the call and put options have the same strike, the arrows appear superimposed.

Profit/loss diagram of the short straddle.

One thing that obviously stands out is the fact that the profit of a short straddle strategy has a ceiling, but the loss has no floor. In the price range of the stock considered in this study, the maximum profit ($2,010.00, which is the value received from selling the calls and puts) is about four times smaller than the maximum loss ($8,091.00). This gives a good idea of the risk involved, so I would like to repeat this is a study for educational purposes, not a recomendation!

The print commands at the end of the Python code snippet display on the screen some information of interest to the trader. This information is contained in a dictionary stored in the variable out that receives the return from the run() method.

Strategy credit: 2010.00
Stock price profitable range at maturity: 149.91 -> 190.09
Maximum profit: 2010.00
Maximum loss: 8091.00
Probability of profit: 58.4%
Expected profit: 1060.76
Expected loss: 1402.89

The PoP for this strategy at the options’ expiration was slightly over 58%. To be profitable, Nvidia’s stock price needed to fall within the range of $149.91 to $190.09 on February 17, 2023.

The last two lines are particularly relevant for the purpose of this article. The expected profit of this short straddle at expiration, if it turned out to be profitable, amounted to $1,060.76. On the other hand, the expected loss, should the strategy yield a negative return, was estimated at $1,402.89. These expected values, beyond the absolute figures themselves, offer insights into how short straddles with a similar configuration of calls and puts would perform when executed repeatedly over time. In simpler terms, with this PoP and knowing the expected profits and losses, traders could anticipate whether their accounts were likely to grow or face the risk of being wiped out.

OptionLab 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.

OptionLab’s source code is freely available on GitHub:

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

--

--

Roberto Gomes, PhD

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