Ejemplo n.º 1
0
        public IDictionary <int, PnLState> Process(int poolSize)
        {
            //Process Single Tickets in the memory
            var watch = System.Diagnostics.Stopwatch.StartNew();

            eventReceiver.Receive(allUpTickets, matchResults, poolSize);

            // the code that you want to measure comes here
            watch.Stop();
            Console.WriteLine("Time Elapsed in ms for Receiving events :  " + watch.ElapsedMilliseconds);
            int matchPlayed = 0;

            while (matchResults.Count > matchPlayed)
            {
                watch.Restart();
                Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " After match " + matchPlayed + " All Up Tickets Unprocessed : " + allUpTickets.Count);
                foreach (AllUpTicket allUpTicket in allUpTickets)
                {
                    foreach (Leg leg in allUpTicket.Legs)
                    {
                        if (leg.PoolId == matchResults[matchPlayed].PoolId)
                        {
                            SingleTicket ticket = reducer.Reduce(allUpTicket, leg);
                            scenarioGenerator.Generate(mutator, sourcer, pnLConsumer, ticket);
                        }
                    }
                }
                watch.Stop();
                Console.WriteLine("Time Elapsed in ms for Generating the single tickets of match number " + matchPlayed + " :  " + watch.ElapsedMilliseconds);
                watch.Restart();
                scenarioGenerator.Pick(mutator, sourcer, pnLConsumer, matchResults[matchPlayed]);
                reducer.Advance(allUpTickets, matchResults[matchPlayed]);
                matchPlayed++;
                watch.Stop();
                Console.WriteLine("Time Elapsed in ms for Resolving the single tickets of match number " + matchPlayed + " :  " + watch.ElapsedMilliseconds);
            }

            //6. Query Dividend
            pnLConsumer.PrintAllInvestment();
            pnLConsumer.PrintAllDividend();
            pnLConsumer.PrintAllRefund();


            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Emitted : " + mutator.HighWaterMark);
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Processed : " + pnLConsumer.GetHighWaterMark());
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Remaining All Up Tickets Unprocessed : " + allUpTickets.Count);

            return(pnLConsumer.GetPnL());
        }
Ejemplo n.º 2
0
        public IDictionary <int, PnLState> Process(int poolSize)
        {
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Event Sourcing : first pool 71000001 win and second pool 71000004 lose");
            //A. Receive 1 million bets and win the pool

            for (int i = 1; i < poolSize + 1; i++)
            {
                // 1. Flowing state in the form of ticket bets coming in
                SingleTicket ticket = new SingleTicket
                {
                    TicketId = "17_2_1_" + (410100000 + i).ToString(),
                    BetId    = 1,
                    LegNo    = 1,
                    Odds     = 1.5m,
                    UnitBets = 0.1m,
                    PoolId   = 71000001
                };

                //2. Produce all Ticket Mutations on PnL based on Pool's Win Scenario
                Mutation ticketMutationWin    = mutator.GetTicketMutation(ticket, Result.WIN);
                Mutation ticketMutationLoss   = mutator.GetTicketMutation(ticket, Result.LOSS);
                Mutation ticketMutationDraw   = mutator.GetTicketMutation(ticket, Result.DRAW);
                Mutation ticketMutationRefund = mutator.GetTicketMutation(ticket, Result.REFUND);

                //3. Source the events
                sourcer.Source(ticketMutationWin);
                sourcer.Source(ticketMutationLoss);
                sourcer.Source(ticketMutationDraw);
                sourcer.Source(ticketMutationRefund);

                //4. Apply the mutation on the system state
                pnLConsumer.Consume(ticketMutationWin);
                pnLConsumer.Consume(ticketMutationLoss);
                pnLConsumer.Consume(ticketMutationDraw);
                pnLConsumer.Consume(ticketMutationRefund);
            }

            //5. Pool Result arrives and is consumed
            Mutation matchMutation = mutator.GetMatchMutation(Result.WIN, 71000001);

            sourcer.Source(matchMutation);
            pnLConsumer.Consume(matchMutation);

            //6. Query Dividend
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Aggregatged Dividend for pool 71000001 : " + pnLConsumer.QueryDividend(71000001));
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Aggregatged Refund for pool 71000001 : " + pnLConsumer.QueryRefund(71000001));
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Emitted : " + mutator.HighWaterMark);
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Processed : " + pnLConsumer.GetHighWaterMark());

            ////B. Receive 1 million bets and lose the pool

            for (int i = poolSize + 1; i < (poolSize * 2) + 1; i++)
            {
                // 1. Flowing state in the form of ticket bets coming in
                SingleTicket ticket = new SingleTicket
                {
                    TicketId = "17_2_1_" + (410100000 + i).ToString(),
                    BetId    = 1,
                    LegNo    = 1,
                    Odds     = 1.5m,
                    UnitBets = 0.1m,
                    PoolId   = 71000004
                };

                //2. Produce all Ticket Mutations on PnL based on Pool's Win Scenario
                Mutation ticketMutationWin    = mutator.GetTicketMutation(ticket, Result.WIN);
                Mutation ticketMutationLoss   = mutator.GetTicketMutation(ticket, Result.LOSS);
                Mutation ticketMutationDraw   = mutator.GetTicketMutation(ticket, Result.DRAW);
                Mutation ticketMutationRefund = mutator.GetTicketMutation(ticket, Result.REFUND);

                //3. Source the events
                sourcer.Source(ticketMutationWin);
                sourcer.Source(ticketMutationLoss);
                sourcer.Source(ticketMutationDraw);
                sourcer.Source(ticketMutationRefund);

                //4. Apply the mutation on the system state
                pnLConsumer.Consume(ticketMutationWin);
                pnLConsumer.Consume(ticketMutationLoss);
                pnLConsumer.Consume(ticketMutationDraw);
                pnLConsumer.Consume(ticketMutationRefund);
            }

            //5. Pool Result arrives and is consumed
            pnLConsumer.Consume(mutator.GetMatchMutation(Result.LOSS, 71000004));

            //6. Query Dividend
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Aggregatged Dividend Payout for pool 71000004 : " + pnLConsumer.QueryDividend(71000004));
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " Aggregatged Refund Payout for pool 71000004 : " + pnLConsumer.QueryRefund(71000004));
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Emitted : " + mutator.HighWaterMark);
            Console.WriteLine("At Thread " + Thread.CurrentThread.ManagedThreadId + " High Water Mark Processed : " + pnLConsumer.GetHighWaterMark());
            return(pnLConsumer.GetPnL());
        }