How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (2024)

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (3)

Introduction

Hello everyone , I wish everyone is having a great year so far and hopefully financially on track for financial freedom.

So basically this is a continuation of my previous article , Titled : How have I managed to generate $1,000 every week in passive income in 2023. This time I will break in parts how I leveraged data science techniques to read and evaluate different asset classes and investment assets to generate passive income. Hence, this paper will be very technical and requires a basic knowledge in the use of python and other Data Science technologies . however , with my approach it should be easy to implement even for non-programming individuals.

There are numerous ways to evaluate stock options prices, however without understand what a stock options are or at best what are the fundamental concept of these complex product, you might actually suffer major losses if you invest without putting risk measurement in place.

Fundamental of Stock Options

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (4)

Let’s start with the obvious , what is Stock options trading, well Stock Options trading is a financial market activity that involves buying and selling contracts that give the holder the right, but not the obligation, to buy or sell a specific underlying stock at a predetermined price (also known as the strike price) within a set period of time.

The contracts can be bought and sold on options exchanges, and the price of the contract is determined by the value of the underlying stock, the strike price, and the amount of time until the contract expires. The main focus of this paper is the use of options contracts to generate income through premiums received by selling them, although investors also engage in stock options trading to speculate on the direction of stock prices or to hedge their investments.

Types of Stock Options

· Buy a call options : These type of stock options contract will gives the holder the right, but not the obligation, to buy a specific underlying asset, such as a stock, at the strike price within a set period of time. When an investor purchases a call option, they are essentially betting that the price of the underlying asset will increase in the future, allowing them to buy it at a lower price than its market value.

· Sell a call options : While Selling a call option is a type of options trading strategy where the trader or investor sells a call option contract to a buyer, which gives the buyer the right, but not the obligation, to buy a specific underlying asset at a specified price (strike price) within a specified period of time. By selling the call option, the seller receives a premium or fee from the buyer.

· Buy a put options : stock option contract that gives the holder the right, but not the obligation, to sell a specific underlying asset, such as a stock, at a predetermined price (known as the strike price) within a set period of time. When an investor purchases a put option, they are essentially betting that the price of the underlying asset will decrease in the future, allowing them to sell it at a higher price than its market value.

· Sell a put options: Selling a put option is a strategy where an investor sells a put contract on an underlying asset, such as a stock, with the expectation that the price of the asset will rise. The seller receives a premium for selling the contract and is obligated to buy the underlying asset at the strike price if the price of the asset falls below the strike price at expiration. This strategy is typically used by investors who are bullish on a particular stock and are willing to buy it at a discounted price if it falls below a certain level. However, there is a risk that the price of the asset may fall significantly, causing the seller to incur a loss.

Variation Stock options

· American-style options, which can be exercised at any time before the expiration date, in my opinion its always safer to have the flexibility to get outta of any trade at anytime , hence this style is the best style to adopt.

· European-style options, which can only be exercised on the expiration date.

· Exotic options, which have more complex terms and conditions than standard options, such as barrier options or binary options.

Each type of option has its own unique characteristics and can be used by investors for different purposes, depending on their investment goals and risk tolerance. So please choose carefully and study these options before you attempt to place any trades in the market.

Criteria for a successful Stock Options trade — key points :

· Open interest

· Traded volume

· Implied volatility

· Stock Options price (DELTA)

· Fundamental story of the stock

· Intuition & instinct

Open interest

Open interest in Stock option trading is the total number of outstanding contracts or positions that have not been settled or closed out by either an offsetting trade or an exercise of the option. In other words, it represents the number of contracts that are still open and active in the market.

