com.dxfeed.glossary
Class PriceIncrements

java.lang.Object
  extended by com.dxfeed.glossary.PriceIncrements
All Implemented Interfaces:
Serializable

public class PriceIncrements
extends Object
implements Serializable

Represents rules for valid price quantization for a given instrument on a certain exchange. These rules are defined as a set of price ranges with associated price increments. Each price increment defines what price values are valid for corresponding price range - valid prices shall be divisible by corresponding price increment.

All price ranges shall be mutually exclusive and they shall cover entire space from 0 to infinity. Therefore all ranges can be represented as a sequence of numbers where increments are interleaved with range limits, with extreme limits (0 and infinity) omitted for short. Negative space (from negative infinity to 0) uses symmetrical price ranges.

There is a special value EMPTY which is used to represent unknown or undefined rules. This value has empty textual representation and is considered to have sole increment with value 0.

See getText() and getPriceIncrements() for details about used formats and representations.

NOTE:This class produces precise results for decimal numbers with at most 14 significant digits and at most 14 digits after decimal point.

See Also:
Serialized Form

Field Summary
static PriceIncrements EMPTY
          Empty price increments - it has empty text and sole increment with value 0.
 
Method Summary
 boolean equals(Object obj)
           
 double getPriceIncrement()
          Returns first price increment (for price range adjacent to 0), usually the smallest one.
 double getPriceIncrement(double price)
          Returns price increment which shall be applied to the specified price.
 double getPriceIncrement(double price, int direction)
          Returns price increment which shall be applied to the specified price in the specified direction.
 double[] getPriceIncrements()
          Returns internal representation of price increments as a single array of double values.
 int getPricePrecision()
          Returns first price precision (for price range adjacent to 0), usually the largest one.
 int getPricePrecision(double price)
          Returns price precision for the price range which contains specified price.
 String getText()
          Returns textual representation of price increments in the format: TEXT ::= "" | LIST LIST ::= INCREMENT | RANGE "; " LIST RANGE ::= INCREMENT " " UPPER_LIMIT Where INCREMENT is a price increment in the given price range and UPPER_LIMIT is the upper bound of that range.
 int hashCode()
           
 double incrementPrice(double price, int direction)
          Returns specified price incremented in the specified direction by appropriate increment and then rounded to nearest valid value.
 double incrementPrice(double price, int direction, double step)
          Returns specified price incremented in the specified direction by the maximum of specified step and appropriate increment, and then rounded to nearest valid value.
 double roundPrice(double price)
          Returns specified price rounded to nearest valid value.
 double roundPrice(double price, int direction)
          Returns specified price rounded in the specified direction to nearest value that is valid according to price increment rules.
 String toString()
           
static PriceIncrements valueOf(double increment)
          Returns an instance of price increments for specified single increment.
static PriceIncrements valueOf(double[] increments)
          Returns an instance of price increments for specified internal representation.
static PriceIncrements valueOf(String text)
          Returns an instance of price increments for specified textual representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final PriceIncrements EMPTY
Empty price increments - it has empty text and sole increment with value 0.

Method Detail

valueOf

public static PriceIncrements valueOf(String text)
Returns an instance of price increments for specified textual representation. See getText() for format specification.

Throws:
IllegalArgumentException - if text uses wrong format or contains invalid values

valueOf

public static PriceIncrements valueOf(double increment)
Returns an instance of price increments for specified single increment.

Throws:
IllegalArgumentException - if increment uses invalid value

valueOf

public static PriceIncrements valueOf(double[] increments)
Returns an instance of price increments for specified internal representation. See getPriceIncrements() for details about internal representation.

Throws:
IllegalArgumentException - if data contains invalid values

getText

public String getText()
Returns textual representation of price increments in the format:
 TEXT ::= "" | LIST
 LIST ::= INCREMENT | RANGE "; " LIST
 RANGE ::= INCREMENT " " UPPER_LIMIT
 
Where INCREMENT is a price increment in the given price range and UPPER_LIMIT is the upper bound of that range. All ranges are listed in the ascending order of upper limits and the last range is considered to extend toward infinity and is therefore specified without upper limit. All increments and limits are finite positive numbers. The case with empty text is a special stub used for EMPTY value, it uses sole increment with value 0.


getPriceIncrements

public double[] getPriceIncrements()
Returns internal representation of price increments as a single array of double values. This array specifies all numbers from textual representation (see getText()) in the same order. Therefore numbers at even positions are increments and numbers at odd positions are upper limits. The array always has odd length - the infinite upper limit of last range is always omitted and the first increment (for price range adjacent to 0) is always included even for EMPTY value.


getPriceIncrement

public double getPriceIncrement()
Returns first price increment (for price range adjacent to 0), usually the smallest one. Returns 0 for EMPTY price increments.


getPriceIncrement

public double getPriceIncrement(double price)
Returns price increment which shall be applied to the specified price. If price is Not-a-Number (NaN) then first price increment is returned. If price is a breakpoint between two ranges then minimum of upward and downward increments is returned. This method is equivalent to calling getPriceIncrement(price, 0).


getPriceIncrement

public double getPriceIncrement(double price,
                                int direction)
Returns price increment which shall be applied to the specified price in the specified direction. If price is Not-a-Number (NaN) then first price increment is returned. If price is a breakpoint between two ranges and direction is 0 then minimum of upward and downward increments is returned.


getPricePrecision

public int getPricePrecision()
Returns first price precision (for price range adjacent to 0), usually the largest one. Returns 0 for EMPTY price increments.


getPricePrecision

public int getPricePrecision(double price)
Returns price precision for the price range which contains specified price. Price precision is a number of decimal digits after decimal point that are needed to represent all valid prices in the given price range. This method returns price precision in the interval [0, 10] inclusive. If price is Not-a-Number (NaN) then first price precision is returned. If price is a breakpoint between two ranges then precision of lower range is returned.


roundPrice

public double roundPrice(double price)
Returns specified price rounded to nearest valid value. If price is Not-a-Number (NaN) then NaN is returned. If appropriate price increment is 0 then specified price is returned as is. This method is equivalent to calling roundPrice(price, 0).


roundPrice

public double roundPrice(double price,
                         int direction)
Returns specified price rounded in the specified direction to nearest value that is valid according to price increment rules. If price is Not-a-Number (NaN) then NaN is returned. If appropriate price increment is 0 then specified price is returned as is. If direction is 0 then price is rounded to nearest valid value.


incrementPrice

public double incrementPrice(double price,
                             int direction)
Returns specified price incremented in the specified direction by appropriate increment and then rounded to nearest valid value. If price is Not-a-Number (NaN) then NaN is returned. If appropriate price increment is 0 then specified price is returned as is. This method is equivalent to calling incrementPrice(price, direction, 0).

Throws:
IllegalArgumentException - if direction is 0

incrementPrice

public double incrementPrice(double price,
                             int direction,
                             double step)
Returns specified price incremented in the specified direction by the maximum of specified step and appropriate increment, and then rounded to nearest valid value. If price is Not-a-Number (NaN) then NaN is returned. If both step and appropriate price increment are 0 then specified price is returned as is. Note that step must be positive even for negative directions.

Throws:
IllegalArgumentException - if direction is 0 or step uses invalid value

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Devexperts. All Rights Reserved.