public PortfolioRatingModel GenerateRatingsModel(List<AssetBase> assets) { List<InternationalEquity> equityWithResearchValues = assets.OfType<InternationalEquity>().ToList(); var weightings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); double assetsSuitability = weightings.Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore); double percentage = equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); PortfolioRatingModel model = new PortfolioRatingModel { suitability = assetsSuitability, notSuited = percentage, data = new List<PortfolioRatingItemModel>() }; foreach (var weighting in weightings) { Equity equity = (Equity)weighting.Weightable; if (model.data.Any(m => m.name == equity.Ticker) == false) { model.data.Add(new PortfolioRatingItemModel { name = equity.Ticker, weighting = weighting.Percentage, score = equity.GetRating().TotalScore }); } } return model; }
public PortfolioRatingModel GetRatings_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); double assetsSuitability = 0; double percentage = 0; foreach (var account in groupAccounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<ManagedInvestment>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } foreach (var account in clientAccounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<ManagedInvestment>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } PortfolioRatingModel model = new PortfolioRatingModel { suitability = assetsSuitability, notSuited = percentage }; return model; } else { List<ClientAccount> accounts = edisRepo.GetAccountsForClientSync(client.ClientNumber, DateTime.Now); double assetsSuitability = 0; double percentage = 0; foreach (var account in accounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<ManagedInvestment>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((ManagedInvestment)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } PortfolioRatingModel model = new PortfolioRatingModel { suitability = assetsSuitability, notSuited = percentage }; return model; } }
public PortfolioRatingModel GetRatings_Adviser(string clientGroupId = null) { if (string.IsNullOrEmpty(clientGroupId)) { List<GroupAccount> groupAccounts = edisRepo.getAllClientGroupAccountsForAdviser(User.Identity.GetUserId(), DateTime.Now); List<ClientAccount> clientAccounts = edisRepo.getAllClientAccountsForAdviser(User.Identity.GetUserId(), DateTime.Now); double assetsSuitability = 0; double percentage = 0; foreach (var account in groupAccounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<InternationalEquity>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } foreach (var account in clientAccounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<InternationalEquity>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } PortfolioRatingModel model = new PortfolioRatingModel { suitability = assetsSuitability, notSuited = percentage }; return model; } else { ClientGroup clientGroup = edisRepo.getClientGroupByGroupId(clientGroupId); List<GroupAccount> accounts = edisRepo.GetAccountsForClientGroupSync(clientGroup.ClientGroupNumber, DateTime.Now); double assetsSuitability = 0; double percentage = 0; foreach (var account in accounts) { var equityWithResearchValues = account.GetAssetsSync().OfType<InternationalEquity>().ToList(); assetsSuitability += equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings().Sum(w => w.Percentage * ((InternationalEquity)w.Weightable).GetRating().TotalScore); //var weigthings = equityWithResearchValues.Cast<AssetBase>().ToList().GetAssetWeightings(); //% of not suitable assets percentage += equityWithResearchValues.Where(a => a.GetRating().SuitabilityRating == SuitabilityRating.Danger).Sum(a => a.GetTotalMarketValue()) / equityWithResearchValues.Sum(a => a.GetTotalMarketValue()); } PortfolioRatingModel model = new PortfolioRatingModel { suitability = assetsSuitability, notSuited = percentage }; return model; } }