예제 #1
0
파일: Fund.cs 프로젝트: erikprat61/Stocks
        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;
            }
        }
예제 #2
0
 public void Sell(Lot lot)
 {
     Cash = Cash + lot.Price * lot.Holdings;
     this.Remove(lot);
 }
예제 #3
0
 public void Remove(Lot lot)
 {
     Stocks.Remove(lot);
     SortSymbol();
     CalcPortfolioValue();
 }
예제 #4
0
 public void Add(Lot lot)
 {
     lot.ParentPort = this;
     Stocks.Add(lot);
     SortSymbol();
     CalcPortfolioValue();
 }
예제 #5
0
 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();
 }