Build a Dividend and Portfolio Tracker in Excel With Python (Free Template)
A free Excel template that tracks a dividend portfolio: enter the ticker, the number of shares and your average purchase price, click a button, and a Python script pulls prices, yields and dividend data from Yahoo Finance into the sheet, converted into one currency of your choice.
Use the template
The workbook has one input area per holding: the ticker symbol, the number of shares and your average purchase price. The script fills in the market and dividend data for every row.

The ticker can be anything Yahoo Finance knows, not only US stocks: shares on other exchanges, ETFs, mutual funds, cryptocurrencies, forex pairs and commodity futures. Use the symbol exactly as Yahoo Finance writes it. A ticker Yahoo does not find gets an empty row, and the console names the ticker so you can fix it.
Currencies
A named cell called TARGET_CURRENCY decides the output currency. Enter a currency code such as USD or EUR and every price is converted into it. Enter TICKER CURRENCY and each holding stays in the currency it trades in.
For the conversion, the script looks up the exchange rate on Yahoo Finance as a forex pair (for example EURUSD=X) and multiplies every price by it. The sheet shows the ticker currency and the rate it used next to each holding, so you can check the numbers.

How the script pulls the data
The script reads the ticker column, asks Yahoo Finance for each ticker through the yahoofinancials package, collects the answers in a pandas DataFrame and writes that DataFrame back into the sheet column by column.

For every ticker it builds one row. Each price goes through convert_to_target_currency, which returns None when Yahoo has no value, so a missing field stays empty instead of breaking the run:
new_row = {
"ticker": ticker,
"currency": ticker_currency,
"long_name": long_name,
"conversion_rate": conversion_rate,
"yield_rel": yield_rel,
"exdividend_date": data.get_exdividend_date(),
"payout_ratio": data.get_payout_ratio(),
"open_price": convert_to_target_currency(
open_price, conversion_rate
),
"current_price": convert_to_target_currency(
data.get_current_price(), conversion_rate
),
"daily_low": convert_to_target_currency(
data.get_daily_low(), conversion_rate
),
"daily_high": convert_to_target_currency(
data.get_daily_high(), conversion_rate
),
"yearly_low": convert_to_target_currency(
data.get_yearly_low(), conversion_rate
),
"yearly_high": convert_to_target_currency(
data.get_yearly_high(), conversion_rate
),
"fifty_day_moving_avg": convert_to_target_currency(
data.get_50day_moving_avg(), conversion_rate
),
"twohundred_day_moving_avg": convert_to_target_currency(
data.get_200day_moving_avg(), conversion_rate
),
"dividend_rate": convert_to_target_currency(
data.get_dividend_rate(), conversion_rate
),
}
Before it writes, the script clears the old values, and it stamps the time of the run into a TIMESTAMP cell. If you only need price history rather than dividend data, the shorter route is to export stock data to Excel with yfinance.
Run it from Excel
The button on the sheet calls the Python script through xlwings. The script finds the workbook that called it with xw.Book.caller(), so it always works on the open file and shows a message box when it is done.
The video builds this connection from scratch, starting with the xlwings quickstart project, whose sample button writes a test message into A1. I explain the same setup step by step in my xlwings crash course.


Add or move columns
Two places in portfolio_overview.py decide what lands where. The Column class maps each field to a column number (1 is column A), and the new_row dictionary decides which values the script asks Yahoo Finance for.
To add a field, add a key to new_row with the matching yahoofinancials call, then add the same name to Column with the column number it should go to. To move a field, change only its number in Column. The script clears and writes only the columns listed in Column, so formulas you keep in other columns survive every refresh. For charts on top of the data, see Python charts inserted into Excel.
Setup on a current Python
The requirements.txt in the repository pins versions from 2021 (yahoofinancials 1.6, pandas 1.2.0, xlwings 0.22.2). yahoofinancials 1.6 no longer returns data from Yahoo Finance, and the script uses DataFrame.append, which pandas 2.0 removed.
Install current versions instead of the pinned ones:
pip install --upgrade yahoofinancials xlwings pandas
In my November 2026 test, yahoofinancials 1.20 still returned current prices and dividend yields. With pandas 2, replace the three append lines in pull_stock_data with pd.concat:
# ticker not found or failed: add an empty row
df = pd.concat([df, pd.DataFrame([{}])], ignore_index=True)
# ticker found: add its data
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
If the button reports that RunPython is not defined, Excel cannot find the xlwings add-in. Install it with xlwings addin install and restart Excel.
