Stock

BPTK API Documentation for the Stock class
Keywords

system dynamics, bptk, bptk-py, python, business prototyping

Stock

Stock in a SD DSL model.

A stock is what a system remembers. Its value at any instant cannot be read off the rest of the system: it is the accumulation of everything that has flowed in and out since the start, which is why it needs both an initial value and an equation.

Create one through the model rather than directly: model.stock("population").

Stock Constructor

Stock(model, name)

Create the stock.

Stock.initial_value

property initial_value

The value the stock holds at starttime, before any flow has acted on it. Set it to a number, to a Constant — which is what lets a scenario override it — or to any expression:

population = model.stock("population")
population.initial_value = 80000000.0

# or computed, from constants, converters or a user-defined function
births = model.constant("births")
births.equation = 800000.0
population.initial_value = births * 100

The expression is evaluated once, before the run, with t at the start time. A boolean is refused, and so is anything that is not a number or a model expression; the error names the stock.

A scenario cannot set the stock itself as a constant - that would replace its equation and the stock would not move. It raises ValueError naming the stock; set the constant its initial value refers to instead.

Stock.equation

property equation

The net change per timestep, not the value — usually the inflows minus the outflows. Read, it returns the equation as originally set - an SD DSL Element or Operator.

population.equation = births - deaths

Inherited from Element

Everything else — equation, function_string, plot() and the arrayed-element API — comes from Element, where it is documented once for all element types.