private DataFrame CreateFlowTable(List <Trade> allTrades)
        {
            int otherlength = allTrades.Count;
            PrimitiveDataFrameColumn <DateTime> flowDate  = new PrimitiveDataFrameColumn <DateTime>("date", otherlength);
            PrimitiveDataFrameColumn <decimal>  cashCol   = new PrimitiveDataFrameColumn <decimal>("cash", otherlength);
            PrimitiveDataFrameColumn <decimal>  inflowCol = new PrimitiveDataFrameColumn <decimal>("inflow", otherlength);
            DataFrame flowFrame     = new DataFrame(flowDate, cashCol, inflowCol);
            int       rowRef        = 0;
            decimal   lastcashvalue = Decimal.Zero; // cumsum for cash column

            foreach (Trade trade in allTrades)
            {
                decimal TradeAmount = trade.Quantity * trade.Price;
                flowFrame[rowRef, 0] = trade.TradeDate;
                if (TradeAmount > 0)
                {
                    //trade is a purchase, set inflow
                    flowFrame[rowRef, 1] = lastcashvalue;
                    flowFrame[rowRef, 2] = TradeAmount;
                }
                else
                {
                    //trade is a sell, set cash
                    flowFrame[rowRef, 1] = Math.Abs(TradeAmount) + lastcashvalue;
                    lastcashvalue        = (decimal)flowFrame[rowRef, 1];
                    flowFrame[rowRef, 2] = Decimal.Zero;
                }
                rowRef++;
            }
            GroupBy groupBy = flowFrame.GroupBy("date");

            flowFrame = groupBy.Sum();
            return(flowFrame);
        }
Ejemplo n.º 2
0
        public object MarcasVendida(int ano)
        {
            var listaVendas = db.Vendas.ToList();
            var listaCarros = db.Carros.ToList();
            var listaMarcas = db.Marcas.ToList();

            var retornoCarros = from ven in listaVendas
                                join car in listaCarros on ven.Carro equals car.Id
                                join mar in listaMarcas on car.Marca equals mar.Id
                                where ven.DatInc.Year == ano
                                group ven by ven.Carros.Marcas into GroupBy
                                select new
            {
                Marcas     = GroupBy.Key.Nome,
                Quantidade = GroupBy.Sum(x => x.Quantidade)
            };

            return(retornoCarros);
        }