Exemplo n.º 1
0
        public Fund(InvestmentProduct investmentproduct)
        {
            this.PerformanceList = new List <FundPerformance>();

            ProductCode code;

            Enum.TryParse <ProductCode>(investmentproduct.ProductCode, out code);
            this.ProductCode = code;

            this.FullName = investmentproduct.FullName;
            this.ID       = investmentproduct.id;

            List <SectorAllocation1> sectorlist      = new List <SectorAllocation1>();
            List <FundPrice1>        performancelist = new List <FundPrice1>();

            foreach (var ext in investmentproduct.OLifEExtension.ToList())
            {
                foreach (var item in ext.Items)
                {
                    if (item.GetType() == typeof(SectorAllocation1))
                    {
                        sectorlist.Add(item as SectorAllocation1);
                    }

                    else if (item.GetType() == typeof(FundPrice1))
                    {
                        performancelist.Add(item as FundPrice1);
                    }
                }
            }

            SetSectorValues(sectorlist);
            SetPerformanceValues(performancelist);
        }
        public void AddEdit(InvestmentProduct investmentProduct, User user)
        {
            DynamicParameters spParams = new DynamicParameters();

            spParams.Add("Id", investmentProduct.Id);
            spParams.Add("Name", investmentProduct.Name);
            spParams.Add("Description", investmentProduct.Description);
            spParams.Add("ProductCategoryId", investmentProduct.ProductCategoryId);
            spParams.Add("InvestmentPeriod", investmentProduct.InvestmentPeriod);
            spParams.Add("UserId", user.Id);

            DapperORM.ExecuteWithoutReturn("AddEditProduct", spParams);
        }
Exemplo n.º 3
0
        public void GetCostBasisPerShare_TypicalValues_ExpectCorrectAnswer()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            int               numShares           = 44;
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", 1223.67M, DateTime.Now);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, DateTime.Now, numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            decimal basisCost = userInvestment.GetCostPerBasisShare();

            // Assert
            Assert.AreEqual(originalSharePrice * numShares, basisCost);
        }
Exemplo n.º 4
0
        public void GetTerm_GreaterThan365_expectLong()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            decimal           currentPrice        = 99.33M;
            int               numShares           = 44;
            DateTime          currentDate         = new DateTime(2020, 5, 12);
            DateTime          purchaseDate        = new DateTime(2018, 1, 15);
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", currentPrice, currentDate);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, purchaseDate, numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            InvestmentTerm actualTerm = userInvestment.GetTerm();

            // Assert
            Assert.AreEqual(InvestmentTerm.Long, actualTerm);
        }
Exemplo n.º 5
0
        public void GetTotalGainLoss_PriceDropped_ExpectCorrectNegativeAnswer()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            decimal           currentPrice        = 99.33M;
            int               numShares           = 44;
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", currentPrice, DateTime.Now);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, DateTime.Now.AddMonths(-4), numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            decimal loss = userInvestment.GetTotalGainLoss();

            // Assert
            decimal expectedLoss = (currentPrice - originalSharePrice) * numShares;

            Assert.AreEqual(expectedLoss, loss);
        }
