ifference between revisions of "EMK:Formulae and Functions"

From EMK Wiki
Jump to navigation Jump to search
Line 103: Line 103:
 
|-
 
|-
 
| Between || Whether a number is between two limits || Number: lower limit; upper limit, Integer, real or date || 0 or 1 || Between(5.7,9.7) || 0
 
| Between || Whether a number is between two limits || Number: lower limit; upper limit, Integer, real or date || 0 or 1 || Between(5.7,9.7) || 0
 +
|}
 +
 +
===Run Information Functions===
 +
 +
The following table lists EMarket's Run information functions:
 +
{|class="wikitable"
 +
! Function !! Purpose !! Parameters !! Return Type
 +
|-
 +
| Date || Date of current Tick || None || Date
 +
|-
 +
| TP || TP number of current Tick || None || Integer
 +
|-
 +
| Version || The position of a Run in a Batch sequence. For first Run, Version is zero. || None || Integer
 
|}
 
|}

Revision as of 09:23, 21 November 2012

Formulae can be entered as substitutes for specific values into most fields in EMarket to control the derivation of variable values at run time. A formula can contain any combination of:

Constants

Constants can be:

  • Numbers: Integers or Reals (e.g. 1, 2.5, -3), they can also be entered in scientific notation e.g. '3E+10'.
  • Strings: Written inside double quotes e.g. "A Node"
  • Dates: Must be enclosed in single quotes e.g '1/3/2004' or '14 April 2005'

Warning: The format for entering dates should compatible with the computer's local date (locality) setting

Variables

Variables can be regarded as user-defined Entity.Traits which can be defined in the Volatility Matrix or the Schedule. Previously defined variables can be used in formulae.

Note: EMarket provides a 'system' variable the user need not define: 'DateTime' which is of type 'Date' and gives the current simulation date as the model runs.

Operators

Operators are all pre-defined in EMarket. Their purpose is to separate a formula into parts that are then combined to give a single value.

The following operators are shown in descending order of precedence.

Operator Meaning Example Parameter Type Return Type
\ Integer Division 3\2 = 1 Real; Int Int
% Modulus 7%5 = 2 Real; Int Int
/ Division 3/2 = 1.5 Real; Int Real
* Multiplication 5*4.2 = 21 Real; Int Real
- Subtraction 7-3.2 = 3.8 Real; Int Real
+ Addition 3.5+1.5 = 5 Real; Int Real

Functions

Functions provide a powerful mechanism for deriving field and variable data values from input parameters.

A function has the form FunctionName(Parameter1, Parameter2, ...)

An operator is used in a Function in the following form: <Parameter1>Operator<Parameter2>.

EMarket provides the following function types:

  • Arithmetic functions
  • Logic functions
  • Run information functions
  • Time functions
  • Other functions

Note: Logic operators and functions evaluate to one for a result that is true (for example 6 = 6), and zero for false.

Arithmetic Functions

The following table lists EMarket's Arithmetic functions:

Function Purpose Parameters (Description, Type) Return Type Example Result
Sqrt Square root of a number Number, Integer or Real Real Sqrt(546.94) 23.387
Abs Absolute value of a number Number, Integer or Real Real Abs(-19.1) 19.1
Int Integer portion of a number Number, Integer or Real Integer Int(45.786) 45
Sum Total value of numbers in an array Value Array (Exclude Value), Integer or Real Real Sum(Node.Price)
Max Maximum value of numbers in an array, optionally excluding values with value over an exclude value Value Array (Exclude Value), Integer or Real Real Max(Generator.Generation)
Min Minimum value of numbers in an array Value Array (Exclude Value), Integer or Real Real Min(Generator.Generation)
StdDev Standard deviation of numbers in an array Value Array (Exclude Value), Integer or Real Real StdDev(Generator.Generation)
Avg Average value of numbers in an array Value Array (Exclude Value), Integer or Real Real Avg(Generator.Generation)
WgtAvg Average of numbers in an array, weighted by numbers in another array Value Array (Weights Array), Integer or Real Real WgtAvg(Generator.Generation,Generator.Cost)
Choke Returns a collared value (i.e. the value of the referenced variable is returned if it falls within the specified range otherwise the relevant minimum or maximum value is returned) Number, Integer or Real Real Choke(500,200,Generator.Generation)

Logic Functions

The following table lists EMarket3's Logic functions:

Operator Purpose Parameters (Description, Type) Return Value Example Result
= Whether two numbers are Equal 2 numbers, Integer or Real 0 or 1 5 = 6 0
< Whether first number is less than the second 2 numbers, Integer or Real 0 or 1 -2 < 7 1
> Whether first number is Greater than the second 2 numbers, Integer or Real 0 or 1 9 > 7 1
AND Whether two numbers are both non-zero 2 numbers, Integer or Real 0 or 1 And(6=6,4<3) 0
OR Whether either of two numbers are non-zero 2 numbers, Integer or Real 0 or 1 OR(3<5, 2>3) 1
Between Whether a number is between two limits Number: lower limit; upper limit, Integer, real or date 0 or 1 Between(5.7,9.7) 0

Run Information Functions

The following table lists EMarket's Run information functions:

Function Purpose Parameters Return Type
Date Date of current Tick None Date
TP TP number of current Tick None Integer
Version The position of a Run in a Batch sequence. For first Run, Version is zero. None Integer