For example, if you examine the following snapshot of the open interest for Wallmart stock from Yahoo Finance (which can be accessed through this link: https://finance.yahoo.com/quote/WMT/options?p=WMT), you can easily navigate to the stock dashboard and select the “Options” tab to view it.

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (5)

As you can see there are numerous open interests on many different strike prices , don’t let the table intimidate you , once you understand the flow of it , it will be easy to navigate around it and see what is the most suitable liquidity profile based on your investment objective .

Open interest is particularly important to options traders, as it provides key information regarding the liquidity of an option. A high open interest indicates that a large number of traders have taken active positions in a contract, also used as an indicator of market sentiment, as changes in open interest levels can signal shifts in the balance of supply and demand for a particular option or stock.

Without further ado, let me show you how you can get this data concerning open interest using Python and data science.

Python Implementation

To complete this task you need to install yfinance library on your jupyterlab or any other IDEs of your choosing, you can simply type

“Pip install yfinance”

What is yfinance

Yfinance is a Python library that provides convenient access to the Yahoo Finance API. It allows users to download historical stock data, get real-time stock quotes, and obtain information about stock symbols, such as company name and stock exchange.

Please visit yfinance library link (https://pypi.org/project/yfinance/ ) if you wish to know more about his library, as you can scrap any details about stock from this library.

Also, you need the pandas library, I assume you know about pandas.

Importing libraries

import yfinance as yf
import pandas as pd

To extract historical information using the yfinance API, the first step is to select a stock that you want to analyze. For this I’ve gone with Exxon and Tesla :

exxon = yf.Ticker("XOM")
tesla = yf.Ticker("TSLA")

Populating stock options chain list for these two stocks

# getting options chain table for these scripts
options_exxon = exxon.option_chain()
options_tesla = tesla.option_chain()
options_exxon

Output

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (6)

great , the data looks great , but generally prefer using pandas dataframes to convert these data into a table. I find that this makes the data easier to manipulate and analyze using Python, and it also tends to look cleaner. Hence , let’s use pandas for this.

Using pandas DataFrames

# create a dataframe from the option_chain data
df_calls_exxon = pd.DataFrame(options_exxon.calls)
df_puts_exxon = pd.DataFrame(options_exxon.puts)
df_calls_tesla = pd.DataFrame(options_tesla.calls)
df_puts_tesla = pd.DataFrame(options_tesla.puts)
df_calls_exxon.head(2)

Below is a list of option chain table for calls options concerning exxon

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (7)

Setting a date range to display the open interest for a particular period.

df_calls_2023_exxon = df_calls_exxon[df_calls_exxon['lastTradeDate'] >= '2023-01-01']
df_calls_2023_tesla = df_calls_tesla[df_calls_tesla['lastTradeDate'] >= '2023-01-01']
df_calls_2023_tesla.head(2)

Output

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (8)

displaying end result

print(f'Tesla total open interest in 2023 is {df_calls_2023_tesla["openInterest"].sum():,}')
print(f'Exxon total open interest in 2023 is {df_calls_2023_exxon["openInterest"].sum():,}')

Output

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (9)

As you can see, the total open interest for Tesla since the beginning of the year is significantly larger than that of Exxon. Tesla has a total open interest of 1.2 million, while Exxon has a mere 154,401. This tells us that Tesla has more market participants and more investors interested in the stock, and also indicates that Tesla shares are more liquid than those of Exxon. This is a clear indication that if you open a contract in Tesla, you can likely get out of it as quickly as you bought it, without any hiccups. Hence, the liquidity profile for the stock checks out.

Final thoughts

If you have made it this far reading my paper, then I congratulate you. You are getting closer to understanding this world of capital markets and finance, and hopefully, one day you will be able to make some profit and money for yourself.

In part 2 , I will also explain how to calculate the current volatility of stock performance and traded volume to have a clearer picture of whether the stock at hand offers a better opportunity to open stock options contracts or any other related complex structure contracts.

We still have other criteria items to check to make a final decision for your trade.

Thank you all again. Please join and follow my channel to get notified about Part 2 and the remaining parts, which will leverage Data Science techniques to read the market and hopefully make money in the process once you have understood them. Please connect with me here or add me on LinkedIn and reach out to me.

linkedin: https://www.linkedin.com/in/abdallamahgoub/

How to trade Stock Options using Data Science and AI techniques — Making Passive Income Part 1 (2024)
Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5598

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.