HomeGuidesBeta and cost of equity in Excel
Beta and cost of equity in Excel
Work out a stock's beta and its CAPM cost of equity in Excel: load daily prices for the stock and a benchmark fund, take weekly returns, use SLOPE and add the 10 year yield.
dino.markets is a financial data API for apps and AI agents with stocks and ETFs on 42 exchanges, a free plan and paid plans from $29 a month (as of November 2026). This guide works out the beta of one stock against a benchmark fund in Excel and turns it into a cost of equity with the capital asset pricing model (CAPM). It takes three requests: daily prices for the stock, daily prices for the benchmark, and the 10 year government yield. The steps run in Power Query, and the whole calculation fits on one sheet.
The formulas, in the order the guide builds them:
Weekly return = this week's close / last week's close - 1
Beta = SLOPE(stock returns, benchmark returns)
Cost of equity = risk-free rate + beta x equity risk premium
Before you start
- Microsoft 365 for Windows or Mac. Power Query ships with Excel there. Menu names below are for the Windows desktop app.
- A dino.markets API key.
- Each successful request counts against your plan’s monthly limit. Failed requests do not count.
- The Free plan covers the last 12 months of history, which gives about 50 weekly returns. Starter and Basic cover 5 years, and Pro the full history, so you can move the start date back on a larger plan.
What you need to supply
dino.markets gives you prices and the yield. Two inputs are yours.
- The equity risk premium. This is an assumption you supply, and dino.markets does not provide one. Several universities and banks publish estimates each year. Pick a source, note its date, and use the same one for every company you value.
- The benchmark. The sample uses a fund that tracks the US market,
ARCX:SPY. For a company listed elsewhere, use a fund that tracks its own market.
The figures in the sample are for illustration only. The 5.00% premium is an example, not a recommendation.
Get a key
Sign up for the Free plan, which needs no card. Then open keys in the dashboard and create a key. The key will sit inside the workbook, so make one just for it.
Store the key and the dates
Open a new workbook. Choose Data, then Get Data, then Launch Power Query Editor. In the editor, choose Home, then Manage Parameters, then New Parameter, and create three parameters of Type Text:
| Name | Current value |
|---|---|
DinoKey |
Your API key |
StartDate |
The first day, for example 2025-11-17. On the Free plan, keep it inside the last 12 months |
EndDate |
The last day, for example 2026-11-06 |
The workbook stores the key, so do not share the file. Create a key just for it and revoke it in the dashboard when you stop using it. See manage API keys.
Load the daily prices
Choose Home, then New Source, then Blank Query, then Advanced Editor, and replace the code with the query below. Name the query WeeklyPrices.
let
GetWeekly = (path as text) as table =>
let
Source = Json.Document(Web.Contents(
"https://api.dino.markets/v1" & path,
[Headers = [Authorization = "Bearer " & DinoKey], Query = [start = StartDate, end = EndDate]]
)),
AsTable = Table.FromRecords(Source[bars]),
Picked = Table.SelectColumns(AsTable, {"date", "close"}),
Typed = Table.TransformColumnTypes(Picked, {{"date", type date}, {"close", type number}}, "en-US"),
Week = Table.AddColumn(Typed, "week", each Date.StartOfWeek([date], Day.Monday), type date),
Weekly = Table.Group(Week, {"week"}, {{"close", each List.Last([close]), type number}})
in
Weekly,
Stock = Table.RenameColumns(GetWeekly("/equities/XNAS:MSFT/bars"), {{"close", "stock"}}),
Fund = Table.RenameColumns(GetWeekly("/funds/ARCX:SPY/bars"), {{"week", "week_fund"}, {"close", "benchmark"}}),
Joined = Table.Join(Stock, "week", Fund, "week_fund", JoinKind.Inner),
Sorted = Table.Sort(Table.RemoveColumns(Joined, {"week_fund"}), {{"week", Order.Ascending}}),
WithPrevious = Table.FromColumns(
{Sorted[week], Sorted[stock], Sorted[benchmark],
{null} & List.RemoveLastN(Sorted[stock], 1), {null} & List.RemoveLastN(Sorted[benchmark], 1)},
{"week", "stock", "benchmark", "prev_stock", "prev_benchmark"}
),
StockReturn = Table.AddColumn(WithPrevious, "stock_return", each [stock] / [prev_stock] - 1, type number),
BenchmarkReturn = Table.AddColumn(StockReturn, "benchmark_return", each [benchmark] / [prev_benchmark] - 1, type number),
Result = Table.RemoveColumns(Table.Skip(BenchmarkReturn, 1), {"prev_stock", "prev_benchmark"})
in
Result
The function calls GET /v1/equities/{id}/bars for the stock and GET /v1/funds/{id}/bars for the fund. Both are daily bars by default, oldest first, adjusted for splits and dividends. Each bar has a date and a close, written as decimal strings.
Example response, trimmed to two bars and to the date and close fields the query uses (each bar also has timestamp, open, high, low and volume):
{
"id": "XNAS:MSFT",
"currency": "USD",
"adjusted": true,
"bars": [
{ "date": "2026-11-05", "close": "535.93" },
{ "date": "2026-11-06", "close": "530.61" }
],
"next_cursor": null
}
A page holds up to 5,000 bars, so two years of daily bars fits in one call for each instrument.
To use another stock, change the id in the Stock line. A bare US ticker such as MSFT also works. If you do not know the id, search for it with GET /v1/equities/search?q=micro.
Weekly closes and returns
The query groups the daily bars by week, from Monday, and keeps the last close of each week. A week with a market holiday uses the last trading day. It then matches the stock and the fund by week, sorts the weeks oldest first, and works out each week’s return as this week’s close divided by last week’s close, minus 1. The first week has no week before it, so the query drops it.
Choose Close and Load. The sheet shows a table named WeeklyPrices with five columns: week, stock, benchmark, stock_return and benchmark_return. Format the two return columns as percentages. Weekly returns use fewer points than daily ones, which keeps differences in trading hours between markets from distorting a beta.
The table grows and shrinks with the dates you ask for, so the formulas below use its column names and need no row numbers.
Beta
Beta is the slope of the stock’s returns against the benchmark’s returns. The result goes in the summary block next to the table (see Cost of equity). The formula is:
=SLOPE(WeeklyPrices[stock_return], WeeklyPrices[benchmark_return])
The stock returns come first, as known_y's, and the benchmark returns second, as known_x's.
Risk-free rate
Use the 10 year government yield as the risk-free rate. Open a second blank query, name it RiskFree, and replace the code with this.
let
Source = Json.Document(Web.Contents(
"https://api.dino.markets/v1/economics/USA/yield-curve",
[Headers = [Authorization = "Bearer " & DinoKey], Query = [maturity = "10y"]]
)),
TenYear = Number.FromText(Source[yields]{0}[yield_percent], "en-US") / 100
in
#table({"risk_free"}, {{TenYear}})
The call is GET /v1/economics/{country}/yield-curve. The maturity parameter returns one point of the curve, and the response always holds a yields array. The value is a decimal string in percent, so the query divides it by 100.
Example response from 13 November 2026:
{
"country": "USA",
"curve_type": "nominal_par",
"date": "2026-11-12",
"yields": [
{ "maturity": "10y", "tenor": "P10Y", "yield_percent": "5.10" }
]
}
Without a date, the call returns the latest curve. To use the yield on your valuation date, add date = "2026-09-30" to the Query record. On the Free plan, a date older than 12 months is refused with 403 plan_upgrade_required, and a plan with longer history lifts that limit.
Yield curves are available for the US, the UK, Germany, Japan, Canada, Sweden, Norway, Australia and the euro area. For a company priced in another currency, use the curve of the country whose currency your cash flows use.
Cost of equity
Choose Close and Load again. Then set up the summary block in columns G and H, to the right of the table, with the labels in G and the values in H.
G1: Risk-free rate H1: =RiskFree[risk_free]
G2: Equity risk premium H2: 0.05
G3: Beta H3: =SLOPE(WeeklyPrices[stock_return], WeeklyPrices[benchmark_return])
G4: Cost of equity H4: =H1+H3*H2
The value in H2 is your assumption, so type your own. As an example, with a risk-free rate of 5.10%, a beta of 1.45 and a premium of 5.00%, the cost of equity is 5.10% + 1.45 x 5.00% = 12.35%.
Check the result
- Test the sheet by setting the stock to the benchmark fund as well. A fund’s beta against itself is exactly 1.
- Count the returns with
=COUNT(WeeklyPrices[stock_return]). A beta from about 100 weekly returns is steadier than one from 50, and a standard error you compute withLINESTshows how wide the range is. - A beta describes the past. A different period, a different benchmark or daily returns give a different number, so write down the choices you made next to the result.
- The dates must cover the same weeks for both prices. The join keeps only the weeks the two have in common.
Cost and limits
- Three requests make one company: stock prices, benchmark prices and the yield.
- Each refresh repeats all three requests. Use Refresh All only when you want new numbers.
- For several companies, add one
Stockline per company. The benchmark and the yield are the same for all of them, so ten companies use 12 requests. - The Free plan has 3,000 successful requests a month and 12 months of history.
Handle errors
Errors come back as problem JSON with a code. Read the errors guide for the full list. In Excel, a failed call shows as a Web.Contents error with the status.
| Status | Code | What to do |
|---|---|---|
| 401 | unauthenticated |
The key is wrong or revoked. Replace the DinoKey parameter. |
| 429 | See code |
You reached the per-minute limit or the monthly limit of your plan. Wait, or change plan. |
For a price call you may also see 404 not_found for an id that matches no listing, and 404 not_covered when an exchange has no prices yet. On the Free plan, a StartDate older than 12 months is moved up to the start of that window, so you get fewer weeks and no error. If the EndDate is also older than the window, the call is refused with 403 plan_upgrade_required. A plan with longer history gives you the full range.
Common questions
How many requests does a beta take
Three requests: the stock, the benchmark and the 10 year yield. Failed requests do not count.
Which equity risk premium should I use
That is an assumption you supply, and dino.markets does not provide one. Several universities and banks publish estimates each year. Choose one, note its date, and keep it the same across your valuations.
Why weekly returns
Weekly returns are a common choice for a beta, and they are less noisy than daily ones. You can change the query to group by month, or skip the grouping and use daily returns.
Can I use a different benchmark
Yes. Replace the fund id in the `Fund` line with the fund that tracks the market you want. The benchmark should match the market the company is listed in.
Can I do this in Python
Yes. The same three calls work with any language. See stock prices in Python for the request pattern.
Next steps
- Browse every endpoint in the stocks and funds reference and the economics reference.
- New to Power Query? Read stock prices in Excel.
- Convert the figures into your reporting currency with the exchange rates guide.
Next steps
Start with a free key
3,000 requests a month, no card needed.