Price class: arithmetic operators
The Price class overloads common arithmetic operators that allow you to perform arithmetic on prices in a variety of formats.
public static Price operator *(int tick, Price price);
public static Price operator *(Price price, int tick);
public static Price operator *(Price lhs, Price rhs);
public static Price operator /(int tick, Price price);
public static Price operator /(Price price, int tick);
public static Price operator /(Price lhs, Price rhs);
public static Price operator +(int tick, Price price);
public static Price operator +(Price price, int tick);
public static Price operator +(Price lhs, Price rhs);
public static Price operator -(int tick, Price price);
public static Price operator -(Price price, int tick);
public static Price operator -(Price lhs, Price rhs);
public static Price operator --(Price price);
public static Price operator ++(Price price);
For example, assume that the variable inst represents a valid instance for the Eurex FGBL-Jun20 futures contract. You could use the overloaded ++ operator to increase the price by one tick.
Price p1 = Price.FromString(inst,"114.73");
Console.WriteLine("Price = " + p1.ToString());
p1++;
Console.WriteLine("Price = " + p1.ToString());
The result of this code snippet would be:
Price = 114.73
Price = 114.74
Because these operators return a Price object, you can create expressions such as:
Price p1 = Price.FromString(inst,"114.73");
Price p2 = (p1 + 1) * 2;
The expression (p1 + 1) calls the +(Price price, int tick) operator. Because this expression also returns a Price object, it then calls the *(Price price, int tick) operator to complete the evaluation.