Value types¶
Every value column has a kind and a shape, and its type names both: zk.FloatA is an array
of floats, zk.StringC a string constant, and so on.
Shapes¶
| Shape | Suffix | A value cell holds | Typical use |
|---|---|---|---|
| Constant | C |
One value | Premium, a parameter, a limit |
| Array | A |
length values, one per simulation |
Simulated IBNR, attritional losses |
| Jagged | J |
length entries, each holding its own number of values |
Large losses: per simulation, a count of events and a severity for each |
A jagged value is stored densely: every value in one long array, and the number of values in each entry in another. A low-frequency distribution, where most simulations have no events, takes little memory.
Kinds¶
| Kind | Python type | Constant | Array | Jagged |
|---|---|---|---|---|
| Float | float |
zk.FloatC |
zk.FloatA |
zk.FloatJ |
| Int | int |
zk.IntC |
zk.IntA |
zk.IntJ |
| Bool | bool |
zk.BoolC |
zk.BoolA |
zk.BoolJ |
| Date | datetime.date |
zk.DateC |
zk.DateA |
zk.DateJ |
| String | str |
zk.StringC |
zk.StringA |
zk.StringJ |
Each kind is stored at its own width: 64-bit floats and integers, booleans, dates as days since 1970, and strings as codes into a shared table of the strings seen.
Naming a column¶
Subscript a type with a name to declare a column of that type:
Using Literal makes the name part of the static type, so a type checker can follow which columns
a collection holds. At runtime zk.FloatA["gross_ibnr"] works too.
To declare several columns together, subclass zk.ValueColumns. See
Building collections.
Nothing converts implicitly¶
zeki never changes a value's kind or shape behind your back:
- Kinds must match. Adding a float column to an int column raises a
ValueError. Operations take operands of one kind:+,-,*and//take floats or ints,/takes floats or ints (ints divide to floats, as in Python),zk.minandzk.maxtake floats, ints or dates, and comparisons give bools. - A constant broadcasts. A constant combines with an array or jagged value, applying to every value.
- An array of length 1 is not a constant. Arrays combine only when their lengths are equal. See Lengths.
- An array spreads over a jagged value of the same length entry by entry: each entry's values combine with that entry's array value.