Ejemplo n.º 1
0
        public void ProbabilityCalculationTest()
        {
            var calculator = new SpreadCalculator();

            var maxProbability = calculator.CalculateNormalDistribution(7, 7);

            Assert.Equal(1.0, maxProbability, 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public object FunctionHandler(InputModel input, ILambdaContext context)
        {
            if (input == null)
            {
                return(new List <int> {
                    42
                });
            }

            if (input.WorkStart > input.BusiestHour || input.BusiestHour > input.WorkEnd)
            {
                return(new List <int>());
            }

            var weightCalculator = new WeightCalculator();
            var spreadCalculator = new SpreadCalculator();

            var weights = weightCalculator.Calculate(input);
            var spread  = spreadCalculator.Calculate(input, weights);

            return(spread);
        }
Ejemplo n.º 3
0
        public void SpreadCalculateWithStaticWeightsTest()
        {
            var calculator = new SpreadCalculator();

            var input = new InputModel
            {
                WorkStart   = 9,
                WorkEnd     = 18,
                BusiestHour = 16
            };
            var weights = Enumerable.Repeat(1.0, 9).ToList();

            var customersForMonth = Enumerable.Repeat(0, 1000)
                                    .Select(x => calculator.Calculate(input, weights));

            //customers per hour. indicating number of customers from the interval start time till the next interval
            //9 - .5 - 10 - .5 - 11 - .5 - 12 - .5 - 13 - .5 - 14 - .5 - 15 - .5 - 16 - .5 - 17 - .5
            Assert.All(customersForMonth, (spread) => Assert.Equal(18, spread.Count));

            var totalCustomersPerDay = customersForMonth.Select(spread => spread.Sum());

            Assert.True(Math.Abs(13 - totalCustomersPerDay.Average()) < 0.5);
        }
        public static OrderExecutionOrderBook ToDomain(this OrderExecutionOrderBookContract contract)
        {
            var orderBook = new OrderExecutionOrderBook
            {
                OrderId         = contract.OrderId,
                ExternalOrderId = contract.ExternalOrderId,
                OrderBook       = new ExternalOrderBook
                {
                    ExchangeName = contract.OrderBook.ExchangeName,
                    AssetPairId  = contract.OrderBook.AssetPairId,
                    Timestamp    = contract.OrderBook.Timestamp,
                    Asks         = contract.OrderBook.Asks.Select(x => new VolumePrice {
                        Volume = x.Volume, Price = x.Price
                    }).ToList(),
                    Bids = contract.OrderBook.Bids.Select(x => new VolumePrice {
                        Volume = x.Volume, Price = x.Price
                    }).ToList(),
                },
            };

            orderBook.Spread = SpreadCalculator.CalculateSpread(orderBook, contract.Volume);

            return(orderBook);
        }
 public decimal Spread_Calculation_Success(OrderExecutionOrderBook orderExecutionOrderBook, decimal volume)
 {
     return(SpreadCalculator.CalculateSpread(orderExecutionOrderBook, volume));
 }