Exemplo n.º 6
0
        void proxy_GetFundCompleted(object sender, GetFundCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null || e.Cancelled)
                {
                    if (OnFundProcessError != null)
                    {
                        OnFundProcessError(this, new SourceLookupEventArgs(e.UserState as SourceLookup));
                    }
                }

                OLife obj = e.Result;

                InvestmentProduct investmentproduct = (InvestmentProduct)obj.Items[0];

                string code = investmentproduct.InvestProductSysKey[0].Replace("Silica_FundCode{", "").Replace("}", "");

                SourceLookup lookup = e.UserState as SourceLookup; //_ActiveRequests.SingleOrDefault(t => t.SourceId == code);
                lock (_ActiveRequests)
                {
                    if (lookup != null)
                    {
                        _ActiveRequests.Remove(lookup);
                    }

                    Fund fund = new Fund(investmentproduct);

                    FundController.CreateFundWithPerformance(fund);

                    if (OnFundProcessed != null)
                    {
                        OnFundProcessed(this, new InvestProductEventArgs(investmentproduct));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        private void DisplayInvestmentDetails(UserInvestment selectedInvestment)
        {
            try
            {
                InvestmentProduct product     = selectedInvestment.GetInvestmentProduct();
                TradeTransaction  transaction = selectedInvestment.GetPurchaseTransaction();
                investmentName.InnerText    = product.Name;
                numShares.InnerText         = transaction.NumShares.ToString();;
                costBasisPerShare.InnerText = selectedInvestment.GetCostPerBasisShare().ToString("C3");
                currentValue.InnerText      = selectedInvestment.GetCurrentValue().ToString("C3");
                currentPrice.InnerText      = product.CurrentPrice.ToString("C3");
                term.InnerText          = selectedInvestment.GetTerm().ToString();
                totalGainLoss.InnerText = selectedInvestment.GetTotalGainLoss().ToString("C3");

                _nLogger.Info($"Displaying details for {product.Name}");
            }
            catch (Exception ex)
            {
                errorLabel.InnerText = "Error displaying investment details.  Please try again later";
                _nLogger.Error(ex, "Exception displaying investment details");
            }
        }
Exemplo n.º 8
0
        public IEnumerable <UserInvestment> GetAllUserInvestments(int userId)
        {
            List <UserInvestment> products       = new List <UserInvestment>();
            InvestmentProduct     productAbc     = new InvestmentProduct(1, "Grogu Heavy Lifting", 1.23M, DateTime.Now);
            TradeTransaction      transactionAbc = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2018, 4, 15), 100, 0.55M);
            UserInvestment        investmentAbc  = new UserInvestment(_nLogger, productAbc, transactionAbc);

            products.Add(investmentAbc);

            InvestmentProduct productBcd     = new InvestmentProduct(2, "Guild Enterprises", 44.78M, DateTime.Now);
            TradeTransaction  transactionBcd = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2020, 11, 15), 1500, 71.00M);
            UserInvestment    investmentBcd  = new UserInvestment(_nLogger, productBcd, transactionBcd);

            products.Add(investmentBcd);

            InvestmentProduct productCde     = new InvestmentProduct(3, "Karga Holdings", 1434.78M, DateTime.Now);
            TradeTransaction  transactionCde = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2019, 2, 1), 50, 1042.55M);
            UserInvestment    investmentCde  = new UserInvestment(_nLogger, productCde, transactionCde);

            products.Add(investmentCde);

            return(products);
        }
Exemplo n.º 9
0
        private void DisplayAllInvestments(IDataRepository dataRepository)
        {
            try
            {
                _userInvestments = dataRepository.GetAllUserInvestments(_userId);
                if (_userInvestments == null || _userInvestments.Count() == 0)
                {
                    errorLabel.InnerText = "No active investments";
                    _nLogger.Warn("No active investments");
                    return;
                }

                using (DataTable data = new DataTable())
                {
                    data.Columns.AddRange(new DataColumn[3]
                    {
                        new DataColumn("Id", typeof(string)),
                        new DataColumn("Name", typeof(string)),
                        new DataColumn("Get Details", typeof(string))
                    });

                    foreach (UserInvestment userInvestment in _userInvestments)
                    {
                        InvestmentProduct product = userInvestment.GetInvestmentProduct();
                        data.Rows.Add(product.Id, product.Name);
                    }
                    PortfolioGridView.CellPadding = 50;
                    PortfolioGridView.DataSource  = data;
                    PortfolioGridView.DataBind();
                }
            }
            catch (Exception ex)
            {
                errorLabel.InnerText = "The site is experiences technical issues.  Please try again later";
                _nLogger.Fatal(ex, $"Exception in 'DisplayAllInvestments' method");
            }
        }
