Functions & Operators

The below tables list the functions and operators available for Driver Models.

Operators

Type Operator Notes
Arithmetic + - * / The standard arithmetic operators
Arithmetic % modulus, or remainder
Arithmetic ^ ** “to the power of”. x^y can be written as x**y or pow(x,y)
Logical Boolean && || ! And, Or, Not
Bitwise & | xor And, Or, Xor
Comparison > < >= <= Greater than, Less Than, Greater Than or Equal To, Less Than or Equal To
Comparison = == Is Equal To
Comparison != Is Not Equal To
Constants e pi Euler’s constant, approximately 2.7182818, Pi, approximately 3.14159265

Functions

Math
Function Notes
abs(Number) Returns the absolute value of the specified number
acos(Number) Returns the angle whose cosine is the specified number
asin(Number) Returns the angle whose sine is the specified number
atan(Number) Returns the angle whose tangent is the specified number
ceiling(Number) Returns the smallest integral value that is greater than or equal to the specified number
cos(Angle) Returns the cosine of the given angle
cosh(Angle) Returns the hyperbolic cosine of the specified angle
exp(Number) Returns e raised to the specified power
floor(Number) Returns the largest integer less than or equal to the specified number
ln(Number) Returns the natural (base e) logarithm of a number
log10(Number) Returns the natural (base 10) logarithm of a number
log(Number, Base) Returns the logarithm of a number in a specified base
pow(Number, Power) Returns a number raised to the specified power
rand() Returns a random number between 0 and 1
rangepart(value, min[, max]) Returns that part of a value that lies between min and max)
round(Number[, d]) Rounds the argument, (optionally to the nearest ’d’ decimal places)
sin(Angle) Returns the sine of the given angle
sinh(Angle) Returns the hyperbolic sine of the specified angle
sqrt(Number) Returns the square root of the specified number
tan(Angle) Returns the tangent of the given angle
tanh(Angle) Returns the hyperbolic tangent of the specified angle
trunc(Number) Rounds the specified number to the nearest integer towards zero
Aggregate
Function Notes
avg(A, B, C, ..n) Returns the average of the specified numbers
max(A, B, C, ..n) Returns the maximum of the specified numbers
min(A, B, C, ..n) Returns the minimum of the specified numbers
sum(A, B, C, ..n) Returns the sum of the specified numbers
Time-period Functions
Function Notes
asset(AssetName, AttributeName) Returns the value of an attribute on an asset
simulationruntime() Returns the simulation time (from the active scenario)
periodCurrent() Gets the current 0 based period number
periodAverage(N[,[start][,end][,error_value]) Returns the cumulative average of the argument over all the model iterations to date, or between start and end if set. Error value applies prior to values prior to the range, or if not set the period 0 value
periodWeightedAverage(N, W[,[start][,end][,error_value]) Returns the cumulative weighed average of the argument over all the model iterations to date, or between start and end if set. Error value applies prior to values prior to the range, or if not set the period 0 value
periodCount([N,[start][,end]) Returns the number of model iterations to date, or between start and end if set.
periodFirst(N) Returns the value of the argument at the first model iteration.
periodLast(N) Returns the value of the argument at the last model iteration.
periodMax(N[,start][,end][,error_value]) Returns the high-water-mark of the argument over all the model iterations to date, or between start and end if set. Error value applies prior to values prior to the range, or if not set the period 0 value
periodMin(N[,start][,end][,error_value]) Returns the low-water-mark of the argument over all the model iterations to date, or between start and end if set. Error value applies prior to values prior to the range, or if not set the period 0 value
periodSum(N[,start][,end][,error_value]) Returns the cumulative sum of the argument over all the model iterations to date, or between start and end if set. Error value applies prior to values prior to the range, or if not set the period 0 value
periodOpeningBalance(I[,A[,R]]) Returns the start-of-period balance, based on an Initial balance and accruing Additions and Removals on each subsequent period.
periodClosingBalance(I[,A[,R]]) Returns the end-of-period balance, based on an Initial balance and accruing Additions and Removals on each period.
periodPresentValue(d, N) Returns the present value of parameter N using the specified discount rate of d
periodNPV(d, N) Returns the NPV of parameter N using the specified discount rate of d
periodDelay(p, N[, default]) Returns the value of the argument N, but p periods later. Prior to that, it returns optional [default], else 0
periodVar(N) Returns the variance of the argument N
relativePeriodSum([node], N) Returns the period sum of “node” over a rolling window into the past. The value of “N” determines the number of periods to go into the past including the current period.
Time-period Functions for All Periods
Function Notes
periodAverageAll(N) Returns the average of the argument over all of the time periods
periodCountAll() Returns the total number of periods
periodLastAll(N) Returns the value of the argument in the last period
periodMaxAll(N) Returns the maximum value of the argument over all of the time periods
periodMinAll(N) Returns the minimum value of the argument over all of the time periods
periodSumAll(N) Returns the sum value of the argument over all of the time periods
periodWeightedAverageAll(N, W) Returns the weighted average of the argument N over all of the time periods, weighted by W
Conditional Functions
Function Notes
if(test,truepart,falsepart) If ’test’ is true, returns ’truepart’, else ‘falsepart’
iferror(calculation, errorresult) If ‘calculation’ has an error, return the error result, otherwise return the result of ‘calculation’
switch(value, condition, result, condition2, result2, condition3, result3, ...) Evaluates a value, then returns the result associated with the value
Conditional Time-period Functions
Function Notes
AverageIf(condition, N) Returns the cumulative average of the argument over all the model iterations to date if the condition is met
CountIf(condition) Returns the number of model iterations to date if the condition is met
SumIf(condition, N) Returns the cumulative sum of the argument over all the model iterations to date if the condition is met
Execute Functions
Function Notes
execute(model name, period, input1Name, [input1Node], input2Name, [input2Node], ...) Executes an Akumen app (use period for the period number in driver models, 0 for Py/R). Returns 0 if successfull, otherwise -1. Note that this is not intended for large Py/R models, and could cause a performance impact. It is designed to be used as simple helper functions the driver model cannot perform. It is also limited to int/float inputs only
executeoutput([executeNode], output1Name) Returns the result of the execute function, getting the value output1Name from the result. This is limited to simple int/float outputs only
Optimise Functions
Function Notes
optimise(numParticles, maxIterations, [evaluationnode], targetvalue, [first_input], first_input_lower_bound, first_input_upper_bound, ... to max of 5 inputs) Optimises a node, altering inputs until the target value is reached
optimiseerror([optimise node]) Returns the error, ie how far from the target value was reached
optimiseInput([optimise node], [Input node]) Returns the final input value from the optimisation
minimise(numParticles, maxIterations, [evaluationnode], [first_input], first_input_lower_bound, first_input_upper_bound, ... to max of 5 inputs) Alters inputs until the minimal value of the result node is reached
minimiseInput([minimise node], [Input node]) Returns the final input value from the minimisation
maximise(numParticles, maxIterations, [evaluationnode], [first_input], first_input_lower_bound, first_input_upper_bound, ... to max of 5 inputs) Alters inputs until the minimal value of the result node is reached
maximiseInput([maximise node], [Input node]) Returns the final input value from the maximisation

Datasource Functions

See here for information on setting up datasources, or here for further information on how to use datasources within Value Driver Models.

Function Notes
datasource([datasource_node], value_column, aggregation_method, forwardfill, forwardfillstartingvalue, filter1column, filter1value, filter2column, filter2value, ...) Links a calculation to the datasource and applies an optional filter
datasourceall([datasource_node], value_column, aggregation_method, forwardfill, forwardfillstartingvalue, filter1column, filter1value, filter2column, filter2value, ...) Links a calculation to the datasource and applies an optional filter
  • value_column: The column within the datasource that contains the value
  • aggregation_method: sum, avg, min, max, count, stddev, firstquartile, thirdquartile, firstknownvalue, lastknownvalue or median
  • forwardfill: true/false/number: If true, the last known value is used to forward fill when there is no data. False will cause an error if there is no data. Number will use the number value where there is no data
  • forwardfillstartingvalue: A number to use if there is no last know value to start with
  • filter1column: The column that contains the string value to filter the data on for this particular calculations
  • filter1value: The string value to filter on
Info

Datasource specific filtering can be used across multiple columns in the datasource by adding in filter2column, filter2value, filter3column, filter3value etc.

Info

datasourceall can also be used in place of datasource (using the same parameters). Instead of operating at a single time period, it operates across the entire dataset (honouring the load id and additional filter). This allows you to do things like get the stddev or mean of the entire dataset.

Timeseries Functions

If only one row exists in the timeseries node, data can be referenced in the calculation formula by only providing the timeseries node name.
If multiple rows exist, the row name will need to be specified in the calculation formula as well. See grid below for calculation formula formats.

Function Notes
timeseries([timeseries_node]) References time series node with name “timeseries_node”
timeseries(timeseries([timeseries_node],"row_name")) References time series node with name “timeseries_node” and row label “row_name”
timeseries([timeseries_node],[numeric_node_name]) References time series node with name “timeseries_node” and the row set to the 0-based value “numeric_node_name”

DateTime

Function Notes
CurrentDayInMonth() The numerical day of the month of the current period
CurrentDayInWeek() The numerical day of the week of the current period
CurrentDayInYear() The numerical day of the year of the current period
CurrentMonth() The numerical current month
CurrentPeriodDateTimeUtc() The current period datetime in Excel format (ie 40000)
CurrentYear() The numerical current year
DaysInMonth() The numerical days in the month
FirstPeriodDateTimeUtc() Period 0’s datetime in Excel format
LastPeriodDateTimeUtc() The last period’s datetime in Excel format
NumPeriods() The number of periods in the model

Random

Function
ContinuousUniform(lower, upper, [seed])
Lognormal(mu, signma, [seed])
Normal(mean, stddev, [seed])
Pert(min, mostlikely, max, [seed])
Triangular(lower, upper, mode, [seed])
Info

The seed is optional, and applies at time period 0. This means that the random number generated for time period 0 will always be the same as long as the seed remains the same. The following periods reuse the random number generator meaning the pattern of numbers will be exactly the same for each execution. This guarantees consistency of results. The seed can also be applied using a scenario parameter.

Range Checking

Click here for more information on range checking nodes.

Function Notes
rangecheck(sourcenode, lowlow, low, high, highhigh) Performs a check against of the source nodes value against the limits
rangecheckresult(rangechecknode) Returns a value corresponding to which limit has been broken. -2 = lowlow, -1 = low, 0 = none, 1 = high, 2 = highhigh