Simulating IPO Stock Data And Finding Optimal Entry/Exit Points

Posted on Wed, Apr 20, 2022 Economics Python Software

Overview

IPOs, or Initial Public Offerings is the process of offering shares of a previously private corporation to the public. On the first 30 days, IPOs have high volatility and therefore, it is difficult to make decisions on when to enter and exit a market, or even enter the market at all. Simple python formulas that can be easily scaled up can be used to find the optimal entry/exit points within a 30 day investment horizon. Optimal entry/exit points are periods within an investment horizon that give the highest profit.

🔗

Check the source code of the program on GitHub. The following details will be based on the code.

Objective

The python program consists of two parts:

  1. Generating Scalable Stock Data
    1. Stock Name, Day, Corresponding Day’s Price.
  2. Finding Entry/Exit Points to maximize profit.

Assumptions:

  1. One cannot exit without entering the market.
  2. One cannot enter and exit on the same day.
  3. The random prices created in the data is an attempt to replicate the random fluctuations of prices of the first few days of an IPO.

Analysis/Observations

When looking at the optimal entry/exit points found by the program:

  1. Entry points are distributed evenly across the 30 day investment horizon.
  2. There was a higher frequency of exit points on the last days.

Generating Stock Data

To generate the basic stock data, the following is needed: the stock name, the number of days, and the stock prices over a certain number of days.

Generating Stock Names and Days

The stock name and the number of days can be a fixed number, however the stock prices have to be random in order to replicate the fluctuations of an IPO. This can be created using an iterative loop in python.

For example, to create a list of stock names use the following code.

#Generates a list of stocks ranging from 1 to 5, including 5.

stock_name = []
for i in range(1,6): #range(start#, END# +1)
  stock_name.append(i)

The above function can be used to create a set number of days as well.

Generating Random Stock Prices

Generating the stock prices over a number of days is different as the prices have to be random on each day. The random numbers can be created using a simple random function, and then can be tweaked to amplify the randomness of the prices. The first one section of the below code shows the simple version of the random function.

#Simple version of random function.

rand_num = []
for y in sp.random.uniform(low = 1, high = 5, size = 1):
    rand_num.append(y)
    
rand_num

#EXAMPLE OUTPUT: [2.6924070800438296]

The function used in the source code nested more random functions within the low and high parameters of the original function to amplify the randomness of the prices.

Visualizations

This is an example of generated optimal entry/exit day points results from the code.

Bar Graph showing the frequency of the optimal entry days.

Bar Graph showing the frequency of the optimal exit days.

🔗

Check the source code of the program on GitHub for all the visualizations and to simulate the data.