private double getOptionMidPrice(StockOptionTickTransaction tick, double volumeTarget = 10)
        {
            double mid = 0;

            if (tick == null || tick.AskV1 == 0 || tick.BidV1 == 0 || tick.Ask1 == 0 || tick.Bid1 == 0)
            {
                return(mid);
            }
            var askv1     = Math.Min(volumeTarget, tick.AskV1);
            var askv2     = Math.Max(Math.Min(volumeTarget - askv1, tick.AskV2), 0);
            var askv3     = Math.Max(Math.Min(volumeTarget - askv1 - askv2, tick.AskV3), 0);
            var askv4     = Math.Max(Math.Min(volumeTarget - askv1 - askv2 - askv3, tick.AskV4), 0);
            var askv5     = Math.Max(Math.Min(volumeTarget - askv1 - askv2 - askv3 - askv4, tick.AskV5), 0);
            var bidv1     = Math.Min(volumeTarget, tick.BidV1);
            var bidv2     = Math.Max(Math.Min(volumeTarget - bidv1, tick.BidV2), 0);
            var bidv3     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2, tick.BidV3), 0);
            var bidv4     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2 - bidv3, tick.BidV4), 0);
            var bidv5     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2 - bidv3 - bidv4, tick.BidV5), 0);
            var askvtotal = askv1 + askv2 + askv3 + askv4 + askv5;
            var bidvtotal = bidv1 + bidv2 + bidv3 + bidv4 + bidv5;
            var position  = (askv1 * tick.Ask1 + askv2 * tick.Ask2 + askv3 * tick.Ask3 + askv4 * tick.Ask4 + askv5 * tick.Ask5 + bidv1 * tick.Bid1 + bidv2 * tick.Bid2 + bidv3 * tick.Bid3 + bidv4 * tick.Bid4 + bidv5 * tick.Bid5) / (askvtotal + bidvtotal);
            var x         = (position - (tick.Ask1 + tick.Bid1) / 2) / ((tick.Ask1 - tick.Bid1) / 2);

            if (x > 0)
            {
                mid = (x) / (0.1 + x) * ((tick.Ask1 - tick.Bid1) / 2) + (tick.Ask1 + tick.Bid1) / 2;
            }
            else
            {
                mid = (x) / (0.1 - x) * ((tick.Ask1 - tick.Bid1) / 2) + (tick.Ask1 + tick.Bid1) / 2;
            }
            return(mid);
        }
        public static List <StockOptionTickTransaction> ModifyOptionTickData(List <StockOptionTickTransaction> original)
        {
            if (original == null || original.Count() == 0)
            {
                return(null);
            }
            var timelist = GetStockTickStamp();

            StockOptionTickTransaction[] modify = new StockOptionTickTransaction[timelist.Count];
            int      timeIndex = 0;
            DateTime today     = new DateTime(original[0].TransactionDateTime.Year, original[0].TransactionDateTime.Month, original[0].TransactionDateTime.Day);

            for (int j = 0; j < original.Count; j++)
            {
                while (original[j].TransactionDateTime.TimeOfDay >= timelist[timeIndex] && timeIndex < timelist.Count - 1)
                {
                    timeIndex++;
                }
                if (original[j].TransactionDateTime.TimeOfDay < timelist[timeIndex])
                {
                    var data0 = original[j];
                    modify[timeIndex - 1] = new StockOptionTickTransaction {
                        Ask1 = data0.Ask1, Ask2 = data0.Ask2, Ask3 = data0.Ask3, Ask4 = data0.Ask4, Ask5 = data0.Ask5, AskV1 = data0.AskV1, AskV2 = data0.AskV2, AskV3 = data0.AskV3, AskV4 = data0.AskV4, AskV5 = data0.AskV5, Bid1 = data0.Bid1, Bid2 = data0.Bid2, Bid3 = data0.Bid3, Bid4 = data0.Bid4, Bid5 = data0.Bid5, BidV1 = data0.BidV1, BidV2 = data0.BidV2, BidV3 = data0.BidV3, BidV4 = data0.BidV4, BidV5 = data0.BidV5, Amount = data0.Amount, Code = data0.Code, LastPrice = data0.LastPrice, TransactionDateTime = data0.TransactionDateTime, Volume = data0.Volume, OpenInterest = data0.OpenInterest
                    };
                }
            }
            for (int i = 1; i < timelist.Count; i++)
            {
                if (modify[i] == null && modify[i - 1] != null)
                {
                    var data0 = modify[i - 1];
                    modify[i] = new StockOptionTickTransaction {
                        Ask1 = data0.Ask1, Ask2 = data0.Ask2, Ask3 = data0.Ask3, Ask4 = data0.Ask4, Ask5 = data0.Ask5, AskV1 = data0.AskV1, AskV2 = data0.AskV2, AskV3 = data0.AskV3, AskV4 = data0.AskV4, AskV5 = data0.AskV5, Bid1 = data0.Bid1, Bid2 = data0.Bid2, Bid3 = data0.Bid3, Bid4 = data0.Bid4, Bid5 = data0.Bid5, BidV1 = data0.BidV1, BidV2 = data0.BidV2, BidV3 = data0.BidV3, BidV4 = data0.BidV4, BidV5 = data0.BidV5, Amount = data0.Amount, Code = data0.Code, LastPrice = data0.LastPrice, TransactionDateTime = data0.TransactionDateTime, Volume = data0.Volume, OpenInterest = data0.OpenInterest
                    };
                    modify[i].TransactionDateTime = today + timelist[i];
                }
                if (modify[i] != null)
                {
                    modify[i].TransactionDateTime = today + timelist[i];
                }
            }

            return(modify.ToList());
        }
        private double getOptionSpread(StockOptionTickTransaction tick, double volumeTarget = 10)
        {
            double mid       = tick.Ask1 - tick.Bid1;
            var    askv1     = Math.Min(volumeTarget, tick.AskV1);
            var    askv2     = Math.Max(Math.Min(volumeTarget - askv1, tick.AskV2), 0);
            var    askv3     = Math.Max(Math.Min(volumeTarget - askv1 - askv2, tick.AskV3), 0);
            var    askv4     = Math.Max(Math.Min(volumeTarget - askv1 - askv2 - askv3, tick.AskV4), 0);
            var    askv5     = Math.Max(Math.Min(volumeTarget - askv1 - askv2 - askv3 - askv4, tick.AskV5), 0);
            var    bidv1     = Math.Min(volumeTarget, tick.BidV1);
            var    bidv2     = Math.Max(Math.Min(volumeTarget - bidv1, tick.BidV2), 0);
            var    bidv3     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2, tick.BidV3), 0);
            var    bidv4     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2 - bidv3, tick.BidV4), 0);
            var    bidv5     = Math.Max(Math.Min(volumeTarget - bidv1 - bidv2 - bidv3 - bidv4, tick.BidV5), 0);
            var    askvtotal = askv1 + askv2 + askv3 + askv4 + askv5;
            var    bidvtotal = bidv1 + bidv2 + bidv3 + bidv4 + bidv5;
            var    askMean   = (askv1 * tick.Ask1 + askv2 * tick.Ask2 + askv3 * tick.Ask3 + askv4 * tick.Ask4 + askv5 * tick.Ask5) / askvtotal;
            var    bidMean   = (bidv1 * tick.Bid1 + bidv2 * tick.Bid2 + bidv3 * tick.Bid3 + bidv4 * tick.Bid4 + bidv5 * tick.Bid5) / bidvtotal;

            mid = askMean - bidMean;
            return(mid);
        }
        private List <StockOptionTickTransaction> ConvertToTicks(string code, HashEntry[] hashEntries)
        {
            var ticks = new List <StockOptionTickTransaction>();

            for (int i = 0; i < hashEntries.Length; i++)
            {
                var array = hashEntries[i].Value.ToString().Split(',');
                var tick  = new StockOptionTickTransaction()
                {
                    Code = code,
                    TransactionDateTime = hashEntries[i].Name.ToString().ToDateTime(),
                    LastPrice           = array[0].ConvertTo <double>(),
                    Ask1         = array[1].ConvertTo <double>(),
                    Ask2         = array[2].ConvertTo <double>(),
                    Ask3         = array[3].ConvertTo <double>(),
                    Ask4         = array[4].ConvertTo <double>(),
                    Ask5         = array[5].ConvertTo <double>(),
                    Bid1         = array[6].ConvertTo <double>(),
                    Bid2         = array[7].ConvertTo <double>(),
                    Bid3         = array[8].ConvertTo <double>(),
                    Bid4         = array[9].ConvertTo <double>(),
                    Bid5         = array[10].ConvertTo <double>(),
                    AskV1        = array[11].ConvertTo <double>(),
                    AskV2        = array[12].ConvertTo <double>(),
                    AskV3        = array[13].ConvertTo <double>(),
                    AskV4        = array[14].ConvertTo <double>(),
                    AskV5        = array[15].ConvertTo <double>(),
                    BidV1        = array[16].ConvertTo <double>(),
                    BidV2        = array[17].ConvertTo <double>(),
                    BidV3        = array[18].ConvertTo <double>(),
                    BidV4        = array[19].ConvertTo <double>(),
                    BidV5        = array[20].ConvertTo <double>(),
                    Volume       = array[21].ConvertTo <double>(),
                    Amount       = array[22].ConvertTo <double>(),
                    OpenInterest = array[23].ConvertTo <double>()
                };
                ticks.Add(tick);
            }
            return(ticks);
        }