示例#1
0
        public Core.RootModel DeserializeRoot(RootModel model)
        {
            var targetingTypeGroup  = this.deserializer.DeserializeTargetingTypeGroup(model.TargetingTypeGroup);
            var benchmarkRepository = this.deserializer.ClaimBenchmarkRepository(model.BenchmarkDate);
            var basket     = this.deserializer.DeserializeBasket(model.Basket.Id);
            var securities = this.DeserializeSecurities(model.Securities).ToList();

            if (model.SecurityToBeAddedOpt != null)
            {
                var security = this.DeserializeAdditionalSecurity(
                    basket,
                    model.SecurityToBeAddedOpt,
                    targetingTypeGroup,
                    benchmarkRepository
                    );
                if (!securities.Where(x => x.Security.Id == security.Security.Id).Any())
                {
                    securities.Add(security);
                }
            }
            var baseTotalExpression       = this.modelBuilder.CreateBaseTotalExpression(securities);
            var benchmarkTotalExpression  = this.modelBuilder.CreateBenchmarkTotalExpression(securities);
            var baseActiveTotalExpression = this.modelBuilder.CreateBaseActiveTotalExpression(securities);
            var core = new Core.CoreModel(
                targetingTypeGroup,
                basket,
                this.DeserializePortfolios(model.Portfolios, securities),
                securities,
                baseTotalExpression,
                benchmarkTotalExpression,
                baseActiveTotalExpression
                );

            var result = new Core.RootModel(
                this.DeserializeTargetingTypeGroupBasketSecurityBaseValueChangeset(model.LatestBaseChangeset),
                this.DeserializeBasketPortfolioSecurityTargetChangesetInfo(model.LatestPortfolioTargetChangeset),
                core,
                model.BenchmarkDate
                );

            return(result);
        }
        public RootModel DeserializeRoot(
            JsonReader reader,
            SecurityRepository securityRepository,
            ManagingTargetingTypes.TargetingTypeGroupRepository targetingTypeGroupRepository,
            ManagingBaskets.BasketRepository basketRepository,
            PortfolioRepository portfolioRepository,
            RepositoryManager repositoryManager,
            IOnDemand <IDataManager> ondemandManager
            )
        {
            var latestBaseChangeset = reader.Read(JsonNames.LatestBaseChangeset, delegate
            {
                return(this.DeserializeLatestBaseChangeset(reader));
            });

            var latestPortfolioTargetChangeset = reader.Read(JsonNames.LatestPortfolioTargetChangeset, delegate
            {
                return(this.DeserializeLatestPortfolioTargetChangeset(reader));
            });

            var targetingTypeGroupId = reader.ReadAsInt32(JsonNames.TargetingTypeGroupId);
            var targetingTypeGroup   = targetingTypeGroupRepository.GetTargetingTypeGroup(targetingTypeGroupId);

            var basketId      = reader.ReadAsInt32(JsonNames.BasketId);
            var basket        = basketRepository.GetBasket(basketId);
            var benchmarkDate = reader.ReadAsDatetime(JsonNames.BenchmarkDate);

            var securityModels = reader.ReadArray("securities", delegate
            {
                var securityModel = this.DeserializeSecurity(
                    reader,
                    securityRepository,
                    portfolioRepository
                    );
                return(securityModel);
            }).ToList();

            // adding a new security if any
            var securityIdTobeAddedOpt = reader.ReadAsNullableString(JsonNames.SecurityIdTobeAdded);

            if (securityIdTobeAddedOpt != null)
            {
                var broadGlobalActivePortfolios = targetingTypeGroup.GetBgaPortfolios();
                var security             = securityRepository.GetSecurity(securityIdTobeAddedOpt);
                var baseExpression       = this.modelBuilder.CreateBaseExpression();
                var benchmarkExpression  = this.modelBuilder.CreateBenchmarkExpression();
                var baseActiveExpression = this.modelBuilder.CreateBaseActiveExpression(baseExpression, benchmarkExpression);
                var securityModel        = new SecurityModel(
                    security,
                    baseExpression,
                    benchmarkExpression,
                    broadGlobalActivePortfolios.Select(bgaPortfolio => new PortfolioTargetModel(
                                                           bgaPortfolio,
                                                           this.modelBuilder.CreatePortfolioTargetExpression(bgaPortfolio.Name)
                                                           )).ToArray(),
                    baseActiveExpression
                    );

                if (!String.IsNullOrWhiteSpace(targetingTypeGroup.BenchmarkIdOpt))
                {
                    var benchmarkRepository = this.repositoryManager.ClaimBenchmarkRepository(ondemandManager, benchmarkDate);
                    this.benchmarkInitializer.InitializeSecurity(basket, targetingTypeGroup.BenchmarkIdOpt, securityModel, benchmarkRepository);
                }
                securityModels.Add(securityModel);
            }


            var portfolios = reader.ReadArray(JsonNames.Portfolios, delegate
            {
                var portfolioId = reader.ReadAsString(JsonNames.Id);
                var portfolio   = portfolioRepository.GetBroadGlobalActivePortfolio(portfolioId);
                var portfolioTargetTotalExpression = this.modelBuilder.CreatePortfolioTargetTotalExpression(
                    portfolio,
                    securityModels
                    );
                return(new PortfolioModel(
                           portfolio,
                           portfolioTargetTotalExpression
                           ));
            });

            var baseTotalExpression       = this.modelBuilder.CreateBaseTotalExpression(securityModels);
            var benchmarkTotalExpression  = this.modelBuilder.CreateBenchmarkTotalExpression(securityModels);
            var baseActiveTotalExpression = this.modelBuilder.CreateBaseActiveTotalExpression(securityModels);

            //var targetingTypeGroup = targetingTypeGroupRepository.Get
            var core = new CoreModel(
                targetingTypeGroup,
                basket,
                portfolios,
                securityModels,
                baseTotalExpression,
                benchmarkTotalExpression,
                baseActiveTotalExpression
                );

            var result = new RootModel(
                latestBaseChangeset,
                latestPortfolioTargetChangeset,
                core,
                benchmarkDate
                );

            return(result);
        }
示例#3
0
        public IEnumerable <IValidationIssue> Validate(CoreModel model, CalculationTicket ticket)
        {
            var issues = this.modelValidator.ValidateCore(model, ticket);

            return(issues);
        }