Energy project economics
Energy project economics
Purpose
Build an Excel economics model for one energy asset: inputs, yearly cash flow, results (LCOE, NPV, IRR, payback), sensitivity. Every result is a formula, so one changed input updates everything.
The AI does not invent assumptions. A value the user did not give goes in as an example marked "Hypothetical [source needed]", and its results are never presented as a real business case.
Input
- Required: asset type and capacity with unit. If missing, ask only: "What is the asset and its capacity (kW or kWp)?"
- Helpful: yield, degradation, life, capex, O&M, replacement cost, price, discount rate, inflation, sources.
- Nominal or real discount rate unclear: ask; with no answer, treat it as nominal and say so.
- DC (kWp) or AC (kW) capacity unclear: ask. Yield and capacity factor use the same basis.
- If your school or instructor gave you a template or set formulas, those come first.
Output
1. `make_energy.py` and `energy_economics.xlsx`: sheets `Inputs`, `Cash flow`, `Results`, `Sensitivity`, two charts.
2. In the chat, "Points to check", 3–7 lines: LCOE, NPV, IRR, paybacks, whether sensitivity flips the verdict, unsourced inputs, cross-checks.
3. If Python cannot run here, give the script and no result numbers, or label them "hand estimate".
Rules
1. Steps
1) Enter assumptions in `INPUTS`, each with unit and source.
2) Run `python make_energy.py`; open the file.
3) Read the `Results` cross-checks first. Not four "Same"? Find the cause before using any result.
4) Tag every reported number with its basis (real 2026 KRW, rate, life).
2. Sheets
- `Inputs`: name, item, value, unit, source, definition. Only value cells are blue.
- Formulas use names, not addresses: `=B6*cap_kWp*yield1*(1-degr)^(A6-1)`.
- Each sheet prints on one A4 landscape page.
3. Definitions
- Real rate r = (1 + nominal) ÷ (1 + inflation) − 1. 6 % and 2 % give 3.92 %, not 4 %.
- LCOE = Σ costₜ/(1+r)ᵗ ÷ Σ energyₜ/(1+r)ᵗ, t = 0…N. Energy is discounted too.
- NPV = Σ net cash flowₜ/(1+r)ᵗ, t = 0…N, year-0 capex included.
- Excel `NPV()` discounts its first value one year: `=NPV(r, years 1…N) + year 0`.
- IRR of real flows is real. Nominal IRR = (1 + real)(1 + inflation) − 1.
- Payback: first year t with cumulative ≥ 0, then (t − 1) + |cumulativeₜ₋₁| ÷ net cash flowₜ.
- Capacity factor = year-1 energy ÷ (capacity × 8,760 h); on DC capacity, write "DC basis".
4. Real and nominal
- Real flows (2026 KRW) take the real rate, nominal flows the nominal rate; both NPVs match.
- Mixing is wrong: in the hypothetical case, nominal flows at the real rate inflate NPV by 39.33 million KRW (the "Wrong" row).
- Input prices are real; convert a nominal price to the base year.
5. Units
- Energy in kWh; MWh once, on `Results` (÷ 1,000).
- Never mix kW and kWh. Yield is kWh/kWp·yr, O&M KRW/kWp·yr.
- Only chart axes show millions of KRW, and say so.
- An input with a blank unit is not used.
6. Sensitivity
- Nominal rate and capex at 80–120 % of base (`step` = 10 %).
- No Excel Data Table (What-If); every cell is a formula. Google Sheets has no Data Table.
- Hypothetical case: NPV < 0 in 8 of 25 cells; LCOE exceeds the value of electricity in the same 8.
- The base cell must equal NPV on `Results` (cross-checked).
7. Result sentences (before → after)
- "LCOE is 105 won, so it is economical." → "LCOE is 105.0 KRW/kWh (real 2026 KRW, real rate 3.92 %, 25 years), below the 110 KRW/kWh value of electricity."
- "NPV is 9.44 million won, so it is worth it." → "NPV is 9.44 million KRW; 10 % higher capex makes it −5.56 million KRW and flips the verdict."
- "Payback is 15 years." → "Simple payback 15.0 years, discounted 22.5 years (25-year life)."
- Results from unsourced inputs carry "(input sources needed)".
8. The file
Run end to end on a hypothetical case: 100 kWp campus rooftop PV, all inputs hypothetical. For another asset, change only `INPUTS`. Needs `pip install openpyxl`.
- Results: LCOE 105.0 KRW/kWh, NPV 9,444,346 KRW, IRR 4.53 % real / 6.62 % nominal, payback 15.0 / 22.5 years, capacity factor 14.3 % (DC).
- LibreOffice-recalculated values matched a separate numpy run, all 50 sensitivity cells included.
9. Final check
- Four cross-checks "Same", only the wrong example "Differs".
- Every input has unit and source; `[source needed]` stays on hypothetical values.
- Real rate by division; LCOE denominator discounted; year 0 outside `NPV()`.
- MWh only on `Results`; no `#NUM!`, `#DIV/0!`, `#NAME?`.
- You said whether you ran the script or only wrote it.
Attachment 1 · make_energy.py (Python)
```python
make_energy.py - rooftop PV economics workbook. Run: python make_energy.py -> energy_economics.xlsx
Inputs and calculations on separate sheets; every result is an Excel formula. Money and discount
rate are real (2026 KRW). Energy in kWh; MWh only on Results.
import sys
from openpyxl import Workbook
from openpyxl.chart import LineChart, Reference, Series
from openpyxl.chart.series import SeriesLabel, StrRef
from openpyxl.formatting.rule import FormulaRule
from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
from openpyxl.workbook.defined_name import DefinedName
from openpyxl.worksheet.datavalidation import DataValidation
SRC = "Hypothetical [source needed]"
1) Inputs (hypothetical). String = section title; tuple = (name, item, value, unit, format, note).
Formulas use the names directly.
INPUTS = [
"Plant",
("cap_kWp", "Capacity", 100, "kWp (DC)", "#,##0", "Sum of module ratings; capacity factor uses this"),
("yield1", "Year-1 specific yield", 1250, "kWh/kWp·yr", "#,##0", "At the AC meter (after inverter)"),
("degr", "Degradation", 0.005, "/yr", "0.00%", "Year-t energy = cap × yield × (1 − degr)^(t − 1)"),
("life", "Operating life", 25, "yr", "0", "1 to 30 (cash flow sheet ends at year 30)"),
"Costs (real, 2026 KRW)",
("capex_kWp", "Installed cost", 1500000, "KRW/kWp", "#,##0", "Once, in year 0 (2026)"),
("om_kWp", "Fixed O&M", 25000, "KRW/kWp·yr", "#,##0", "Year 1 to end of life, flat real"),
("inv_kWp", "Inverter replacement", 120000, "KRW/kWp", "#,##0", "Once, in the replacement year"),
("inv_year", "Inverter replacement year", 13, "year", "0", "None if after end of life"),
"Revenue (real, 2026 KRW)",
("p_kWh", "Value of electricity", 110, "KRW/kWh", "#,##0", "Sale or avoided purchase price, flat real"),
"Discounting",
("i_nom", "Nominal discount rate", 0.06, "/yr", "0.00%", "Only for nominal cash flows"),
("infl", "Inflation", 0.02, "/yr", "0.00%", "Real rate r = (1 + nominal) ÷ (1 + inflation) − 1"),
"Sensitivity",
("step", "Sensitivity step", 0.10, "of base", "0%", "±2 steps (±20 %) on nominal rate and capex"),
]
MONEY = "#,##0;[Red]-#,##0"
CF, R0, TMAX = "'Cash flow'!", 5, 30 # year 0 on row 5, up to year 30
R1, RS = R0 + TMAX, R0 + TMAX + 1 # last year row, total row
2) Cash flow columns from B: (header, unit, year-0 formula, year-1+ formula, format, width,
total). {r} = this row, {p} = row above
COLS = [
("Running", "1/0", "=IF(AND(A{r}>=1,A{r}<=life),1,0)", None, "0", 7, False),
("Energy", "kWh", "=B{r}*cap_kWp*yield1*(1-degr)^(A{r}-1)", None, "#,##0", 10, True),
("Revenue", "KRW", "=C{r}*p_kWh", None, MONEY, 12, True),
("Capex", "KRW", "=IF(A{r}=0,cap_kWp*capex_kWp,0)", None, MONEY, 12, True),
("O&M", "KRW", "=B{r}*cap_kWp*om_kWp", None, MONEY, 11, True),
("Inverter", "KRW", "=IF(AND(A{r}=inv_year,B{r}=1),cap_kWp*inv_kWp,0)", None, MONEY, 11, True),
("Total cost", "KRW", "=E{r}+F{r}+G{r}", None, MONEY, 12, True),
("Net cash flow", "KRW", "=D{r}-H{r}", None, MONEY, 12, True),
("Cumulative", "KRW", "=I{r}", "=J{p}+I{r}", MONEY, 13, False),
("Disc. factor", "1/(1+r)^t", "=1/(1+r_real)^A{r}", None, "0.0000", 9, False),
("Disc. energy", "kWh", "=C{r}*K{r}", None, "#,##0", 10, True),
("Disc. cost", "KRW", "=H{r}*K{r}", None, MONEY, 12, True),
("Disc. net CF", "KRW", "=I{r}*K{r}", None, MONEY, 12, True),
("Disc. cumul.", "KRW", "=N{r}", "=O{p}+N{r}", MONEY, 13, False),
("Payback", "yr (interp.)", "", '=IF(AND(J{p}<0,J{r}>=0),A{p}-J{p}/I{r},"")', "0.00", 9, False),
("Disc. payback", "yr (interp.)", "", '=IF(AND(O{p}<0,O{r}>=0),A{p}-O{p}/N{r},"")', "0.00", 9, False),
]
K = [-2, -1, 0, 1, 2] # sensitivity steps: base × (1 + k × step)
FONT, BLUE = "Calibri", "0000FF"
LINE = Side(style="thin", color="BFBFBF")
FILL = {"head": "E7E6E6", "input": "FFF9E5", "sec": "DDEBF7", "bad": "F8D7DA"}
def put(ws, ref, v, color="000000", bold=False, fill=None, fmt=None, size=10, wrap=True):
if ":" in ref:
ws.merge_cells(ref)
ref = ref.split(":")[0]
c = ws[ref]
c.value = v
c.font = Font(name=FONT, size=size, bold=bold, color=color)
c.alignment = Alignment(wrap_text=wrap, vertical="center")
c.border = Border(left=LINE, right=LINE, top=LINE, bottom=LINE)
if fill:
c.fill = PatternFill("solid", fgColor=FILL[fill])
if fmt:
c.number_format = fmt
def setup(ws, area, widths): # widths, print area, A4 landscape, one page
for i, w in enumerate(widths):
ws.column_dimensions[chr(65 + i)].width = w
ws.print_area = area
ws.page_setup.orientation = "landscape"
ws.page_setup.paperSize = ws.PAPERSIZE_A4
ws.page_setup.fitToWidth = ws.page_setup.fitToHeight = 1
ws.sheet_properties.pageSetUpPr.fitToPage = True
ws.print_options.horizontalCentered = True
ws.oddFooter.center.text = "&A · &P / &N"
def name(wb, n, ref):
wb.defined_names[n] = DefinedName(n, attr_text=ref)
def rng(col): # one column of the cash flow sheet, years 0 to 30
return f"{CF}${col}${R0}:${col}${R1}"
def chart(title, ytitle, xtitle, anchor, ws, series, dashes, legend="b"):
ch = LineChart()
ch.title, ch.width, ch.height = title, 17, 10
ch.y_axis.title, ch.x_axis.title, ch.y_axis.numFmt = ytitle, xtitle, "#,##0,,"
ch.x_axis.delete = ch.y_axis.delete = False
ch.x_axis.tickLblPos = "low" # labels below the plot, not on the zero line
ch.legend.position = legend
for s, dash in zip(series, dashes):
s.graphicalProperties.line.dashStyle = dash # color is not the only cue
s.graphicalProperties.line.width = 22000
s.smooth = False
ch.series.append(s)
ws.add_chart(ch, anchor)
return ch
def build(out):
wb = Workbook()
a = wb.active
a.title = "Inputs"
setup(a, f"A1:F{len(INPUTS) + 3}", [12, 24, 13, 13, 28, 54])
put(a, "A1:F1", "Inputs - hypothetical case: 100 kWp campus rooftop PV. All values are hypothetical; "
"replace with real values and sources", bold=True, size=13)
put(a, "A2:F2", "Edit only the blue cells. Year 0 = 2026, money in real 2026 KRW. "
"Formulas use the names in column A.", color="595959")
for j, h in enumerate(["Name", "Item", "Value", "Unit", "Source", "Definition / note"]):
put(a, f"{chr(65 + j)}3", h, bold=True, fill="head")
for i, x in enumerate(INPUTS):
r = 4 + i
if isinstance(x, str):
put(a, f"A{r}:F{r}", x, bold=True, fill="sec")
continue
n, label, v, unit, fmt, memo = x
row = [(n, "595959", None, None), (label, None, None, None), (v, BLUE, "input", fmt),
(unit, None, None, None), (SRC, "595959", None, None), (memo, None, None, None)]
for j, (val, color, fill, f) in enumerate(row):
put(a, f"{chr(65 + j)}{r}", val, color or "000000", fill=fill, fmt=f)
name(wb, n, f"'Inputs'!$C${r}")
if n == "life":
dv = DataValidation(type="whole", operator="between", formula1="1", formula2=str(TMAX))
a.add_data_validation(dv)
dv.add(f"C{r}")
c = wb.create_sheet("Cash flow")
setup(c, f"A1:Q{RS}", [6] + [x[5] for x in COLS])
put(c, "A1:Q1", "Cash flow - real 2026 KRW, year 0 = 2026. Energy in kWh, money in KRW", bold=True, size=13)
put(c, "A2:C2", "Real discount rate r", bold=True)
put(c, "D2", "=(1+i_nom)/(1+infl)-1", bold=True, fmt="0.00%")
name(wb, "r_real", f"{CF}$D$2")
put(c, "E2:Q2", "r = (1 + nominal) ÷ (1 + inflation) − 1. Real cash flows take the real rate only. "
"Grey rows: outside the life.", color="595959")
put(c, "A3", "Year t", bold=True, fill="head")
put(c, "A4", "year", fill="head")
for j, (h, unit, f0, f1, fmt, w, tot) in enumerate(COLS):
col = chr(66 + j)
put(c, f"{col}3", h, bold=True, fill="head")
put(c, f"{col}4", unit, fill="head")
for t in range(TMAX + 1):
r = R0 + t
f = f0 if t == 0 else (f1 or f0)
put(c, f"{col}{r}", f.format(r=r, p=r - 1) if f else None, fmt=fmt)
put(c, f"{col}{RS}", f"=SUM({col}{R0}:{col}{R1})" if tot else None, bold=True, fill="head", fmt=fmt)
for t in range(TMAX + 1):
put(c, f"A{R0 + t}", t, fmt="0")
put(c, f"A{RS}", "Total", bold=True, fill="head")
c.conditional_formatting.add(f"A{R0 + 1}:Q{R1}", FormulaRule(formula=[f"$B{R0 + 1}=0"], font=Font(color="A6A6A6")))
c.freeze_panes = f"B{R0}"
s = wb.create_sheet("Results")
setup(s, "A1:P22", [27, 17, 14, 50])
put(s, "A1:P1", "Results - hypothetical 100 kWp campus rooftop PV (all inputs hypothetical)", bold=True, size=13)
put(s, "A2:D2", "Real 2026 KRW, discounted at real r. N = operating life. All values are formulas.",
color="595959")
for j, h in enumerate(["Metric", "Value", "Unit", "Definition (formula)"]):
put(s, f"{chr(65 + j)}3", h, bold=True, fill="head")
first, total = f"{CF}C{R0 + 1}", f"{CF}C{RS}"
results = [
("LCOE", f"={CF}M{RS}/{CF}L{RS}", "KRW/kWh (real)", "#,##0.0", "Σ cost_t/(1+r)^t ÷ Σ energy_t/(1+r)^t, t = 0…N"),
("NPV", f"={CF}N{RS}", "KRW (real)", MONEY, "Σ net CF_t/(1+r)^t, t = 0…N, including year-0 capex"),
("IRR (real)", f'=IFERROR(IRR({rng("I")}),"none")', "/yr", "0.00%", "Real discount rate at which NPV = 0"),
("IRR (nominal)", '=IFERROR((1+B6)*(1+infl)-1,"none")', "/yr", "0.00%", "(1 + real IRR) × (1 + inflation) − 1"),
("Simple payback", f'=IF(COUNT({rng("P")})=0,"not within life",MIN({rng("P")}))', "yr", "0.0",
"Cumulative net CF first ≥ 0; linear within the year"),
("Discounted payback", f'=IF(COUNT({rng("Q")})=0,"not within life",MIN({rng("Q")}))', "yr", "0.0",
"Discounted cumulative first ≥ 0"),
("Year-1 energy", f"={first}/1000", "MWh", "#,##0.0", "kWh ÷ 1,000 (MWh on this sheet only)"),
("Lifetime energy", f"={total}/1000", "MWh", "#,##0", "With degradation, undiscounted"),
("Capacity factor (yr 1)", f"={first}/(cap_kWp*8760)", "on DC capacity", "0.0%", "Year-1 energy ÷ (capacity × 8,760 h)"),
]
for i, (label, f, unit, fmt, memo) in enumerate(results):
r = 4 + i
put(s, f"A{r}", label, bold=True)
put(s, f"B{r}", f, bold=True, fmt=fmt, size=11)
put(s, f"C{r}", unit)
put(s, f"D{r}", memo, color="595959")
put(s, "A13", "Verdict", bold=True)
put(s, "B13:D13", '=IF(B5>0,"NPV > 0: capex recovered at real rate "&TEXT(r_real,"0.00%"),'
'"NPV <= 0: capex not recovered")&". LCOE "&TEXT(B4,"#,##0.0")&" KRW/kWh, value "&p_kWh&" KRW/kWh"', bold=True)
for j, h in enumerate(["Cross-check", "Value (KRW)", "Diff. from NPV", "Verdict · note"]):
put(s, f"{chr(65 + j)}15", h, bold=True, fill="head")
checks = [
("Excel NPV() function", f"=NPV(r_real,{CF}I{R0 + 1}:I{R1})+{CF}I{R0}", "NPV() discounts its first value; add year 0 outside"),
("Nominal CF at nominal rate", f"=SUMPRODUCT({rng('I')}*(1+infl)^{rng('A')}/(1+i_nom)^{rng('A')})", "Real with real, nominal with nominal"),
("(Wrong) nominal CF at real rate", f"=SUMPRODUCT({rng('I')}*(1+infl)^{rng('A')}/(1+r_real)^{rng('A')})", "Mixing inflates NPV this much. Never use"),
("(Value − LCOE) × disc. energy", f"=(p_kWh-B4)*{CF}L{RS}", "Equals NPV when value is flat real"),
("Sensitivity base cell", "='Sensitivity'!E8", "Rate and capex at 100 %"),
]
for i, (label, f, memo) in enumerate(checks):
r = 16 + i
put(s, f"A{r}", label)
put(s, f"B{r}", f, fmt=MONEY)
put(s, f"C{r}", f"=B{r}-$B$5", fmt="#,##0.00;[Red]-#,##0.00")
put(s, f"D{r}", f'=IF(ABS(C{r})<1,"Same. ","Differs. ")&"{memo}"', color="595959")
put(s, "A22:D22", "Four rows 'Same', only the wrong example 'Differs': the model follows the definitions.",
color="595959")
chart("Cumulative net cash flow · real", "million KRW · 2026 KRW", "Year t", "F3", s,
[Series(Reference(c, min_col=col, min_row=R0, max_row=R1), title=title) for col, title in ((10, "Simple"), (15, "Discounted"))],
["solid", "dash"]).set_categories(Reference(c, min_col=1, min_row=R0, max_row=R1))
m = wb.create_sheet("Sensitivity")
setup(m, "A1:T24", [12, 12, 15, 15, 15, 15, 15, 26])
put(m, "A1:T1", "Sensitivity - nominal rate and capex at ±20 % of base, 10 % steps (hypothetical case)",
bold=True, size=13)
put(m, "A2:H2", "The nominal rate is varied, then made real. All numbers are formulas. "
"Red cell = verdict flips.", color="595959")
npv = "=SUMPRODUCT(({D}-{F}-{G})/(1+$B{r})^{A})-(1+({k})*step)*{CF}$E${R0}"
lcoe = "=((1+({k})*step)*{CF}$E${R0}+SUMPRODUCT(({F}+{G})/(1+$B{r})^{A}))/SUMPRODUCT({C}/(1+$B{r})^{A})"
ref = {x: rng(x) for x in "ACDFG"}
for top, title, f, fmt in ((5, "Table 1. NPV (KRW, real)", npv, MONEY), (14, "Table 2. LCOE (KRW/kWh, real)", lcoe, "#,##0.0")):
put(m, f"A{top - 1}:H{top - 1}", title, bold=True)
put(m, f"A{top}", "Nominal rate", bold=True, fill="head")
put(m, f"B{top}", "Real rate", bold=True, fill="head")
put(m, f"H{top}", "Legend name" if top == 5 else None, bold=True, fill="head")
for j, k in enumerate(K):
put(m, f"{chr(67 + j)}{top}", f'="Capex "&TEXT(1+({k})*step,"0%")', bold=True, fill="head")
for i, k in enumerate(K):
r = top + 1 + i
put(m, f"A{r}", f"=i_nom*(1+({k})*step)", bold=k == 0, fmt="0.00%")
put(m, f"B{r}", f"=(1+A{r})/(1+infl)-1", bold=k == 0, fmt="0.00%")
for j, kc in enumerate(K):
put(m, f"{chr(67 + j)}{r}", f.format(r=r, k=kc, CF=CF, R0=R0, **ref), bold=k == 0 and kc == 0, fmt=fmt)
if top == 5:
put(m, f"H{r}", f'="Rate "&TEXT(A{r},"0.0%")', color="595959")
body = f"C{top + 1}:G{top + 5}"
bad = f"C{top + 1}<0" if top == 5 else f"C{top + 1}>p_kWh"
m.conditional_formatting.add(body, FormulaRule(formula=[bad], fill=PatternFill("solid", fgColor=FILL["bad"])))
put(m, "A11:H11", '=IF(COUNTIF(C6:G10,"<0")=0,"NPV > 0 in all 25 cells: the verdict holds over this range",'
'IF(COUNTIF(C6:G10,">=0")=0,"NPV <= 0 in all 25 cells: the verdict holds over this range",'
'"NPV < 0 in "&COUNTIF(C6:G10,"<0")&" of 25 cells: the verdict depends on the capex and rate assumptions"))', bold=True)
put(m, "A20:H20", '="LCOE exceeds the value of electricity ("&p_kWh&" KRW/kWh) in "&COUNTIF(C15:G19,">"&p_kWh)'
'&" of 25 cells; same cells as NPV < 0 in Table 1"', bold=True)
series = []
for i in range(5):
sr = Series(Reference(m, min_col=3, max_col=7, min_row=6 + i))
sr.tx = SeriesLabel(strRef=StrRef(f"'Sensitivity'!$H${6 + i}"))
series.append(sr)
chart("NPV by capex multiplier", "million KRW · real", "Capex multiplier", "J4", m, series,
["sysDot", "dash", "solid", "lgDash", "dashDot"], legend="r").set_categories(Reference(m, min_col=3, max_col=7, min_row=5))
wb.save(out)
print("saved", out, "| sheets:", ", ".join(wb.sheetnames))
if __name__ == "__main__":
build(sys.argv[1] if len(sys.argv) > 1 else "energy_economics.xlsx")
```
Connect ChatGPT or Claude and use this prompt now · More prompts