Пример #1
0
        /// <summary>
        /// Generates a random <see cref="Tick"/> that is at most the specified <paramref name="maximumPercentDeviation"/> away from the
        /// previous price and is of the requested <paramref name="tickType"/>
        /// </summary>
        /// <param name="dateTime">The time of the generated tick</param>
        /// <param name="tickType">The type of <see cref="Tick"/> to be generated</param>
        /// <param name="maximumPercentDeviation">The maximum percentage to deviate from the
        /// previous price for example, 1 would indicate a maximum of 1% deviation from the
        /// previous price. For a previous price of 100, this would yield a price between 99 and 101 inclusive</param>
        /// <returns>A random <see cref="Tick"/> value that is within the specified <paramref name="maximumPercentDeviation"/>
        /// from the previous price</returns>
        public virtual Tick NextTick(DateTime dateTime, TickType tickType, decimal maximumPercentDeviation)
        {
            var next = _priceGenerator.NextValue(maximumPercentDeviation, dateTime);
            var tick = new Tick
            {
                Time     = dateTime,
                Symbol   = Symbol,
                TickType = tickType,
                Value    = next
            };

            switch (tickType)
            {
            case TickType.OpenInterest:
                return(NextOpenInterest(dateTime, Security.OpenInterest, maximumPercentDeviation));

            case TickType.Trade:
                tick.Quantity = _random.NextInt(1, 1500);
                return(tick);

            case TickType.Quote:
                var bid = _random.NextPrice(Symbol.SecurityType, Symbol.ID.Market, tick.Value, maximumPercentDeviation);
                if (bid > tick.Value)
                {
                    bid = tick.Value - (bid - tick.Value);
                }
                var ask = _random.NextPrice(Symbol.SecurityType, Symbol.ID.Market, tick.Value, maximumPercentDeviation);
                if (ask < tick.Value)
                {
                    ask = tick.Value + (tick.Value - ask);
                }

                tick.BidPrice = bid;
                tick.BidSize  = _random.NextInt(1, 1500);
                tick.AskPrice = ask;
                tick.AskSize  = _random.NextInt(1, 1500);
                return(tick);

            default:
                throw new ArgumentOutOfRangeException(nameof(tickType), tickType, null);
            }
        }
Пример #2
0
 /// <summary>
 /// Generates an asset price
 /// </summary>
 /// <param name="maximumPercentDeviation">The maximum percent deviation. This value is in percent space,
 ///     so a value of 1m is equal to 1%.</param>
 /// <param name="referenceDate">date used in price calculation</param>
 /// <returns>Returns a new decimal as price</returns>
 public decimal NextValue(decimal maximumPercentDeviation, DateTime referenceDate)
 => _random.NextPrice(_security.Symbol.SecurityType, _security.Symbol.ID.Market, _security.Price, maximumPercentDeviation);