Exemplo n.º 1
0
        }//end IsZeroVector()

        //
        //
        // *****************************************************************
        // ****						Round Price Safely                  ****
        // *****************************************************************
        //
        /// <summary>
        ///		This method takes a price and rounds it to the SAFER tick price. Here, "safer"
        ///		means the price is rounded further away from the market. Therefore, sell side prices
        ///		are rounded up, and buy prices are rounded down to the nearest ticks.
        ///
        ///		In general, a sloppy price can be writen as an exact price with an small error "eps",
        ///				price = iPrice * minTickSize	+  eps
        ///		where iPrice is an integer, and  minTickSize > eps.  Error is smaller than eps.  Then,
        ///		we want to return the safer trade price of
        ///
        ///			(iPrice + Theta[eps] )*minTickSize			for Sells,
        ///
        ///			(iPrice - Theta[-eps])*minTickSize			for Buys.
        ///
        ///		This formula says
        ///			for Sells: if eps > 0, then we will add another tick to the price.
        ///			for Buys: if 0 > eps, then we lower the price by another tick.
        ///
        ///		Using the above relation for the price, we find that (since tickSize > |eps|)
        ///			iPrice = Round(  price / minTickSize )
        ///			eps = price - iPrice * minTickSize
        ///
        /// </summary>
        /// <param name="price">imperfect price to round to nearest (safe) tick price.</param>
        /// <param name="mktSideSign">Selling price = -1, Buying prices = +1</param>
        /// <param name="minTickSize">0.5 for ED.</param>
        /// <returns></returns>
        public static double RoundPriceSafely(double price, int mktSideSign, double minTickSize)
        {
            double safePrice = 0.0d;

            try
            {
                double nearestTickPrice = minTickSize * Math.Round(price / minTickSize); // nearest tick price.
                double epsilon          = price - nearestTickPrice;                      // small error between price and nearest tick price.
                epsilon = -mktSideSign * epsilon;                                        // make sign denote round off direction.
                double safetyCushion = -mktSideSign *QTMath.Heaviside(epsilon) * minTickSize;

                safePrice = nearestTickPrice + safetyCushion;
            }
            catch (Exception e)
            {
                Console.WriteLine(" errSrc:" + e.Source + " errMsg:" + e.Message + " Stack:" + e.StackTrace.ToString(), "QTMath.RoundPriceSafely");
            }
            return(safePrice);
        }//end RoundPrice()
Exemplo n.º 2
0
 public static int MktSignToActiveMktSide(double sign)
 {
     return(QTMath.Heaviside(sign));
 }
Exemplo n.º 3
0
 /// <summary>
 ///	Given the "market sign" +1 for buys and -1 for sells, this method returns
 ///	a 0 and 1, respectively.
 /// </summary>
 /// <param name="sign">market sign +1=bid, -1=ask.</param>
 /// <returns>
 ///		0 if sign is +1, 1 if sign is -1.
 /// </returns>
 public static int MktSignToMktSide(int sign)
 {
     return(QTMath.Heaviside(-sign));
 }