/* *This method consolidates the assets based on their Symbol and type. If there are two assets
         *  with same Symbol and same asset type (i.e two or more Domestic Stocks with the Symbol ABC, they will be
         *  consolidated.
         *
         * If there are similar assets but with different currencies, they will be consolidated after converting
         *   their respective prices to Euro. The possibility of having Same symbols, bought in different currency
         *   denominations is an assumption that I made.
         *
         */
        public static List <IAssets> CompareAssets(List <IAssets> consolidatedList, IAssets asset)
        {
            ExchangeRates exchangeRate = new ExchangeRates();

            if (consolidatedList.Count == 0)
            {
                consolidatedList.Add(asset);
                return(consolidatedList);
            }

            IAssets tempAsset = consolidatedList.Find(x => x.Equals(asset));

            if (tempAsset == null)
            {
                consolidatedList.Add(asset);
                return(consolidatedList);
            }

            try
            {
                if (tempAsset.Currency == asset.Currency)
                {
                    consolidatedList.Remove(tempAsset);
                    tempAsset.Price   = ((tempAsset.Price * tempAsset.Shares) + (asset.Price * asset.Shares)) / (tempAsset.Shares + asset.Shares);
                    tempAsset.Shares += asset.Shares;
                    consolidatedList.Add(tempAsset);
                    return(consolidatedList);
                }

                else if (tempAsset.Type == asset.Type)
                {
                    consolidatedList.Remove(tempAsset);
                    var entryPrice = exchangeRate.GetRate(tempAsset.Price, tempAsset.Currency.ToString(), "EUR");
                    var assetPrice = exchangeRate.GetRate(asset.Price, asset.Currency.ToString(), "EUR");
                    tempAsset.Price    = ((entryPrice * tempAsset.Shares) + (assetPrice * asset.Shares)) / tempAsset.Shares + asset.Shares;
                    tempAsset.Shares  += asset.Shares;
                    tempAsset.Currency = CurrencyTypes.EUR;
                    consolidatedList.Add(tempAsset);
                    return(consolidatedList);
                }

                consolidatedList.Add(asset);
            }

            catch (Exception e)
            {
                Console.WriteLine("\nError:" + e.Message);
                consolidatedList.Add(tempAsset);
            }

            return(consolidatedList);
        }
Exemple #2
0
        /*
         * Valuation of the asset is done based on the currency denomination chosen by the user.
         */
        public double Value(string toCurrency)
        {
            ExchangeRates exchangeRate = new ExchangeRates();

            return(exchangeRate.GetRate((Shares * Price), Currency.ToString(), toCurrency));
        }