public PortfolioStasticsModel GenerateStasticsModel(AssetsAndLiabilites assetsAndLiabilities) {
            List<AssetBase> assets = assetsAndLiabilities.assets;
            List<LiabilityBase> liabilities = assetsAndLiabilities.liabilities;

            PortfolioStasticsModel model = new PortfolioStasticsModel { data = new List<PortfolioStasticsItem>() };

            List<AssetBase> aeAssets = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList();
            List<AssetBase> ieAssets = assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList();
            List<AssetBase> miAssets = assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList();

            var aeRatios = aeAssets.GetAverageRatiosFor<AustralianEquity>();
            var ieRatios = ieAssets.GetAverageRatiosFor<InternationalEquity>();
            var miRatios = miAssets.GetAverageRatiosFor<ManagedInvestment>();

            model.data.Add(new PortfolioStasticsItem {
                assetClass = edisRepo.GetEnumDescription(AssetTypes.AustralianEquity),
                costInvestment = aeAssets.Sum(a => a.GetCost().Total),
                marketValue = aeAssets.Sum(a => a.GetTotalMarketValue()),
                suitability = aeAssets.GetAssetWeightings().Sum(w => w.Percentage * ((AustralianEquity)w.Weightable).GetRating().TotalScore),
                oneYearReturn = aeRatios.OneYearReturn,
                threeYearReturn = aeRatios.ThreeYearReturn,
                fiveYearReturn = aeRatios.FiveYearReturn,
                earningsPerShare = aeRatios.EarningsStability,
                dividend = aeRatios.DividendYield,
                beta = aeRatios.Beta.ToString(),
                returnOnAsset = aeRatios.ReturnOnAsset,
                returnOnEquity = aeRatios.ReturnOnEquity,
                priceEarningsRatio = aeRatios.PriceEarningRatio,
                avMarketCap = aeRatios.Capitalisation.ToString()
            });

            model.data.Add(new PortfolioStasticsItem {
                assetClass = edisRepo.GetEnumDescription(AssetTypes.InternationalEquity),
                costInvestment = ieAssets.Sum(a => a.GetCost().Total),
                marketValue = ieAssets.Sum(a => a.GetTotalMarketValue()),
                suitability = ieAssets.GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore),
                oneYearReturn = ieRatios.OneYearReturn,
                threeYearReturn = ieRatios.ThreeYearReturn,
                fiveYearReturn = ieRatios.FiveYearReturn,
                earningsPerShare = ieRatios.EarningsStability,
                dividend = ieRatios.DividendYield,
                beta = ieRatios.Beta.ToString(),
                returnOnAsset = ieRatios.ReturnOnAsset,
                returnOnEquity = ieRatios.ReturnOnEquity,
                priceEarningsRatio = ieRatios.PriceEarningRatio,
                avMarketCap = ieRatios.Capitalisation.ToString()
            });

            model.data.Add(new PortfolioStasticsItem {
                assetClass = edisRepo.GetEnumDescription(AssetTypes.ManagedInvestments),
                costInvestment = miAssets.Sum(a => a.GetCost().Total),
                marketValue = miAssets.Sum(a => a.GetTotalMarketValue()),
                suitability = miAssets.GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore),
                oneYearReturn = miRatios.OneYearReturn,
                threeYearReturn = miRatios.ThreeYearReturn,
                fiveYearReturn = miRatios.FiveYearReturn,
                earningsPerShare = miRatios.EarningsStability,
                dividend = miRatios.DividendYield,
                beta = miRatios.Beta.ToString(),
                returnOnAsset = miRatios.ReturnOnAsset,
                returnOnEquity = miRatios.ReturnOnEquity,
                priceEarningsRatio = miRatios.PriceEarningRatio,
                avMarketCap = miRatios.Capitalisation.ToString()
            });


            foreach (var item in model.data) {
                item.pl = item.marketValue - item.costInvestment;
                item.plp = item.costInvestment == 0 ? 0 : (item.marketValue - item.costInvestment) / item.costInvestment;
            }
            return model;
        }
        public PortfolioStasticsModel GetStastics_Client()
        {
            Client client = edisRepo.GetClientSync(User.Identity.GetUserId(), DateTime.Now);
            ClientGroup clientGroup = edisRepo.GetClientGroupSync(client.ClientGroupId, DateTime.Now);
            if (clientGroup.MainClientId == client.Id)
            {
                List<GroupAccount> groupAccounts = edisRepo.GetAccountsForClientGroupSync(clientGroup.ClientGroupNumber, DateTime.Now);
                List<ClientAccount> clientAccounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now);

                PortfolioStasticsModel model = new PortfolioStasticsModel { data = new List<PortfolioStasticsItem>() };

                List<AssetBase> assets = new List<AssetBase>();
                List<LiabilityBase> liabilities = new List<LiabilityBase>();
                foreach (var account in groupAccounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }
                foreach (var account in clientAccounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }

                List<AssetBase> aeAssets = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList();
                List<AssetBase> ieAssets = assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList();
                List<AssetBase> miAssets = assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList();

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "Australian Equity",
                    costInvestment = aeAssets.Sum(a => a.GetCost().Total),
                    marketValue = aeAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = aeAssets.GetAssetWeightings().Sum(w => w.Percentage * ((AustralianEquity)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().OneYearReturn,
                    threeYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().ThreeYearReturn,
                    fiveYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().FiveYearReturn,
                    earningsPerShare = assets.GetAverageRatiosFor<AustralianEquity>().EarningsStability,
                    dividend = assets.GetAverageRatiosFor<AustralianEquity>().DividendYield,
                    beta = assets.GetAverageRatiosFor<AustralianEquity>().Beta.ToString(),
                    returnOnAsset = assets.GetAverageRatiosFor<AustralianEquity>().ReturnOnAsset,
                    returnOnEquity = assets.GetAverageRatiosFor<AustralianEquity>().ReturnOnEquity,
                    priceEarningsRatio = assets.GetAverageRatiosFor<AustralianEquity>().PriceEarningRatio,
                    avMarketCap = assets.GetAverageRatiosFor<AustralianEquity>().Capitalisation.ToString()
                });

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "International Equity",
                    costInvestment = ieAssets.Sum(a => a.GetCost().Total),
                    marketValue = ieAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = ieAssets.GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().OneYearReturn,
                    threeYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().ThreeYearReturn,
                    fiveYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().FiveYearReturn,
                    earningsPerShare = ieAssets.GetAverageRatiosFor<InternationalEquity>().EarningsStability,
                    dividend = ieAssets.GetAverageRatiosFor<InternationalEquity>().DividendYield,
                    beta = ieAssets.GetAverageRatiosFor<InternationalEquity>().Beta.ToString(),
                    returnOnAsset = ieAssets.GetAverageRatiosFor<InternationalEquity>().ReturnOnAsset,
                    returnOnEquity = ieAssets.GetAverageRatiosFor<InternationalEquity>().ReturnOnEquity,
                    priceEarningsRatio = ieAssets.GetAverageRatiosFor<InternationalEquity>().PriceEarningRatio,
                    avMarketCap = ieAssets.GetAverageRatiosFor<InternationalEquity>().Capitalisation.ToString()
                });

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "Managed Investment",
                    costInvestment = miAssets.Sum(a => a.GetCost().Total),
                    marketValue = miAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = miAssets.GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().OneYearReturn,
                    threeYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().ThreeYearReturn,
                    fiveYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().FiveYearReturn,
                    earningsPerShare = miAssets.GetAverageRatiosFor<ManagedInvestment>().EarningsStability,
                    dividend = miAssets.GetAverageRatiosFor<ManagedInvestment>().DividendYield,
                    beta = miAssets.GetAverageRatiosFor<ManagedInvestment>().Beta.ToString(),
                    returnOnAsset = miAssets.GetAverageRatiosFor<ManagedInvestment>().ReturnOnAsset,
                    returnOnEquity = miAssets.GetAverageRatiosFor<ManagedInvestment>().ReturnOnEquity,
                    priceEarningsRatio = miAssets.GetAverageRatiosFor<ManagedInvestment>().PriceEarningRatio,
                    avMarketCap = miAssets.GetAverageRatiosFor<ManagedInvestment>().Capitalisation.ToString()
                });

                foreach (var item in model.data)
                {
                    item.pl = item.marketValue - item.costInvestment;
                    item.plp = item.costInvestment == 0 ? 0 : (item.marketValue - item.costInvestment) / item.costInvestment;
                }

                return model;
            }
            else
            {
                List<ClientAccount> accounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now);

                PortfolioStasticsModel model = new PortfolioStasticsModel { data = new List<PortfolioStasticsItem>() };

                List<AssetBase> assets = new List<AssetBase>();
                List<LiabilityBase> liabilities = new List<LiabilityBase>();
                foreach (var account in accounts)
                {
                    assets.AddRange(account.GetAssetsSync());
                    liabilities.AddRange(account.GetLiabilitiesSync());
                }

                List<AssetBase> aeAssets = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList();
                List<AssetBase> ieAssets = assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList();
                List<AssetBase> miAssets = assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList();

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "Australian Equity",
                    costInvestment = aeAssets.Sum(a => a.GetCost().Total),
                    marketValue = aeAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = aeAssets.GetAssetWeightings().Sum(w => w.Percentage * ((AustralianEquity)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().OneYearReturn,
                    threeYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().ThreeYearReturn,
                    fiveYearReturn = assets.GetAverageRatiosFor<AustralianEquity>().FiveYearReturn,
                    earningsPerShare = assets.GetAverageRatiosFor<AustralianEquity>().EarningsStability,
                    dividend = assets.GetAverageRatiosFor<AustralianEquity>().DividendYield,
                    beta = assets.GetAverageRatiosFor<AustralianEquity>().Beta.ToString(),
                    returnOnAsset = assets.GetAverageRatiosFor<AustralianEquity>().ReturnOnAsset,
                    returnOnEquity = assets.GetAverageRatiosFor<AustralianEquity>().ReturnOnEquity,
                    priceEarningsRatio = assets.GetAverageRatiosFor<AustralianEquity>().PriceEarningRatio,
                    avMarketCap = assets.GetAverageRatiosFor<AustralianEquity>().Capitalisation.ToString()
                });

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "International Equity",
                    costInvestment = ieAssets.Sum(a => a.GetCost().Total),
                    marketValue = ieAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = ieAssets.GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().OneYearReturn,
                    threeYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().ThreeYearReturn,
                    fiveYearReturn = ieAssets.GetAverageRatiosFor<InternationalEquity>().FiveYearReturn,
                    earningsPerShare = ieAssets.GetAverageRatiosFor<InternationalEquity>().EarningsStability,
                    dividend = ieAssets.GetAverageRatiosFor<InternationalEquity>().DividendYield,
                    beta = ieAssets.GetAverageRatiosFor<InternationalEquity>().Beta.ToString(),
                    returnOnAsset = ieAssets.GetAverageRatiosFor<InternationalEquity>().ReturnOnAsset,
                    returnOnEquity = ieAssets.GetAverageRatiosFor<InternationalEquity>().ReturnOnEquity,
                    priceEarningsRatio = ieAssets.GetAverageRatiosFor<InternationalEquity>().PriceEarningRatio,
                    avMarketCap = ieAssets.GetAverageRatiosFor<InternationalEquity>().Capitalisation.ToString()
                });

                model.data.Add(new PortfolioStasticsItem
                {
                    assetClass = "Managed Investment",
                    costInvestment = miAssets.Sum(a => a.GetCost().Total),
                    marketValue = miAssets.Sum(a => a.GetTotalMarketValue()),
                    suitability = miAssets.GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore),
                    oneYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().OneYearReturn,
                    threeYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().ThreeYearReturn,
                    fiveYearReturn = miAssets.GetAverageRatiosFor<ManagedInvestment>().FiveYearReturn,
                    earningsPerShare = miAssets.GetAverageRatiosFor<ManagedInvestment>().EarningsStability,
                    dividend = miAssets.GetAverageRatiosFor<ManagedInvestment>().DividendYield,
                    beta = miAssets.GetAverageRatiosFor<ManagedInvestment>().Beta.ToString(),
                    returnOnAsset = miAssets.GetAverageRatiosFor<ManagedInvestment>().ReturnOnAsset,
                    returnOnEquity = miAssets.GetAverageRatiosFor<ManagedInvestment>().ReturnOnEquity,
                    priceEarningsRatio = miAssets.GetAverageRatiosFor<ManagedInvestment>().PriceEarningRatio,
                    avMarketCap = miAssets.GetAverageRatiosFor<ManagedInvestment>().Capitalisation.ToString()
                });

                foreach (var item in model.data)
                {
                    item.pl = item.marketValue - item.costInvestment;
                    item.plp = item.costInvestment == 0 ? 0 : (item.marketValue - item.costInvestment) / item.costInvestment;
                }
                return model;
            }
        }