Exemplo n.º 10
0
        public static OLife LoadBySourceLookup(SourceLookup sourceLookup)
        {
            FileHelperEngine engine = new FileHelperEngine(typeof(Funds));

            Funds[] fundsexport = (Funds[])engine.ReadFile(HttpContext.Current.Server.MapPath("~/App_Data/Funds.csv"));

            engine = new FileHelperEngine(typeof(FundPerformance));
            FundPerformance[] fundPerformance = (FundPerformance[])engine.ReadFile(HttpContext.Current.Server.MapPath("~/App_Data/FundPerformance.csv"));

            OLife olife = new OLife();

            List <OLifeBase> lstProduct = new List <OLifeBase>();

            //THIS WILL CHANGE ON LIVE
            //int SourceId = int.Parse(sourceLookup.SourceId);

            // var funds = fundsexport.Where(t => t.TrustNo == SourceId).ToList();

            //var sfund = fundsexport.FirstOrDefault(t => t.TrustNo == SourceId);

            var sfund = fundsexport.SingleOrDefault(t => t.JSECode == sourceLookup.SourceId);

            //foreach (var sfund in funds)
            //{
            if (sfund != null)
            {
                InvestmentProduct fund = new InvestmentProduct()
                {
                    id = String.Concat("STLB_InvestmentProduct_", sfund.TrustNo),
                    //InvestProductSysKey = new String[] { String.Concat("Silica_FundCode{", sfund.TrustNo.ToString(), "}") },
                    InvestProductSysKey = new String[] { String.Concat("Silica_FundCode{", sfund.JSECode.ToString(), "}") },
                    ProductCode         = sourceLookup.ProductCode,
                    FullName            = sfund.FundName,
                    SaleEffectiveDate   = sfund.QuarterEnd
                };


                OLifEExtension        ext    = new OLifEExtension();
                List <OLifEExtension> extlst = new List <OLifEExtension>();

                List <FundPrice>        fundprices = new List <FundPrice>();
                List <SectorAllocation> sectors    = new List <SectorAllocation>();

                ext.VendorCode = "STANLIB";
                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Resources",
                    Local          = sfund.Resources,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Financials",
                    Local          = sfund.Financials,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Industrials",
                    Local          = sfund.Industrials,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Alt X",
                    Local          = sfund.AltX,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Property",
                    Local          = sfund.Property,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Bonds",
                    Local          = sfund.Bonds,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode        = sfund.JSECode,
                    MarketSector   = "Cash",
                    Local          = sfund.Cash,
                    LocalSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode          = sfund.JSECode,
                    MarketSector     = "Foreign Equity",
                    Foreign          = sfund.ForeignEquity,
                    ForeignSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode          = sfund.JSECode,
                    MarketSector     = "Foreign Bonds",
                    Foreign          = sfund.ForeignBonds,
                    ForeignSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode          = sfund.JSECode,
                    MarketSector     = "Foreign Property",
                    Foreign          = sfund.ForeignProperty,
                    ForeignSpecified = true
                });

                sectors.Add(new SectorAllocation
                {
                    JSECode          = sfund.JSECode,
                    MarketSector     = "Foreign Cash",
                    Foreign          = sfund.ForeignCash,
                    ForeignSpecified = true
                });

                ext.Items = (object[])sectors.ToArray();
                extlst.Add(ext);

                ext = new OLifEExtension();

                var fundprice = fundPerformance.FirstOrDefault(t => t.JSECode.Trim() == sfund.JSECode.ToString());

                if (fundprice != null)
                {
                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M1"),
                        Performance = fundprice.M1,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M2"),
                        Performance = fundprice.M2,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M3"),
                        Performance = fundprice.M3,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M4"),
                        Performance = fundprice.M4,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M5"),
                        Performance = fundprice.M5
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M6"),
                        Performance = fundprice.M6,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M7"),
                        Performance = fundprice.M7
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M8"),
                        Performance = fundprice.M8,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M9"),
                        Performance = fundprice.M9
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M10"),
                        Performance = fundprice.M10,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M11"),
                        Performance = fundprice.M11
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M12"),
                        Performance = fundprice.M12,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M13"),
                        Performance = fundprice.M13,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M14"),
                        Performance = fundprice.M14,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M15"),
                        Performance = fundprice.M15
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M16"),
                        Performance = fundprice.M16,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M17"),
                        Performance = fundprice.M17,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M18"),
                        Performance = fundprice.M18,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M19"),
                        Performance = fundprice.M19,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M20"),
                        Performance = fundprice.M20,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M21"),
                        Performance = fundprice.M21,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M22"),
                        Performance = fundprice.M22,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M23"),
                        Performance = fundprice.M23,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M24"),
                        Performance = fundprice.M24,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M25"),
                        Performance = fundprice.M25,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M26"),
                        Performance = fundprice.M26
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M26"),
                        Performance = fundprice.M27,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M28"),
                        Performance = fundprice.M28,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M29"),
                        Performance = fundprice.M29,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M30"),
                        Performance = fundprice.M30,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M31"),
                        Performance = fundprice.M31,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M32"),
                        Performance = fundprice.M32,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M33"),
                        Performance = fundprice.M33,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M34"),
                        Performance = fundprice.M34,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M35"),
                        Performance = fundprice.M35,
                        Name        = sfund.FundName,
                        Type        = PriceType.Price
                    });

                    fundprices.Add(new FundPrice()
                    {
                        JSECode     = fundprice.JSECode,
                        Date        = LookupDate("M36"),
                        Performance = fundprice.M36
                    });

                    ext.Items = (object[])fundprices.ToArray();
                    extlst.Add(ext);
                }

                fund.OLifEExtension = extlst.ToArray();
                lstProduct.Add(fund);
            }
            //}

            olife.Items = lstProduct.ToArray();
            return(olife);
        }
Exemplo n.º 11
0
 public InvestProductEventArgs(InvestmentProduct ip)
 {
     this.investmentproduct = ip;
 }