예제 #1
0
        public void ValuePositions(List <Portfolio> portfolios, List <PriceValue> prices, int valuationId)
        {
            DateTime valuationTime = prices[0].PriceDate;

            ValuationTime = valuationTime;
            //delete any valuations that exists with the same valuationTime
            _valuationDetailRepo.Delete(valuationId, ValuationTime);
            _valuationRepo.SaveChanges();


            foreach (Portfolio p in portfolios)
            {
                foreach (PortfolioPosition pp in p.PortfolioPositions)
                {
                    ValuationDetail vDetail = new ValuationDetail();
                    vDetail.PortfolioId         = pp.PortfolioId;
                    vDetail.ValuationId         = valuationId;
                    vDetail.ValuationTime       = valuationTime;
                    vDetail.PortfolioPositionId = pp.Id;
                    vDetail.Quantity            = pp.Quantity;
                    vDetail.Price          = prices.Where(x => x.Symbol == pp.Symbol.Trim()).FirstOrDefault().Price;
                    vDetail.IntradayChange = prices.Where(x => x.Symbol == pp.Symbol.Trim()).FirstOrDefault().IntradayChange;
                    vDetail.PositionValue  = vDetail.Quantity * vDetail.Price;
                    _valuationDetailRepo.Insert(vDetail);
                    _valuationDetailRepo.SaveChanges();
                }
            }
            ValuationStatus = "Success";
        }
        public void InsertValuationDetailTest()
        {
            ValuationDetailRepo _repo = new ValuationDetailRepo();

            ValuationDetail vDetail = new ValuationDetail();

            vDetail.ValuationId         = 1000;
            vDetail.ValuationTime       = DateTime.Now;
            vDetail.PortfolioPositionId = 1;
            vDetail.PortfolioId         = 100;
            vDetail.PositionValue       = 35000;
            vDetail.Quantity            = 500;

            _repo.Insert(vDetail);
            _repo.SaveChanges();
        }