public IEnumerable <CumulativePositionModel> CumulativePortfolioPosition() { var entities = PortfolioPositionRepository.Query().Include(entity => entity.Portfolio).OrderBy(entity => entity.DateTime) .ToList(); var transactions = Mapper.Map <List <CumulativePositionModel> >(entities); foreach (var group in transactions.GroupBy(entity => new { entity.PortfolioId, entity.Isin })) { var previousAmount = 0m; var previousValue = 0m; foreach (var cumulativePositionModel in group) { cumulativePositionModel.ValuePerItemChange = cumulativePositionModel.CurrentValue - previousValue; cumulativePositionModel.AmountChange = cumulativePositionModel.Amount - previousAmount; previousAmount = cumulativePositionModel.Amount; previousValue = cumulativePositionModel.CurrentValue; } } var transSum = 0m; foreach (var transaction in transactions) { transSum += transaction.CurrentValue * transaction.Amount - (transaction.CurrentValue - transaction.ValuePerItemChange) * (transaction.Amount - transaction.AmountChange); transaction.Cumulative = transSum; } transactions.Reverse(); return(transactions); }
public PortfolioPositionModel DeletePortfolioPosition(long id) { var transaction = PortfolioPositionRepository.GetById(id); PortfolioPositionRepository.Delete(transaction); PortfolioPositionRepository.Save(); return(Mapper.Map <PortfolioPositionModel>(transaction)); }
public IEnumerable <PortfolioPositionModel> GetPortfolioPositionsForPortfolioId(long id) { var positions = PortfolioPositionRepository.GetAllByPortfolioId(id) .GroupBy(entity => entity.Isin) .Select(entities => entities.OrderByDescending(entity => entity.DateTime).FirstOrDefault()).ToList(); return(Mapper.Map <IEnumerable <PortfolioPositionModel> >(positions)); }
public IEnumerable <PortfolioPositionModel> GetAllPortfolioPositions() { var positions = PortfolioPositionRepository.Query() .Include(entity => entity.Portfolio) .GroupBy(entity => new { entity.Isin, entity.Portfolio }) .Select(entities => entities.OrderByDescending(entity => entity.DateTime).FirstOrDefault()) .ToList(); return(Mapper.Map <IEnumerable <PortfolioPositionModel> >(positions)); }
public IEnumerable <PortfolioPositionModel> PortfolioGroupPositions(long portfolioGroupId) { var isins = GetPortfolioGroup(portfolioGroupId).AssignedIsins.ToList(); var positions = PortfolioPositionRepository.Query().Where(model => isins.Contains(model.Isin)) .Include(entity => entity.Portfolio) .GroupBy(entity => new { entity.Isin, entity.Portfolio }) .Select(entities => entities.OrderByDescending(entity => entity.DateTime).FirstOrDefault()) .ToList(); //TODO contains ignore case return(Mapper.Map <IEnumerable <PortfolioPositionModel> >(positions)); }
public PortfolioPositionModel CreatePortfolioSalePosition(PortfolioPositionModel model) { var portfolio = PortfolioRepository.GetById(model.PortfolioId); var otherPosOfIsin = PortfolioPositionRepository .Query() .First(positionEntity => positionEntity.Isin == model.Isin && positionEntity.Name != null); var entity = new SalePositionEntity { Amount = 0, DateTime = model.DateTime, Isin = model.Isin, Name = otherPosOfIsin.Name, CurrentValueCurrencyIso = otherPosOfIsin.CurrentValueCurrencyIso, OriginalValueCurrencyIso = otherPosOfIsin.OriginalValueCurrencyIso, Portfolio = portfolio }; var insertedEntity = PortfolioPositionRepository.Insert(entity); PortfolioPositionRepository.Save(); return(Mapper.Map <PortfolioPositionModel>(insertedEntity)); }