public static Fund NewFundFromPortfolio(string openLocation, DateTime date) { Fund fund = new Fund(); Portfolio port = new Portfolio(); Processor proc = new Processor(); TrendUniverse SU = new TrendUniverse(); proc.Portfolio = port; proc.WeeklyDate = Convert.ToDateTime(date.ToShortDateString()); proc.StockPick = "Stock Pick"; proc.Universe = SU; fund.AddProc(proc); using (System.IO.StreamReader sr = new StreamReader(openLocation)) { string unparsedCSV = sr.ReadToEnd(); //Stock name, Lot, Holdings, purchase price, date, high alert, low alert. 6 items looping string[] parsedCSV = unparsedCSV.Replace("\n", " ").Replace(" ", ",").Split(','); int LotCounter = 0; while (LotCounter < parsedCSV.Length) { string stockName = parsedCSV[LotCounter + 0]; if (stockName == "ZZZCASH") { port.Cash = Convert.ToDecimal(parsedCSV[LotCounter + 2]); break; } int lotNumber = Convert.ToInt16(parsedCSV[LotCounter + 1]); decimal holdings = Convert.ToDecimal(parsedCSV[LotCounter + 2]); parsedCSV[LotCounter +3] = parsedCSV[LotCounter + 3].Replace("$", ""); decimal purchasePrice = Convert.ToDecimal(parsedCSV[LotCounter + 3]); DateTime purchaseDate = Convert.ToDateTime(parsedCSV[LotCounter + 4]); decimal highAlert = Convert.ToDecimal(parsedCSV[LotCounter + 5]); decimal lowAlert = Convert.ToDecimal(parsedCSV[LotCounter + 6]); Lot lot = new Lot(stockName, Trends.PriceBySymbol(stockName, date),lotNumber,holdings,purchasePrice,purchaseDate,highAlert,lowAlert); fund.FundHistory[0].Portfolio.Add(lot); LotCounter = LotCounter + 7; } port.CalcPortfolioValue(); return fund; } }
public void Sell(Lot lot) { Cash = Cash + lot.Price * lot.Holdings; this.Remove(lot); }
public void Remove(Lot lot) { Stocks.Remove(lot); SortSymbol(); CalcPortfolioValue(); }
public void Add(Lot lot) { lot.ParentPort = this; Stocks.Add(lot); SortSymbol(); CalcPortfolioValue(); }
public void Add(string symbol, decimal price, int lotNumber, int holdings, decimal purchasePrice, DateTime purchaseDate, decimal highAlert, decimal lowAlert) { Lot lot = new Lot(symbol, price, lotNumber, holdings, purchasePrice, purchaseDate, highAlert, lowAlert); Stocks.Add(lot); SortSymbol(); CalcPortfolioValue(); }