Back To Top

July 18, 2024

Estimating Conditional Probability of Price Movements

Probability Of Price Changes Occurring Conditional On Initial Price Changes

Conditional probability helps us understand the likelihood of an event occurring, given that another event has already occurred. In the context of assets prices, this could mean calculating the probability of a price change based on previous movements over a given time horizon.

In this article, we develop a methodology, based on historical asset prices, to calculate the conditional probability of a stock moving in a given direction over a given time horizon, conditional on how it first moved. For instance, let’s say that a stock price just fell 10% in single day. What is the probability that it will fall another 5% over the next day? 

We’ll provide an end-to-end implementation in Python and refer readers to a  Google Colab notebook. Moreover, to simplify the process, Entreprenerdly offers a conditional probability tool to make it easier to implement the analysis without needing to write any code. 

We’ll discuss and implement the followinc concepts:

  • Interactive Distribution Plot with Specified Thresholds
  • Conditional Probabilities Over Time
  • Price Changes Thresholds Combinations

1. Understanding Conditional Probabilities

Conditional probability measures the likelihood of an event occurring, given that another event has already occurred. In mathematical terms, the conditional probability of event given event is denoted as P(A∣B) and is calculated using the formula:

Where:

  • P(A∩B) is the probability of both events and occurring.
  • P(B) is the probability of event occurring.

For instance, in stock price analysis, we might be interested in the probability of a significant price drop occurring within a certain time frame, given that a significant price increase has already taken place.

1.1 Use Cases in Price Analysis

Conditional probabilities have several practical applications in financial market analysis:

  1. Trend Confirmation: By calculating the probability of a price increase following another price increase, traders can confirm the strength of a trend. For example, if stock shows a 10% increase today, we can determine the probability that it will increase by another 5% in the next two days.

  2. Risk Management: Traders can use conditional probability to assess the likelihood of adverse price movements. For instance, they might calculate the probability of a stock dropping by more than 8% within two days, given that it increased by 6% in the previous day. This helps setting stop-loss levels.

  3. Pattern Recognition: By analyzing historical data, traders can identify patterns and calculate the probability of these patterns repeating. For example, if a stock often shows a 5% increase after a 3% drop within a week, this pattern can be used to make trading decisions.

  4. Event-Driven Strategies: Conditional probability can also be used to assess the impact of specific events on stock prices. For example, calculating the probability of a stock’s price dropping after an earnings report can help traders prepare for potential outcomes. Interested readers in this analysis can read the following article or implement it directly using Entreprenerdly’s Earnings Announcement Tool.

Acquiring And Analyzing Earnings Announcements Data In Python

1.2 Institutional Investors

Big financial institutions, like hedge funds and investment banks, use conditional probability to manage vast portfolios and mitigate risks. Imagine a scenario where a hedge fund is monitoring a portfolio of technology stocks. They notice that historically, and test that statistically, a 10% increase in a major tech stock often leads to a 3% decrease within the next three days.

1.3 High-Frequency Trading

High-frequency trading (HFT) firms are another example of entities leveraging conditional probability. These firms execute thousands of trades per second, relying on complex algorithms that factor in conditional probabilities. For instance, an HFT algorithm might detect a pattern where a sudden spike in trading volume for a specific stock is often followed by a price surge. The algorithm calculates the conditional probability of this price surge and executes trades accordingly, aiming to capitalize on these microsecond opportunities.

2. Conditional Probabilities in Python

2.1 Interactive Distribution Plot

Let’s create an interactive distribution plot to analyze conditional probabilities. We create the code so that there are a few key parameters:

  • First Move Change in N Days
  • Second Move Change in N days

First, we need to download historical data for a particular stock. In this example, we’ll use the stock symbol ASML.AS, the semiconductor company.

We then create a function to perform the conditional probability analysis and plot the results.

This function calculates the percentage changes and the frequency of these changes, and it generates visualizations to help us interpret the data interactively (i.e. the plot changes as we change the sliders).

We’ll use the following parameters:

  • first_move_days = 1
  • second_move_days = 2
  • first_threshold_percentage = 0.06 
  • second_threshold_percentage = 0.08

With these parameters, we essentially want to know ‘What is the probability that the stock will move by 8% in 2 days conditional on the stock having moved 6% 1 day prior?’

				
					import yfinance as yf
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from ipywidgets import interact, widgets
import matplotlib.colors as mcolors

# Download historical data for desired stock
symbol = "ASML.AS"
data = yf.download(symbol, start='2000-01-01', end='2025-12-02')

# Initial values for the parameters
initial_first_move_days = 1
initial_second_move_days = 2
initial_first_threshold_percentage = 0.06 # 6%
initial_second_threshold_percentage = 0.08 # 8%

				
			

Also worth reading:

Interactive Stock Price Movement Probabilities With Python

Prev Post

Multi-objective Portfolio Optimization

Next Post

Dynamic Stop-Losses with Bayesian Walk-Forward Optimization

post-bars
Mail Icon

Newsletter

Get Every Weekly Update & Insights

[mc4wp_form id=]

Leave a Comment