FRENESDE

The broker and capital

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

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
Take the mission on Doji Academy

← Back to the index