public void Consolidate_UnitTest()
        {
            var assetPortfolio = new AssetPortfolio(mockExchangeRates.Object);

            assetPortfolio.Consolidate();
            Assert.AreEqual(assetPortfolio.ConsolidatedPortfolio.Count, 0);

            assetPortfolio.Portfolio = new List <IAsset>()
            {
                new Stock("ABC", "USD", 3, 2),
                new Stock("ABC", "USD", 5, 1),
                new Stock("ABC", "EUR", 10, 2),
                new Currency("EUR", 100),
                new Currency("EUR", 100),
                new Currency("USD", 300),
            };


            assetPortfolio.Consolidate();
            Assert.AreEqual(assetPortfolio.ConsolidatedPortfolio.Count, 4);
            Assert.IsTrue(assetPortfolio.ConsolidatedPortfolio["ABCUSD"].Shares == 8 && ((Stock)assetPortfolio.ConsolidatedPortfolio["ABCUSD"]).Price == 1.375);
            Assert.IsTrue(assetPortfolio.ConsolidatedPortfolio["ABCEUR"].Shares == 10 && ((Stock)assetPortfolio.ConsolidatedPortfolio["ABCEUR"]).Price == 2);
            Assert.AreEqual(assetPortfolio.ConsolidatedPortfolio["CashEUR"].Shares, 200);
            Assert.AreEqual(assetPortfolio.ConsolidatedPortfolio["CashUSD"].Shares, 300);
        }
Exemple #2
0
        public void Should_amount_is_1200_When_euro_consolidate()
        {
            var assetPortfolio = new AssetPortfolio(null);

            assetPortfolio.Add(new Cash(1000, Currency.EUR));
            assetPortfolio.Add(new Cash(200, Currency.EUR));

            var result = assetPortfolio.Consolidate();

            Assert.AreEqual(1, result.Portfolio.Count);
            Assert.AreEqual(Currency.EUR, (result.Portfolio[0] as Cash).Currency);
            Assert.AreEqual(1200, (result.Portfolio[0] as Cash).GetValue());
        }
Exemple #3
0
        public void Should_price_is_3_and_shares_is_300_When_abc_stock_consolidate()
        {
            var assetPortfolio = new AssetPortfolio(null);

            assetPortfolio.Add(new Stock("ABC", 100, 2, Currency.USD));
            assetPortfolio.Add(new Stock("ABC", 200, 3.5, Currency.USD));

            var result = assetPortfolio.Consolidate();

            Assert.AreEqual(1, result.Portfolio.Count);
            Assert.AreEqual(3, (result.Portfolio[0] as Stock).Price);
            Assert.AreEqual(300, (result.Portfolio[0] as Stock).Shares);
        }
Exemple #4
0
        public void TestAddAssetsSameSymbol()
        {
            Assert.DoesNotThrow(delegate
            {
                var portfolio = new AssetPortfolio(_flatrates, "Test Asset Portfolio");
                portfolio.Add(new FXCurrencyAsset("ABC", EUR, 20));
                portfolio.Add(new Stock("ABC", EUR, 10, 20));
                portfolio.Add(new DomesticStock("ABC", 10, 20));
                var consolidated = portfolio.Consolidate();

                Assert.AreEqual(portfolio.NoAssets, portfolio.NoDistinctAssets, 3);
                Assert.AreEqual(consolidated.NoAssets, consolidated.NoDistinctAssets, 3);
            });
        }
Exemple #5
0
        public void Should_price_is_3_and_shares_is_300_amount_is_1200_x_When_euro_and_abc_stock_consolidate()
        {
            var assetPortfolio = new AssetPortfolio(null);

            assetPortfolio.Add(new Stock("ABC", 100, 2, Currency.USD));
            assetPortfolio.Add(new Stock("ABC", 200, 3.5, Currency.USD));
            assetPortfolio.Add(new Cash(1000, Currency.EUR));
            assetPortfolio.Add(new Cash(200, Currency.EUR));

            var result = assetPortfolio.Consolidate();

            Assert.AreEqual(2, result.Portfolio.Count);
            Assert.AreEqual(3, (result.Portfolio[0] as Stock).Price);
            Assert.AreEqual(300, (result.Portfolio[0] as Stock).Shares);
            Assert.AreEqual(Currency.EUR, (result.Portfolio[1] as Cash).Currency);
            Assert.AreEqual(1200, (result.Portfolio[1] as Cash).GetValue());
        }
Exemple #6
0
        public void TestConsolidationPortfolio()
        {
            List <Asset> assets = new List <Asset>
            {
                new Stock("ABCGBP", "GBP", 200, 4),
                new Stock("ABCGBP", "GBP", 200, 4),

                new Stock("ABCUSD", "USD", 200, 4),

                new DomesticStock("ABC", 200, 4),
                new DomesticStock("ABC", 100, 8),
                new DomesticStock("ABC", 400, 8),

                new FXCurrencyAsset("GBP", "GBP", 100),
                new FXCurrencyAsset("GBP", "GBP", 200),
                new FXCurrencyAsset("GBP", "GBP", 300),

                new FXCurrencyAsset("USD", "USD", 100),
                new FXCurrencyAsset("USD", "USD", 200),
                new FXCurrencyAsset("USD", "USD", 300)
            };

            var portfolio = new AssetPortfolio(_flatrates, "Original Portfolio", assets);


            TestValuationPortfolio(portfolio, 8400, EUR);

            //there are 12 assets
            Assert.AreEqual(portfolio.NoAssets, 12);

            //there are 5 distinct assets
            Assert.AreEqual(portfolio.NoDistinctAssets, 5);

            //Consolidating Portfolio
            AssetPortfolio portfolioConsolidated = portfolio.Consolidate();

            TestValuationPortfolio(portfolioConsolidated, 8400, EUR);

            //consolidated into 5 assets
            Assert.AreEqual(portfolioConsolidated.NoDistinctAssets, 5);
            Assert.AreEqual(portfolioConsolidated.NoAssets, 5);

            Console.WriteLine(portfolio);
            Console.WriteLine(portfolioConsolidated);
        }
        public void Consolidate_UnitTest_GivenExample()
        {
            var assetPortfolio = new AssetPortfolio(mockExchangeRates.Object)
            {
                Portfolio = new List <IAsset>()
                {
                    new Stock("ABC", "USD", 100, 2),
                    new Stock("ABC", "USD", 200, 3.5),
                    new Currency("EUR", 1000),
                    new Currency("EUR", 200),
                }
            };

            assetPortfolio.Consolidate();
            Assert.IsTrue(assetPortfolio.ConsolidatedPortfolio.Count == 2);
            Assert.IsTrue(assetPortfolio.ConsolidatedPortfolio["ABCUSD"].Shares == 300 && ((Stock)assetPortfolio.ConsolidatedPortfolio["ABCUSD"]).Price == 3);
            Assert.IsTrue(assetPortfolio.ConsolidatedPortfolio["CashEUR"].Shares == 1200);
        }