Sub topic 5
Balancing inflow and outflow
This chapter assumes you know what sources and sinks are, and that you can read short Python and work with percentages. It builds the working model for predicting where a currency balance ends up. The next chapter uses that model to explain inflation and deflation.
Stock and flow
A game economy has two kinds of quantity.
- A stock is an amount held at a moment in time, such as a player's gold balance.
- A flow is an amount moving per unit of time, such as gold earned per hour or gold spent on repairs per day.
The stock changes only through flows:
balance(t+1) = balance(t) + inflow(t) - outflow(t)When inflow is larger than outflow, the stock grows. When outflow is larger, it shrinks. When they are equal, the stock holds steady. That steady state is called equilibrium. A designer rarely wants a stock that is frozen. The usual goal is an equilibrium at a level that matches the game's pacing, and a way back to it after a shock.
Two kinds of outflow
How the outflow is defined decides whether an equilibrium exists at all.
A fixed sink removes a set amount regardless of the balance, such as a 50-gold repair bill. A proportional sink removes a share of the balance, such as a 5% auction fee or a daily storage tax.
| Property | Fixed outflow | Proportional outflow |
|---|---|---|
| Outflow depends on balance | No | Yes |
| Self-correcting | No | Yes. Richer players lose more. |
| Equilibrium exists | Only if the fixed drain is at least the inflow | Always, for any positive income |
| Typical examples | Repair costs, entry tickets | Transaction fees, decay, wealth taxes |
| Main risk | Wealth grows without limit, or players are drained to zero | Players with small balances barely notice it |
A proportional sink acts like a thermostat. If the balance rises, the drain rises with it. A fixed sink has no feedback. If income is 100 per day and the fixed drain is 80 per day, the balance grows by 20 every day, forever.
Finding the equilibrium
Take a player who earns I per day, then loses a fraction r of the balance to a proportional sink. The update is:
b' = (b + I) * (1 - r)At equilibrium b' = b, so:
b = I * (1 - r) / rFor I = 100 and r = 0.10, the balance settles near 100 * 0.9 / 0.1 = 900. The player holds 1000 right after earning and 900 after the sink runs. Which of those you call "the balance" depends on when you measure, so decide on a measurement point and keep it consistent.
The following script compares the two sink types over 60 days:
def run(step, days, start=0.0):
"""Apply one daily update function repeatedly and return the final balance."""
balance = start
for _ in range(days):
balance = step(balance)
return balance
def proportional(income, rate):
return lambda b: (b + income) * (1 - rate)
def fixed(income, cost):
# A player cannot spend gold they do not have, so the balance floors at 0.
return lambda b: max(0.0, b + income - cost)
print(round(run(proportional(100, 0.10), 60))) # about 898, heading for 900
print(run(fixed(100, 80), 60)) # 1200.0, still growing by 20 a day
print(run(fixed(100, 120), 60)) # 0.0, the player is always brokeThe three results show three regimes. A proportional sink converges. A fixed sink below income grows without limit. A fixed sink above income leaves the player at zero, and the floor hides the fact that the drain is larger than the income.
How fast the economy settles
The equilibrium value tells you where the balance ends up. It does not tell you when. With a proportional sink, the gap between the balance and equilibrium shrinks by a factor of (1 - r) each step. The time to close 90% of the gap is:
days = ln(0.1) / ln(1 - r)For r = 0.10 that is about 22 days. For r = 0.02 it is about 114 days. A gentle sink is slow to correct a surplus. If a bug or event dumps extra currency into the economy, a 2% sink will take months to remove it, while a 10% sink takes weeks. Choose the rate with the correction speed you want in mind, not only the final level.
Where the simple model breaks
The single-player model is a starting point. Real economies break its assumptions in several ways.
- Players are not average. An equilibrium computed from the average income hides the spread. A player earning three times as much settles at three times the balance. Check the formula for your slowest and fastest earners, not only the middle.
- Sinks are optional. A repair bill is mandatory only if the game forces it. A cosmetic shop is a sink only if players choose to buy. If players can skip a sink, treat its outflow as a probability, not a certainty. Measure what share of players use it.
- Income changes over time. Rewards usually rise with level or content tier. The equilibrium moves up as players progress, so the sink must scale with it or its effect fades.
- The population changes. New players add inflow, and churned players leave behind stock that never drains. In a shared market, the money held by inactive accounts still counts toward the total supply even though it no longer moves.
- Spending is bounded by the balance. Outflow can never exceed the stock. A sink sized larger than players' income does not remove more currency. It only blocks them from purchases.
- Conversion moves value without removing it. Trading one currency for another, or one player paying another, shifts the stock between holders. It is a sink only if some of the value is destroyed, for example by a fee.
Measuring flows by reason
To balance flows you need to see them, and a single total hides the cause of any imbalance. Record every change in the balance with a label for its source or sink. The Ledger class below does that and rejects invalid amounts:
from collections import defaultdict
class Ledger:
def __init__(self):
self.balance = 0
self.earned = defaultdict(int)
self.spent = defaultdict(int)
def earn(self, reason, amount):
if amount <= 0:
raise ValueError("amount must be positive")
self.balance += amount
self.earned[reason] += amount
def spend(self, reason, amount):
if amount <= 0:
raise ValueError("amount must be positive")
if amount > self.balance:
raise ValueError("insufficient funds")
self.balance -= amount
self.spent[reason] += amount
def net_flow(self):
return sum(self.earned.values()) - sum(self.spent.values())
wallet = Ledger()
wallet.earn("quest_reward", 500)
wallet.spend("weapon_repair", 120)
print(wallet.balance, wallet.net_flow()) # 380 380Summed over every player, the ledger gives you the economy's total inflow and outflow per source and per sink. The net flow must always equal the change in total balance. If it does not, currency is being created or destroyed somewhere that is not recorded, which is a bug or an exploit.
A balancing procedure
Use these steps when you set up or adjust an economy.
- List every source and every sink, with its expected amount per hour or per day for a typical player.
- Compute the net flow. If it is not close to zero at the intended wealth level, find the term responsible.
- Prefer at least one proportional sink so the system corrects itself.
- Compute the equilibrium and the settling time, then compare them with the pacing you want.
- Repeat for your slowest and fastest earners.
- Measure the real flows after launch and compare them with the plan.
Exercise
A player earns 200 gold per day. A proportional sink removes 8% of the balance each day, applied after income. (a) What balance does the player settle at, measured after the sink? (b) The designer wants to halve that balance by changing only the sink rate. Roughly what rate is needed?
Show answer
(a) b = I (1 - r) / r = 200 0.92 / 0.08 = 2300 gold. (b) The target is 1150. Solve 200 * (1 - r) / r = 1150, which gives 200 - 200r = 1150r, so r = 200 / 1350, about 14.8%. Halving the balance needs nearly double the rate, because the balance depends on (1 - r) / r and not on r directly.
Exercise
A game charges a fixed 90-gold repair bill per day and pays 100 gold per day. After a year, what is the problem, and what kind of sink would fix it without raising the repair bill?
Show answer
The net flow is +10 gold per day, so the balance grows without limit, about 3,650 gold after a year, with nothing pushing it back. Adding a proportional sink, such as a small fee or storage tax on the balance, creates feedback. The balance then settles at a finite level, and it settles faster if the rate is higher.