/// <summary> /// Reads and parses CSV data from file /// </summary> /// <param name="ticker">Ticker associated with CSV file</param> /// <param name="neededTypes">Columns to parse (headers)</param> /// <param name="from">DateTime from</param> /// <param name="to">DateTime to</param> /// <param name="File">Filepath to CSV</param> /// <returns>Marketdata</returns> public ICollection <LoadedMarketData> ReadAndCallLoader(TickerSymbol ticker, IList <MarketDataType> neededTypes, DateTime from, DateTime to, string File) { try { LoadedFile = File; Console.WriteLine("Loading instrument: " + ticker.Symbol + " from: " + File); //We got a file, lets load it. ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); ReadCSV csv = new ReadCSV(File, true, LoadedFormat); if (DateTimeDualColumn) { csv.DateFormat = DateFormat; csv.TimeFormat = TimeFormat; } else { csv.DateFormat = DateFormat; } //"Date","Time","Open","High","Low","Close","Volume" while (csv.Next()) { string datetime = ""; if (DateTimeDualColumn) { datetime = csv.GetDate("Date").ToShortDateString() + " " + csv.GetTime("Time").ToShortTimeString(); } else { datetime = csv.GetDate("Date").ToShortDateString(); } DateTime date = DateTime.Parse(datetime); if (date > from && date < to) { // CSV columns double open = csv.GetDouble("Open"); double high = csv.GetDouble("High"); double low = csv.GetDouble("Low"); double close = csv.GetDouble("Close"); double volume = csv.GetDouble("Volume"); LoadedMarketData data = new LoadedMarketData(date, ticker); foreach (MarketDataType marketDataType in neededTypes) { switch (marketDataType.ToString()) { case "Open": data.SetData(MarketDataType.Open, open); break; case "High": data.SetData(MarketDataType.High, high); break; case "Low": data.SetData(MarketDataType.Low, low); break; case "Close": data.SetData(MarketDataType.Close, close); break; case "Volume": data.SetData(MarketDataType.Volume, volume); break; case "RangeHighLow": data.SetData(MarketDataType.RangeHighLow, Math.Round(Math.Abs(high - low), 6)); break; case "RangeOpenClose": data.SetData(MarketDataType.RangeOpenClose, Math.Round(Math.Abs(close - open), 6)); break; case "RangeOpenCloseNonAbsolute": data.SetData(MarketDataType.RangeOpenCloseNonAbsolute, Math.Round(close - open, 6)); break; case "Weighted": data.SetData(MarketDataType.Weighted, Math.Round((high + low + 2 * close) / 4, 6)); break; } } result.Add(data); } } csv.Close(); return(result); } catch (Exception ex) { Console.WriteLine("Something went wrong reading the csv: " + ex.Message); } return(null); }