otp.state.var#

var(default_value, scope='query')[source]#

Defines a state variable. Supports int, float and string values.

Parameters
  • default_value (any) – Default value of the state variable

  • scope (str) – Scope for the state variable. Possible values are: query, branch, cross_symbol. Default: query

Return type

a state variable that should be assigned to a _source

Examples

>>> data = otp.Ticks(dict(X=[0, 1, 2]))
>>> data.state_vars['SUM'] = otp.state.var(0)
>>> data.state_vars['SUM'] += data['X']
>>> data['SUM'] = data.state_vars['SUM']
>>> data.to_df()[['X', 'SUM']]
   X  SUM
0  0    0
1  1    1
2  2    3