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

            PortfolioSummary summary = new PortfolioSummary {
                investment = new SummaryItem {
                    data = new List <DataNameAmountPair> {
                        new DataNameAmountPair {
                            amount = assets.OfType <AustralianEquity>().Cast <AssetBase>().ToList().GetTotalMarketValue(), name = "Australian Equity"
                        },
                        new DataNameAmountPair {
                            amount = assets.OfType <InternationalEquity>().Cast <AssetBase>().ToList().GetTotalMarketValue(), name = "International Equity"
                        },
                        new DataNameAmountPair {
                            amount = assets.OfType <ManagedInvestment>().Cast <AssetBase>().ToList().GetTotalMarketValue(), name = "Managed Investment"
                        },
                    }
                },
                liability = new SummaryItem {
                    data = new List <DataNameAmountPair> {
                        new DataNameAmountPair {
                            amount = liabilities.OfType <MortgageAndHomeLiability>().Cast <LiabilityBase>().ToList().GetTotalLiabilitiesValue(), name = "Mortgage & Investment Loans"
                        },
                        new DataNameAmountPair {
                            amount = liabilities.OfType <MarginLending>().Cast <LiabilityBase>().ToList().GetTotalLiabilitiesValue(), name = "Margin Loans"
                        },
                        new DataNameAmountPair {
                            amount = liabilities.OfType <Insurance>().Cast <LiabilityBase>().ToList().GetTotalLiabilitiesValue(), name = "Insurance"
                        },
                        //new DataNameAmountPair{amount=30000,name="Margin Loans"}
                    }
                },
                networth = new SummaryItem {
                    data = new List <DataNameAmountPair> {
                        //new DataNameAmountPair{amount=30000, name="Investor Equity"},
                        //new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                    },
                }
            };

            summary.investment.total = summary.investment.data.Sum(d => d.amount);
            summary.liability.total  = summary.liability.data.Sum(d => d.amount);
            summary.networth.total   = summary.investment.total + summary.liability.total;

            return(summary);
        }
        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 PortfolioSummary GenerateSummary(AssetsAndLiabilites assetsAndLiabilities) {
            List<AssetBase> assets = assetsAndLiabilities.assets;
            List<LiabilityBase> liabilities = assetsAndLiabilities.liabilities;

            PortfolioSummary summary = new PortfolioSummary {
                investment = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        new DataNameAmountPair{ amount = assets.OfType<AustralianEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Australian Equity"},
                        new DataNameAmountPair { amount =  assets.OfType<InternationalEquity>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="International Equity"},
                        new DataNameAmountPair { amount =  assets.OfType<ManagedInvestment>().Cast<AssetBase>().ToList().GetTotalMarketValue(), name="Managed Investment"},
                    }
                },
                liability = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        new DataNameAmountPair{amount =  liabilities.OfType<MortgageAndHomeLiability>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Mortgage & Investment Loans"},
                        new DataNameAmountPair{amount =  liabilities.OfType<MarginLending>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Margin Loans"},
                        new DataNameAmountPair{amount =  liabilities.OfType<Insurance>().Cast<LiabilityBase>().ToList().GetTotalLiabilitiesValue(),name="Insurance"},
                        //new DataNameAmountPair{amount=30000,name="Margin Loans"}
                    }
                },
                networth = new SummaryItem {
                    data = new List<DataNameAmountPair> {
                        //new DataNameAmountPair{amount=30000, name="Investor Equity"},
                        //new DataNameAmountPair{amount=500000, name="Non-Investment Asset"}
                    },
                }
            };

            summary.investment.total = summary.investment.data.Sum(d => d.amount);
            summary.liability.total = summary.liability.data.Sum(d => d.amount);
            summary.networth.total = summary.investment.total + summary.liability.total;

            return summary;
        }
        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);
        }