Example #1
0
        public void RecalculateRootModel(
            RootModel root,
            ISqlConnectionFactory connectionFactory,
            IDataManagerFactory dataManagerFactory,
            CalculationTicket ticket
            )
        {
            // everything is recalculated automatically but overlays in case they were changed
#warning it's a big question whether overlays need to be recalculated every time
#warning we need to see if somebody has changed PST composition since we opened for editing but haven't yet saved

            SecurityRepository  securityRepository;
            PortfolioRepository portfolioRepository;
            ManagingPst.PortfolioSecurityTargetRepository portfolioSecurityTargetRepository;
            using (var ondemandManager = new OnDemandDataManager(connectionFactory, dataManagerFactory))
            {
                securityRepository  = this.repositoryManager.ClaimSecurityRepository(ondemandManager);
                portfolioRepository = this.repositoryManager.ClaimPortfolioRepository(ondemandManager);
                portfolioSecurityTargetRepository = this.repositoryManager.ClaimPortfolioSecurityTargetRepository(
                    root.LatestPstChangeset,
                    ondemandManager.Claim()
                    );


                // in order to proceed we need to make sure all missing countries are there
                IEnumerable <BenchmarkSumByIsoInfo> benchmarks = new BenchmarkSumByIsoInfo[] { };
                var computations            = this.modelBuilder.CreateComputations(root.Globe, this.Traverser);
                var countryRepository       = this.repositoryManager.ClaimCountryRepository(ondemandManager);
                var targetingTypeRepository = this.repositoryManager.ClaimTargetingTypeRepository(ondemandManager);
                var targetingType           = targetingTypeRepository.GetTargetingType(root.TargetingType.Id);
                this.RegisterMissingCountriesIfAny(
                    root,
                    computations,
                    countryRepository,
                    targetingType,
                    securityRepository,
                    portfolioRepository,
                    portfolioSecurityTargetRepository,
                    benchmarks
                    );
            }


            this.InitializeOverlay(
                root,
                securityRepository,
                portfolioRepository,
                portfolioSecurityTargetRepository
                );

            // required to inject problems to base values
            // we are not interested in the result of validation
            this.modelApplier.ValidateModel(root, ticket);
        }
Example #2
0
        public ManagingBpt.RootModel GetRootModel(
            Int32 targetingTypeId,
            String portfolioId,
            Boolean shouldBenchmarksBeInitialized,
            IDataManager manager,
            String username
            )
        {
            ManagingBpt.RootModel result;
            // getting targeting, taxonomy, base values, overlays data from the database

            var countryRepository       = this.repositoryManager.ClaimCountryRepository(manager);
            var targetingTypeRepository = this.repositoryManager.ClaimTargetingTypeRepository(manager);
            var targetingType           = targetingTypeRepository.GetTargetingType(targetingTypeId);

            var baseValueResolver   = this.CreateBaseValueResolver(manager, targetingType.Id);
            var securityRepository  = this.repositoryManager.ClaimSecurityRepository(manager);
            var portfolioRepository = this.repositoryManager.ClaimPortfolioRepository(manager);

            var overlayModel = this.overlayManager.GetOverlayModel(
                targetingType,
                portfolioId,
                portfolioRepository,
                securityRepository,
                manager
                );

            var latestTtbbvChangesetInfo = manager.GetLatestTargetingTypeBasketBaseValueChangeset();
            var latestTtbptChangesetInfo = manager.GetLatestTargetingTypeBasketPortfolioTargetChangeset();
            var latestPstoChangesetInfo  = manager.GetLatestBgaPortfolioSecurityFactorChangeset();
            var latestPstChangesetInfo   = manager.GetLatestPortfolioSecurityTargetChangeSet();

            var portfolioSecurityTargetRepository = this.repositoryManager.ClaimPortfolioSecurityTargetRepository(latestPstChangesetInfo, manager);

            var residents    = new List <IGlobeResident>();
            var globe        = this.modelBuilder.CreateGlobeModel(residents);
            var computations = this.modelBuilder.CreateComputations(globe, this.Traverser);

            foreach (var node in targetingType.Taxonomy.GetResidents())
            {
                var resident = this.taxonomyTransformer.CreateModelOnceResolved(computations, node);
                residents.Add(resident);
            }

            var cash = this.modelBuilder.CreateCash(computations);
            var portfolioScaledGrandTotal = this.modelBuilder.CreateAddExpression(cash.PortfolioScaled, globe.PortfolioScaled);
            var trueExposureGrandTotal    = this.modelBuilder.CreateAddExpression(cash.TrueExposure, globe.TrueExposure);
            var trueActiveGrandTotal      = this.modelBuilder.CreateAddExpression(cash.TrueActive, globe.TrueActive);
            var portfolio             = portfolioRepository.GetBroadGlobalActivePortfolio(portfolioId);
            var benchmarkDate         = manager.GetLastestDateWhichBenchmarkDataIsAvialableOn();
            var isUserPermittedToSave = manager.IsSavePermittedForBGAUser(username);

            result = new RootModel(
                targetingType,
                portfolio,
                latestTtbbvChangesetInfo,
                latestTtbptChangesetInfo,
                latestPstoChangesetInfo,
                latestPstChangesetInfo,
                globe,
                cash,
                overlayModel,
                portfolioScaledGrandTotal,
                trueExposureGrandTotal,
                trueActiveGrandTotal,
                benchmarkDate,
                isUserPermittedToSave
                );

            // populating the base and portfolio adjustment columsn first as they don't depend on potentially missing countries
            this.baseValueInitializer.Initialize(result, baseValueResolver);
            this.portfolioAdjustmentInitializer.InitializePortfolioAdjustments(result, manager);

            // in order to proceed we need to make sure all missing countries are there
            IEnumerable <BenchmarkSumByIsoInfo> benchmarks = new BenchmarkSumByIsoInfo[] { };

            // here is the deal with shouldBenchmarksBeInitialized:
            // when we are editing broad-global-avive composition we need benchmakrs for reference and in order to make sure all countries are considered
            // but when the hopper process  runs we don't need additional counties from bechmakr that can mess around and prevent the hopper from running
            // so this is why we need this switch
            if (shouldBenchmarksBeInitialized)
            {
                var benchmarkRepository = this.repositoryManager.ClaimBenchmarkRepository(manager, benchmarkDate);
                benchmarks = benchmarkRepository.GetByBenchmarkId(targetingType.BenchmarkIdOpt);
            }

            this.RegisterMissingCountriesIfAny(
                result,
                computations,
                countryRepository,
                targetingType,
                securityRepository,
                portfolioRepository,
                portfolioSecurityTargetRepository,
                benchmarks
                );

            // now we can initialize columns that require all missing countries to be in the model
            this.InitializeOverlay(
                result,
                securityRepository,
                portfolioRepository,
                portfolioSecurityTargetRepository
                );
            this.benchmarkValueInitializer.Initialize(result, new BenchmarkValueResolver(benchmarks));



            var ticket = new CalculationTicket();

            this.Validate(result, ticket);
            return(result);
        }