Cerebro contains a simulated broker: it holds your cash, executes your orders and keeps your positions. With no setting, it starts with 10,000 in cash.
cerebro.broker.setcash(25000) sets the starting capital, before run(). In the strategy, self.broker.getcash() returns the free cash.
getvalue() returns the total value: cash plus market value of positions. As soon as you hold a position, it moves at every bar, even if you do nothing.
If cash is not enough for an order, the broker rejects it: the order gets the Margin status, visible in notify_order().
Examples
CASH-X (fictional market) : The vertical line marks the current bar. If you hold a position, getvalue() revalues it at each new candle: your value rises and falls with the price, even without a new order.
The crash of 19 October 1987 : That day the Dow Jones lost about 22.6% in a single session, its worst day in percentage terms. A portfolio invested in stocks would have seen its total value fall by as much in one bar, while its cash would not have moved.
Key terms
Broker
The simulator that manages cash, orders and positions
setcash()
Sets the starting capital
getcash()
Returns the available cash
getvalue()
Returns the total value, cash and positions included