Skip to content

Instantly share code, notes, and snippets.

@Adobe-Android
Created January 21, 2026 16:46
Show Gist options
  • Select an option

  • Save Adobe-Android/5e4b0be96915d0e56910441a30ce855d to your computer and use it in GitHub Desktop.

Select an option

Save Adobe-Android/5e4b0be96915d0e56910441a30ce855d to your computer and use it in GitHub Desktop.
A tool for understanding and calculating how both forward and reverse stock splits affect the number of shares owned and the price per share
#!/bin/env python3
from enum import Enum
class StockSplit(Enum):
REVERSE = 1
FORWARD = 2
def main():
# Choose StockSplit.REVERSE or StockSplit.FORWARD based on the type of stock split.
stock_split_type = StockSplit.FORWARD
# 2-for-1 forward split
stock_split_type = StockSplit.FORWARD
ratio_starting_shares = 1
ratio_ending_shares = 2
shares_owned_pre_split = 100
share_price_pre_split = 100
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
def stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split):
if stock_split_type == StockSplit.FORWARD:
shares_owned_post_split = shares_owned_pre_split * ratio_ending_shares
share_price_post_split = share_price_pre_split / ratio_ending_shares
print(shares_owned_post_split)
print(share_price_post_split)
print(f"In a {ratio_ending_shares}-for-{ratio_starting_shares} forward split...")
print(f"You started with {shares_owned_pre_split} share(s) at ${share_price_pre_split} and you now have {shares_owned_post_split} share(s) at ${share_price_post_split}")
elif stock_split_type == StockSplit.REVERSE:
split_ratio = ratio_ending_shares / ratio_starting_shares
shares_owned_post_split = split_ratio * shares_owned_pre_split
share_price_post_split = share_price_pre_split * ratio_starting_shares
print(split_ratio)
print(shares_owned_post_split)
print(share_price_post_split)
print(f"In a {ratio_ending_shares}-for-{ratio_starting_shares} reverse split...")
print(f"You started with {shares_owned_pre_split} share(s) at ${share_price_pre_split} and you now have {shares_owned_post_split} share(s) at ${share_price_post_split}")
def test_scenarios():
# https://www.wallstreetprep.com/knowledge/reverse-stock-split/
# 1-for-10 reverse split
stock_split_type = StockSplit.REVERSE
ratio_starting_shares = 10
ratio_ending_shares = 1
shares_owned_pre_split = 200
share_price_pre_split = 0.90
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
# 1-for-8 reverse split
stock_split_type = StockSplit.REVERSE
ratio_starting_shares = 8
ratio_ending_shares = 1
shares_owned_pre_split = 200
share_price_pre_split = 14
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
# https://www.wallstreetprep.com/knowledge/stock-split/
# 2-for-1 forward split
stock_split_type = StockSplit.FORWARD
ratio_starting_shares = 1
ratio_ending_shares = 2
shares_owned_pre_split = 100
share_price_pre_split = 100
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
# 10-for-1 forward split (e.g. Nvidia )
stock_split_type = StockSplit.FORWARD
ratio_starting_shares = 1
ratio_ending_shares = 10
shares_owned_pre_split = 1
share_price_pre_split = 1_258.30
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
# 5-for-1 forward split (e.g. ServiceNow )
stock_split_type = StockSplit.FORWARD
ratio_starting_shares = 1
ratio_ending_shares = 5
shares_owned_pre_split = 1
share_price_pre_split = 813.43
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
# 1-for-5 reverse split
stock_split_type = StockSplit.REVERSE
ratio_starting_shares = 5
ratio_ending_shares = 1
shares_owned_pre_split = 10
share_price_pre_split = 125
stock_split_calc(stock_split_type, ratio_starting_shares, ratio_ending_shares, shares_owned_pre_split, share_price_pre_split)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment