
Article Topics
Financial modelling with Python means building a forecast in code instead of spreadsheet cells. With pandas, a Python library for tables of data, you enter past figures, set assumptions, project cash flow and discount it to a value today. Learn Excel modelling first; Python pays off when you repeat a model or work with large data.
Last updated: 24 November 2026.
A financial model is a chain of calculations. It takes a company's past numbers and your assumptions, and turns them into a forecast and a value. In Excel, the chain lives in cells and formulas. In Python, it lives in short lines of code that you read from top to bottom.
This guide builds a common valuation model, the discounted cash flow (DCF) model. The idea is simple: a business is worth the cash it will produce in future, brought back to today's money. ₹100 that you receive next year is worth less than ₹100 in your hand today, so each future year's cash is reduced, or "discounted".
Python does not change the finance. It changes how you do the work:
Start with Excel. It shows every number on screen, and your manager and clients can open the file. Add Python when you notice that you do the same steps again and again.
| Task | Excel | Python |
|---|---|---|
| One model, one company | Quick to build | More setup |
| Same model, 50 companies | Copy, paste, repeat | One loop |
| Data above the row limit | Must split it | Can load it |
| Sharing with your manager | Opens anywhere | Export to Excel |
| Testing many scenarios | Slow by hand | A short loop |
You do not always have to choose. If your Microsoft 365 plan qualifies, Python in Excel lets you type Python straight into a cell: enter =PY and pick PY from the list that appears. The code runs in Microsoft's cloud and the result comes back to the sheet. You need an internet connection, but no Python on your own computer.
The example is a made-up company with revenue of ₹1,000 lakh (₹10 crore) in FY26. All figures are in ₹ lakh. Type each block into its own cell and run the cells in order.
import pandas as pd
past = pd.DataFrame(
{"revenue": [826, 909, 1000], "ebit": [198, 218, 240]},
index=["FY24", "FY25", "FY26"],
)
past_growth = past["revenue"].pct_change().mean()
past_margin = (past["ebit"] / past["revenue"]).mean()
print(f"Average growth: {past_growth:.1%}")
print(f"Average EBIT margin: {past_margin:.1%}")
It prints an average growth of 10.0% and an average EBIT margin of 24.0%. EBIT is operating profit, meaning earnings before interest and tax. The margin is EBIT as a share of revenue. The past trend is your first guide to the forecast.
For a real company, put its figures in an Excel sheet, with the years in the first column and columns named revenue and ebit. Upload the file to Colab and read it with pandas' read_excel:
past = pd.read_excel("financials.xlsx", index_col=0)
index_col=0 tells pandas to use the first column as row labels. Reading a .xlsx file needs a helper library called openpyxl. If Python says it is missing, run %pip install openpyxl in a new cell.
A variable is a named box that holds a value. Keep every assumption in one cell, so anyone can see and change them in one place.
growth = 0.10 # revenue growth each year
margin = 0.24 # EBIT as a share of revenue
tax_rate = 0.25 # tax on EBIT
reinvest_rate = 0.08 # share of revenue put back into the business
discount_rate = 0.12 # yearly return investors expect
final_growth = 0.04 # growth for ever after the last forecast year
years = 5
The discount rate is the yearly return that lenders and shareholders expect for the risk they take. Analysts often use the company's weighted average cost of capital (WACC), a blend of the two. The tax rate here is only for practice: use the rate that applies to the company you model. Keep the long-term growth rate below the discount rate, or the formula in Step 5 breaks.
model = pd.DataFrame(index=[f"FY{27 + i}" for i in range(years)])
model["year"] = range(1, years + 1)
model["revenue"] = past["revenue"].iloc[-1] * (1 + growth) ** model["year"]
model["ebit"] = model["revenue"] * margin
model["tax"] = model["ebit"] * tax_rate
model["reinvestment"] = model["revenue"] * reinvest_rate
model["fcf"] = model["ebit"] - model["tax"] - model["reinvestment"]
Free cash flow (fcf) is the cash left after tax and after the money the business puts back in to grow, such as new machines and extra stock. To keep the example short, reinvestment here is a fixed 8% of revenue. A full model works out capital spending, depreciation and working capital line by line.
model["discount_factor"] = 1 / (1 + discount_rate) ** model["year"]
model["value_today"] = model["fcf"] * model["discount_factor"]
print(model[["revenue", "fcf", "value_today"]].round(1))
Year 1's cash is divided by 1.12 once, year 2's by 1.12 twice, and so on. The result, rounded:
| Year | Revenue | Free cash flow | Value today |
|---|---|---|---|
| FY27 | 1,100.0 | 110.0 | 98.2 |
| FY28 | 1,210.0 | 121.0 | 96.5 |
| FY29 | 1,331.0 | 133.1 | 94.7 |
| FY30 | 1,464.1 | 146.4 | 93.0 |
| FY31 | 1,610.5 | 161.1 | 91.4 |
The company does not close after FY31. The terminal value stands for all the cash after that year, growing at the long-term rate for ever. Its formula is the last year's cash flow × (1 + long-term growth) ÷ (discount rate − long-term growth).
last_fcf = model["fcf"].iloc[-1]
terminal_value = last_fcf * (1 + final_growth) / (discount_rate - final_growth)
terminal_today = terminal_value * model["discount_factor"].iloc[-1]
five_years = model["value_today"].sum()
enterprise_value = five_years + terminal_today
print(f"Five years of cash flow: ₹{five_years:,.1f} lakh")
print(f"Terminal value today: ₹{terminal_today:,.1f} lakh")
print(f"Enterprise value: ₹{enterprise_value:,.1f} lakh")
This prints ₹473.8 lakh, ₹1,188.0 lakh and ₹1,661.8 lakh. Enterprise value is the value of the whole business. For the value of the shares, subtract debt and add cash. More than two-thirds of this value comes from the terminal value, so your long-term assumptions deserve the hardest look.
This is where Python saves the most time. Put the model in a function, which is a named recipe you can run again with new inputs. Then a loop runs it once for each of three discount rates:
def firm_value(rate, growth=0.10, margin=0.24, tax_rate=0.25,
reinvest_rate=0.08, final_growth=0.04, years=5,
revenue=1000):
total = 0
for year in range(1, years + 1):
revenue = revenue * (1 + growth)
fcf = revenue * margin * (1 - tax_rate) - revenue * reinvest_rate
total = total + fcf / (1 + rate) ** year
terminal = fcf * (1 + final_growth) / (rate - final_growth)
return total + terminal / (1 + rate) ** years
for rate in [0.11, 0.12, 0.13]:
print(f"Discount rate {rate:.0%}: ₹{firm_value(rate):,.1f} lakh")
Discount rate 11%: ₹1,906.6 lakh
Discount rate 12%: ₹1,661.8 lakh
Discount rate 13%: ₹1,471.7 lakh
A change of one percentage point in the discount rate moves the value by about ₹190 lakh to ₹245 lakh. Now try firm_value(0.12, growth=0.08) to see what slower growth does.
Your manager will still want a spreadsheet. pandas' to_excel writes a table to a .xlsx file when you give it just a file name:
model.round(1).to_excel("dcf_model.xlsx")
Download the file from Colab before you leave. Colab deletes the machine your code runs on after it has been idle for a while, and your file goes with it.
They can write a first draft. Colab has AI built in that can generate code, explain it and fix errors. But Google's own Colab FAQ strongly recommends that you test, review and check all code the AI writes before you rely on it.
AI can make finance mistakes that run without any error message: discounting year 1 twice, charging tax on revenue instead of profit, or setting long-term growth above the discount rate. You will spot these only if you understand each step yourself. Let AI help you type faster, and use your own knowledge to check.
It depends on the work you want. As a default, learn them in this order:
Keep your CA exams first. A short daily slot in a lighter phase of articleship, or the weeks after an attempt, is a good time to build this model and then a bigger one. If you want a guided path, see CA Monk's Python for Financial Automation masterclass.
Not for every job. Excel suits a one-off model that a manager will check cell by cell. Python suits work you repeat, models you test under many scenarios and data larger than a worksheet holds. You can use both: Python for the heavy work, then export the result to Excel to share it.
Only the basics: variables, lists, a loop and a function. You can learn these as you go, by typing out small examples like the ones in this guide and changing one number at a time. Your accounting knowledge matters more, because it tells you whether the code's answer makes sense.
Yes, in small steps, as long as your exam study stays on track. Build one small model at a time, using figures from a listed company's published annual report. Never put client data on a personal laptop or into a free online tool without your firm's permission.
No. AI can draft code quickly, but someone still has to read it, test it and spot wrong logic. Google's own Colab FAQ asks you to check AI-written code before relying on it. Knowing both Python and finance is what lets you do that checking well.
Share the notebook. Colab notebooks are stored in Google Drive and can be shared like a Google Doc, so you can put a link in your CV. Add a short note at the top that lists your assumptions, so an interviewer can follow the model in a few minutes.
It is a useful skill if you want roles where you forecast and value businesses, such as valuation, equity research or corporate finance. No skill guarantees a job or a salary, but a model you built yourself gives you something real to discuss in an interview.
For more on using Python in everyday finance work, these posts are a good next read.
Python For Finance Automation

CA MONK Team
CA Career & Learning Platform
CA MONK Team is the team behind CA Monk, India's CA career and learning platform. We help Chartered Accountants and CA aspirants build skills, explore career opportunities, connect with mentors, and navigate their professional journey through courses, mentorship, career tools, placements, and practical industry insights.
Discover 5 powerful Python automations (GST, TDS, audit) CAs should know to streamline CA tasks and boost accuracy.