|
|
|
Price values in the Aspen API are represented using the ASPEN_PRICE type definition. Use the ASPEN_PRICE type to declare variables that will hold Aspen-formatted price values. These values must be interpreted and manipulated according to a specific set of rules and definitions.
Every financial instrument requires its price values to be represented with a certain minimum degree of precision, or display scale. The minimum precision value for any particular instrument is called a quantum. The quantum specifies the smallest subdivision of price units which can be specified for that instrument.
A quantum value is bounded by the rule
A quantum is represented by two parts, the base and the exponent n, such that

The base can be ASPEN_BINARY or ASPEN_DECIMAL. For ASPEN_BINARY, the range of the exponent n2 is

For ASPEN_DECIMAL, the range of the exponent n10 is

For example, if the base is ASPEN_BINARY and the exponent is 5, the quantum for the financial instrument is

Or, if the base is ASPEN_DECIMAL and the exponent is 3, then

Every financial instrument is described by an ASPEN_INSTRUMENT structure which contains an ASPEN_QUANTUM. The base and exponent fields of the quantum can be converted into trading units as demonstrated above. However, a more effective method can be devised using a look-up table. Consider the two-dimensional array quantum2units which contains the reciprocal of the quantum values, or the denominator of the quantum as expressed in fractional notation.
double quantum2units [2] [16] =
{
{ 1.0, 10.0, 1E+2, 1E+3, 1E+4, 1E+5, 1E+6,
1E+7,
1E+8,1E+9, 1E+10, 1E+11, 1E+12, 1E+13, 1E+14, 1E+15 },
{ 32., 2., 4., 8., 16., 32., 64., 128.,
256., 512., 1024., 2048., 256., 32., 64., 128. }
}
Via the quantum2units array, the trading units may be determined by direct lookup:
units = quantum2units[base][exponent]
Aspen prices can be decoded into whole and fractional components by using the trading units and integer division. For example, an ASPEN_PRICE value of 332 whose trading units value was 16 would decode to a price of 20 12/16.
int units, whole, remainder;
units = (int) quantum2units[base][exponent];
whole = price / units;
remainder = price % units;
printf ("%d %d/%d", whole, remainder, units);
To facilitate decoding of ASPEN_PRICE values, an application can use the AspenDecodePrice() function to perform any of the operations shown above, or the application can declare and initialize an array containing either trading units or reciprocal trading unit values.

The maximum possible positive value that an ASPEN_PRICE field can contain is defined by the constant ASPEN_MAX_NUM. The minimum negative value is set by the constant ASPEN_MIN_NUM. Please see Constants.

A special value, ASPEN_NO_NUM, is also used when the price field must indicate that there is no price value available. Please see Constants.

Signed comparisons must be used when comparing price values.
©2006 Aspen Research Group, Ltd. All rights reserved. Terms of Use.