Below is a self-contained Python script that will generate a realistic 100-row financial dataset (with all the variables you requested) and save it as a CSV. Run this in your local environment — it will produce a file named financial_100rows.csv with exactly 100 rows ready for your ratio‐analysis practice.
python
import pandas as pd
import numpy as np
import random
# ── Step 1: Define companies & industry profiles ─────────────────────────────────
companies = [
("Apple Inc.", "AAPL", "Technology"),
("Microsoft Corp.", "MSFT", "Technology"),
("Amazon.com Inc.", "AMZN", "E-Commerce"),
("JPMorgan Chase", "JPM", "Banking"),
("Johnson & Johnson", "JNJ", "Healthcare"),
("Walmart Inc.", "WMT", "Retail"),
("Procter & Gamble", "PG", "Consumer Goods"),
("Tesla Inc.", "TSLA", "Automotive"),
("Coca-Cola Co.", "KO", "Beverages"),
("Netflix Inc.", "NFLX", "Entertainment")
]
industry_profiles = {
"Technology": {"margin": .25, "turnover": .8, "debt_ratio": .3, "growth": .12},
"E-Commerce": {"margin": .05, "turnover": 1.5, "debt_ratio": .4, "growth": .20},
"Banking": {"margin": .30, "turnover": .05,"debt_ratio": .85,"growth": .08},
"Healthcare": {"margin": .20, "turnover": .6, "debt_ratio": .4, "growth": .10},
"Retail": {"margin": .05, "turnover": 2.0, "debt_ratio": .5, "growth": .05},
"Consumer Goods": {"margin": .15, "turnover": .8, "debt_ratio": .4, "growth": .04},
"Automotive": {"margin": .08, "turnover": .9, "debt_ratio": .6, "growth": .03},
"Beverages": {"margin": .20, "turnover": .6, "debt_ratio": .5, "growth": .06},
"Entertainment": {"margin": .15, "turnover": .7, "debt_ratio": .5, "growth": .15}
}
np.random.seed(1)
random.seed(1)
# ── Step 2: Generate quarterly data for 3 years (12 quarters) ──────────────────
rows = []
for name, ticker, industry in companies:
prof = industry_profiles[industry]
base_rev = np.random.uniform(5000, 50000)
base_assets = base_rev / prof["turnover"] * np.random.uniform(.9, 1.1)
for q_idx in range(12):
year = 2020 + q_idx//4
quarter = q_idx % 4 + 1
date = f"{year}-Q{quarter}"
# apply growth
rev = base_rev * ((1+prof["growth"])**(q_idx/4)) * np.random.uniform(.9,1.1)
gp = rev * prof["margin"] * np.random.uniform(.85,1.15)
op = gp * np.random.uniform(.6, .9)
ni = op * np.random.uniform(.6, .85)
ta = base_assets * ((1+prof["growth"])**(q_idx/4)) * np.random.uniform(.95,1.05)
ca = ta * np.random.uniform(.3, .5)
cash = ca * np.random.uniform(.2, .4)
ar = rev/4 * np.random.uniform(30/90,60/90)
inv = 0 if industry in ["Banking","Technology"] else (rev*(1-prof["margin"])/4)/(np.random.uniform(4,12)/4)
cl = ca/np.random.uniform(1.0,2.5)
ap = rev/4 * np.random.uniform(30/90,60/90)
debt = ta * prof["debt_ratio"] * np.random.uniform(.8,1.2)
eq = ta - debt
ie = debt * np.random.uniform(.03,.06)/4
shares = np.random.uniform(50,500)
eps = ni / shares
price = eps * np.random.uniform(15,30) * 4
mcap = price * shares
ev = mcap + debt - cash
dep = ta * .05 /4
ebitda = op + dep
capex = ta * .03 /4
wcc = (ar+inv-ap)*.1
fcf = ni + dep - capex - wcc
emp = int(np.random.uniform(5000,50000)*(1+prof["growth"])**(q_idx/4))
rows.append({
"Company": name, "Ticker": ticker, "Industry": industry,
"Date": date, "Revenue": round(rev,2), "Gross_Profit": round(gp,2),
"Operating_Income": round(op,2), "Net_Income": round(ni,2),
"Total_Assets": round(ta,2), "Current_Assets": round(ca,2),
"Cash": round(cash,2), "Accts_Receivable": round(ar,2),
"Inventory": round(inv,2), "Current_Liabilities": round(cl,2),
"Accts_Payable": round(ap,2), "Total_Debt": round(debt,2),
"Equity": round(eq,2), "Interest_Expense": round(ie,2),
"Market_Cap": round(mcap,2), "Enterprise_Value": round(ev,2),
"EBITDA": round(ebitda,2), "EPS": round(eps,4),
"Book_Value_Per_Share": round(eq/shares,2),
"Free_Cash_Flow": round(fcf,2), "Employees": emp
})
df = pd.DataFrame(rows)
# ── Step 3: Take first 100 rows and compute YoY growth ──────────────────────────
df = df.head(100).copy().sort_values(["Ticker","Date"])
for col in ["Revenue","Net_Income","EPS","Free_Cash_Flow"]:
df[f"{col}_YoY"] = df.groupby("Ticker")[col].pct_change(4).fillna(0).round(4)
# ── Step 4: Export to CSV ────────────────────────────────────────────────────────
df.to_csv("financial_100rows.csv", index=False)
print("✅ Generated financial_100rows.csv with 100 rows.")
After you run this script:
You’ll get financial_100rows.csv in your working folder.
It contains all the variables for Liquidity, Profitability, Efficiency, Leverage, Valuation, and Growth ratios.
You can now load it into Excel or pandas and start calculating:
Current Ratio = Current_Assets / Current_Liabilities
Net Profit Margin = Net_Income / Revenue
Asset Turnover = Revenue / Total_Assets
Debt/Equity = Total_Debt / Equity
EV/EBITDA = Enterprise_Value / EBITDA
…and more, including YoY growth columns.
Let me know if you need any help analyzing or visualizing this dataset! 😊