/// <summary> /// Reads the CSV and call loader. /// Used internally to load the csv and place data in the marketdataset. /// </summary> /// <param name="symbol">The symbol.</param> /// <param name="neededTypes">The needed types.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <param name="File">The file.</param> /// <returns></returns> ICollection <LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IEnumerable <MarketDataType> neededTypes, DateTime from, DateTime to, string File) { //We got a file, lets load it. ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); ReadCSV csv = new ReadCSV(File, true, CSVFormat.English); //In case we want to use a different date format...and have used the SetDateFormat method, our DateFormat must then not be null.. //We will use the ?? operator to check for nullables. csv.DateFormat = DateFormat ?? "yyyy-MM-dd HH:mm:ss"; csv.TimeFormat = "HH:mm:ss"; DateTime ParsedDate = from; bool writeonce = true; while (csv.Next()) { DateTime date = csv.GetDate(0); ParsedDate = date; if (writeonce) { Console.WriteLine(@"First parsed date in csv:" + ParsedDate.ToShortDateString()); Console.WriteLine(@"Stopping at date:" + to.ToShortDateString()); Console.WriteLine(@"Current DateTime:" + ParsedDate.ToShortDateString() + @" Time:" + ParsedDate.ToShortTimeString() + @" Asked Start date was " + from.ToShortDateString()); writeonce = false; } if (ParsedDate >= from && ParsedDate <= to) { DateTime datex = csv.GetDate(0); double open = csv.GetDouble(1); double close = csv.GetDouble(2); double high = csv.GetDouble(3); double low = csv.GetDouble(4); double volume = csv.GetDouble(5); double range = Math.Abs(open - close); double HighLowRange = Math.Abs(high - low); double DirectionalRange = close - open; LoadedMarketData data = new LoadedMarketData(datex, symbol); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.High, high); data.SetData(MarketDataType.Low, low); data.SetData(MarketDataType.Close, close); data.SetData(MarketDataType.Volume, volume); data.SetData(MarketDataType.RangeHighLow, Math.Round(HighLowRange, 6)); data.SetData(MarketDataType.RangeOpenClose, Math.Round(range, 6)); data.SetData(MarketDataType.RangeOpenCloseNonAbsolute, Math.Round(DirectionalRange, 6)); result.Add(data); } } csv.Close(); return(result); }
public ICollection <LoadedMarketData> Load( TickerSymbol ticker, IList <MarketDataType> dataNeeded, DateTime from, DateTime to) { // TODO: nyyyyyyyaaagh! ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); Uri url = BuildURL(ticker, from, to); WebRequest http = HttpWebRequest.Create(url); HttpWebResponse response = http.GetResponse() as HttpWebResponse; using (Stream istream = response.GetResponseStream()) { ReadCSV csv = new ReadCSV( istream, true, CSVFormat.DECIMAL_POINT ); while (csv.Next()) { // todo: edit headers to match DateTime date = csv.GetDate("DATE"); date = date.Add( new TimeSpan( csv.GetDate("TIME").Hour, csv.GetDate("TIME").Minute, csv.GetDate("TIME").Second ) ); double open = csv.GetDouble("OPEN"); double high = csv.GetDouble("MIN"); double low = csv.GetDouble("MAX"); double close = csv.GetDouble("CLOSE"); double volume = csv.GetDouble("VOLUME"); LoadedMarketData data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.HIGH, high); data.SetData(MarketDataType.LOW, low); data.SetData(MarketDataType.CLOSE, close); data.SetData(MarketDataType.VOLUME, volume); result.Add(data); } csv.Close(); istream.Close(); } return(result); }
public ICollection <LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList <MarketDataType> neededTypes, DateTime from, DateTime to, string File) { try { //We got a file, lets load it. ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); ReadCSV csv = new ReadCSV(File, true, CSVFormat.English); csv.DateFormat = "yyyy.MM.dd HH:mm:ss"; DateTime ParsedDate = from; // Time,Open,High,Low,Close,Volume while (csv.Next() && ParsedDate >= from && ParsedDate <= to) { DateTime date = csv.GetDate("Time"); double Bid = csv.GetDouble("Bid"); double Ask = csv.GetDouble("Ask"); double AskVolume = csv.GetDouble("AskVolume"); double BidVolume = csv.GetDouble("BidVolume"); double _trade = (Bid + Ask) / 2; double _tradeSize = (AskVolume + BidVolume) / 2; LoadedMarketData data = new LoadedMarketData(date, symbol); data.SetData(MarketDataType.Trade, _trade); data.SetData(MarketDataType.Volume, _tradeSize); result.Add(data); Console.WriteLine("Current DateTime:" + ParsedDate.ToShortDateString() + " Time:" + ParsedDate.ToShortTimeString() + " Start date was " + from.ToShortDateString()); Console.WriteLine("Stopping at date:" + to.ToShortDateString()); ParsedDate = date; //double open = csv.GetDouble("Open"); //double close = csv.GetDouble("High"); //double high = csv.GetDouble("Low"); //double low = csv.GetDouble("Close"); //double volume = csv.GetDouble("Volume"); //LoadedMarketData data = new LoadedMarketData(date, symbol); //data.SetData(MarketDataType.Open, open); //data.SetData(MarketDataType.High, high); //data.SetData(MarketDataType.Low, low); //data.SetData(MarketDataType.Close, close); //data.SetData(MarketDataType.Volume, volume); result.Add(data); } csv.Close(); return(result); } catch (Exception ex) { Console.WriteLine("Something went wrong reading the csv"); Console.WriteLine("Something went wrong reading the csv:" + ex.Message); } Console.WriteLine("Something went wrong reading the csv"); return(null); }
/// <summary> /// Load financial data. /// </summary> /// <param name="ticker">The ticker symbol.</param> /// <param name="output">The output file.</param> /// <param name="outputFormat">The output format.</param> /// <param name="from">Starting date.</param> /// <param name="to">Ending date.</param> public void LoadAllData(String ticker, String output, CSVFormat outputFormat, DateTime from, DateTime to) { try { Uri urlData = BuildURL(ticker, from, to); WebRequest httpData = WebRequest.Create(urlData); var responseData = (HttpWebResponse)httpData.GetResponse(); if (responseData != null) { Stream istreamData = responseData.GetResponseStream(); var csvData = new ReadCSV(istreamData, true, CSVFormat.English); TextWriter tw = new StreamWriter(output); tw.WriteLine("date,time,open price,high price,low price,close price,volume,adjusted price"); while (csvData.Next()) { DateTime date = csvData.GetDate("date"); double adjustedClose = csvData.GetDouble("adj close"); double open = csvData.GetDouble("open"); double close = csvData.GetDouble("close"); double high = csvData.GetDouble("high"); double low = csvData.GetDouble("low"); var volume = (long)csvData.GetDouble("volume"); var line = new StringBuilder(); line.Append(NumericDateUtil.DateTime2Long(date)); line.Append(outputFormat.Separator); line.Append(NumericDateUtil.Time2Int(date)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(open, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(high, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(low, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(close, Precision)); line.Append(outputFormat.Separator); line.Append(volume); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(adjustedClose, Precision)); tw.WriteLine(line.ToString()); } tw.Close(); } } catch (WebException ex) { throw new QuantError(ex); } }
/// <summary> /// use this method to find a date in your csv , and it will return the line number.. /// This is useful for evaluation purpose when you need to find the line number so you can check against the real price and the network output prices. ///You must specify the DateFormat ("yyyy-MM-dd HH:mm:ss") for example. /// </summary> /// <param name="file">The file.</param> /// <param name="datetoFind">The date to find.</param> /// <param name="DateFormat">The date format.</param> /// <returns></returns> public static int QuickParseCSVForDate(string file, DateTime datetoFind, String DateFormat) { ReadCSV csv = new ReadCSV(file, true, CSVFormat.English); int currentLine = 0; csv.DateFormat = DateFormat; while (csv.Next()) { csv.GetDate(0); if (csv.GetDate(0) == datetoFind) { return(currentLine); } else { currentLine++; } } return(currentLine); }
public void loadPrime(String primeFilename) { ReadCSV csv = new ReadCSV(primeFilename); while (csv.Next()) { DateTime date = csv.GetDate("date"); double rate = csv.GetDouble("prime"); InterestRate ir = new InterestRate(date, rate); this.rates.Add(ir); } csv.Close(); this.rates.Sort(); }
public void loadPrime(String primeFilename) { var csv = new ReadCSV(primeFilename, true, CSVFormat.English); while (csv.Next()) { var date = csv.GetDate("date"); double rate = csv.GetDouble("prime"); var ir = new InterestRate(date, rate); rates.Add(ir); } csv.Close(); rates.Sort(); }
public void loadSP500(String sp500Filename) { var csv = new ReadCSV(sp500Filename, true, CSVFormat.English); while (csv.Next()) { var date = csv.GetDate("date"); double amount = csv.GetDouble("adj close"); var sample = new FinancialSample(); sample.setAmount(amount); sample.setDate(date); samples.Add(sample); } csv.Close(); samples.Sort(); }
public void loadSP500(String sp500Filename) { ReadCSV csv = new ReadCSV(sp500Filename); while (csv.Next()) { DateTime date = csv.GetDate("date"); double amount = csv.GetDouble("adj close"); FinancialSample sample = new FinancialSample(); sample.setAmount(amount); sample.setDate(date); this.samples.Add(sample); } csv.Close(); this.samples.Sort(); }
/// <summary> /// Load financial data from Google. /// </summary> /// <param name="ticker">The ticker to load from.</param> /// <param name="dataNeeded">The data needed.</param> /// <param name="from">The starting time.</param> /// <param name="to">The ending time.</param> /// <returns>The loaded data.</returns> public ICollection <LoadedMarketData> Load(TickerSymbol ticker, IList <MarketDataType> dataNeeded, DateTime from, DateTime to) { ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); Uri url = BuildUrl(ticker, from, to); WebRequest http = WebRequest.Create(url); var response = (HttpWebResponse)http.GetResponse(); if (response != null) { using (Stream istream = response.GetResponseStream()) { var csv = new ReadCSV(istream, true, CSVFormat.DecimalPoint); while (csv.Next()) { DateTime date = csv.GetDate("date"); double open = csv.GetDouble("open"); double close = csv.GetDouble("close"); double high = csv.GetDouble("high"); double low = csv.GetDouble("low"); double volume = csv.GetDouble("volume"); var data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.Close, close); data.SetData(MarketDataType.High, high); data.SetData(MarketDataType.Low, low); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.Volume, volume); result.Add(data); } csv.Close(); if (istream != null) { istream.Close(); } } } return(result); }
/// <summary> /// Loads the specified financial data. /// </summary> /// <param name="ticker">The currency pair to load.</param> /// <param name="dataNeeded">The financial data needed.</param> /// <param name="from">The beginning date to load data from.</param> /// <param name="to">The ending date to load data to.</param> /// <returns>A collection of LoadedMarketData objects that represent /// the data loaded.</returns> public ICollection <LoadedMarketData> Load( TickerSymbol ticker, IList <MarketDataType> dataNeeded, DateTime from, DateTime to ) { ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); Uri url = buildURL(ticker, from, to); WebRequest http = HttpWebRequest.Create(url); HttpWebResponse response = http.GetResponse() as HttpWebResponse; using (Stream istream = response.GetResponseStream()) { ReadCSV csv = new ReadCSV(istream, true, CSVFormat.DECIMAL_POINT); while (csv.Next()) { // TODO: check these values if possible DateTime date = csv.GetDate("date"); double adjClose = csv.GetDouble("adj close"); // TODO: deprecate? double open = csv.GetDouble("open"); double close = csv.GetDouble("close"); double high = csv.GetDouble("high"); double low = csv.GetDouble("low"); double volume = csv.GetDouble("volume"); // TODO: deprecate? LoadedMarketData data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.ADJUSTED_CLOSE, adjClose); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.CLOSE, close); data.SetData(MarketDataType.HIGH, high); data.SetData(MarketDataType.LOW, low); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.VOLUME, volume); result.Add(data); } csv.Close(); istream.Close(); } return(result); }
public ICollection <LoadedMarketData> ReadAndCallLoader(TickerSymbol symbol, IList <MarketDataType> neededTypes, DateTime from, DateTime to, string File) { try { //We got a file, lets load it. ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); ReadCSV csv = new ReadCSV(File, true, LoadedFormat); csv.DateFormat = DateTimeFormat.Normalize(); // Time,Open,High,Low,Close,Volume while (csv.Next()) { DateTime date = csv.GetDate("Time"); double open = csv.GetDouble("Open"); double close = csv.GetDouble("High"); double high = csv.GetDouble("Low"); double low = csv.GetDouble("Close"); double volume = csv.GetDouble("Volume"); LoadedMarketData data = new LoadedMarketData(date, symbol); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.High, high); data.SetData(MarketDataType.Low, low); data.SetData(MarketDataType.Close, close); data.SetData(MarketDataType.Volume, volume); result.Add(data); } csv.Close(); return(result); } catch (Exception ex) { Console.WriteLine("Something went wrong reading the csv"); Console.WriteLine("Something went wrong reading the csv:" + ex.Message); } Console.WriteLine("Something went wrong reading the csv"); return(null); }
/// <summary> /// Load financial data from a CSV file. /// </summary> /// <param name="ticker">The ticker being loaded, ignored for a CSV load.</param> /// <param name="dataNeeded">The data needed.</param> /// <param name="from">The starting date.</param> /// <param name="to">The ending date.</param> /// <returns></returns> public ICollection <LoadedMarketData> Load(TickerSymbol ticker, IList <MarketDataType> dataNeeded, DateTime from, DateTime to) { try { if (File.Exists(TheFile)) { //We got a file, lets load it. TheFile = TheFile; ICollection <LoadedMarketData> result = new List <LoadedMarketData>(); var csv = new ReadCSV(TheFile, true, CSVFormat.English); // Time,Open,High,Low,Close,Volume while (csv.Next()) { DateTime date = csv.GetDate("Time"); double open = csv.GetDouble("Open"); double close = csv.GetDouble("High"); double high = csv.GetDouble("Low"); double low = csv.GetDouble("Close"); double volume = csv.GetDouble("Volume"); var data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.Volume, close); data.SetData(MarketDataType.High, high); data.SetData(MarketDataType.Low, low); data.SetData(MarketDataType.Volume, volume); result.Add(data); } csv.Close(); return(result); } } catch (Exception ex) { throw new LoaderError(ex); } throw new LoaderError(@"Something went wrong reading the csv"); }
/// <summary> /// Load the specified financial data. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="dataNeeded">The financial data needed.</param> /// <param name="from">The beginning date to load data from.</param> /// <param name="to">The ending date to load data to.</param> /// <returns>A collection of LoadedMarketData objects that represent the data /// loaded.</returns> public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { ICollection<LoadedMarketData> result = new List<LoadedMarketData>(); Uri url = BuildURL(ticker, from, to); WebRequest http = WebRequest.Create(url); var response = (HttpWebResponse) http.GetResponse(); using (Stream istream = response.GetResponseStream()) { var csv = new ReadCSV(istream, true, CSVFormat.DecimalPoint); while (csv.Next()) { DateTime date = csv.GetDate("date"); double adjClose = csv.GetDouble("adj close"); double open = csv.GetDouble("open"); double close = csv.GetDouble("close"); double high = csv.GetDouble("high"); double low = csv.GetDouble("low"); double volume = csv.GetDouble("volume"); var data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.AdjustedClose, adjClose); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.Close, close); data.SetData(MarketDataType.High, high); data.SetData(MarketDataType.Low, low); data.SetData(MarketDataType.Open, open); data.SetData(MarketDataType.Volume, volume); result.Add(data); } csv.Close(); istream.Close(); } return result; }
/// <summary> /// Load the specified financial data. /// </summary> /// <param name="ticker">The ticker symbol to load.</param> /// <param name="dataNeeded">The financial data needed.</param> /// <param name="from">The beginning date to load data from.</param> /// <param name="to">The ending date to load data to.</param> /// <returns>A collection of LoadedMarketData objects that represent the data /// loaded.</returns> public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { ICollection<LoadedMarketData> result = new List<LoadedMarketData>(); Uri url = buildURL(ticker, from, to); WebRequest http = HttpWebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)http.GetResponse(); using (Stream istream = response.GetResponseStream()) { ReadCSV csv = new ReadCSV(istream, true, CSVFormat.DECIMAL_POINT); while (csv.Next()) { DateTime date = csv.GetDate("date"); double adjClose = csv.GetDouble("adj close"); double open = csv.GetDouble("open"); double close = csv.GetDouble("close"); double high = csv.GetDouble("high"); double low = csv.GetDouble("low"); double volume = csv.GetDouble("volume"); LoadedMarketData data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.ADJUSTED_CLOSE, adjClose); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.CLOSE, close); data.SetData(MarketDataType.HIGH, high); data.SetData(MarketDataType.LOW, low); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.VOLUME, volume); result.Add(data); } csv.Close(); istream.Close(); } return result; }
public ICollection<LoadedMarketData> Load( TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { // TODO: nyyyyyyyaaagh! ICollection<LoadedMarketData> result = new List<LoadedMarketData>(); Uri url = BuildURL(ticker, from, to); WebRequest http = HttpWebRequest.Create(url); HttpWebResponse response = http.GetResponse() as HttpWebResponse; using (Stream istream = response.GetResponseStream()) { ReadCSV csv = new ReadCSV( istream, true, CSVFormat.DECIMAL_POINT ); while (csv.Next()) { // todo: edit headers to match DateTime date = csv.GetDate("DATE"); date = date.Add( new TimeSpan( csv.GetDate("TIME").Hour, csv.GetDate("TIME").Minute, csv.GetDate("TIME").Second ) ); double open = csv.GetDouble("OPEN"); double high = csv.GetDouble("MIN"); double low = csv.GetDouble("MAX"); double close = csv.GetDouble("CLOSE"); double volume = csv.GetDouble("VOLUME"); LoadedMarketData data = new LoadedMarketData(date, ticker); data.SetData(MarketDataType.OPEN, open); data.SetData(MarketDataType.HIGH, high); data.SetData(MarketDataType.LOW, low); data.SetData(MarketDataType.CLOSE, close); data.SetData(MarketDataType.VOLUME, volume); result.Add(data); } csv.Close(); istream.Close(); } return result; }
/// <summary> /// Load financial data. /// </summary> /// <param name="ticker">The ticker symbol.</param> /// <param name="output">The output file.</param> /// <param name="outputFormat">The output format.</param> /// <param name="from">Starting date.</param> /// <param name="to">Ending date.</param> public void LoadAllData(String ticker, String output, CSVFormat outputFormat, DateTime from, DateTime to) { try { Uri urlData = BuildURL(ticker, from, to); WebRequest httpData = WebRequest.Create(urlData); var responseData = (HttpWebResponse) httpData.GetResponse(); if (responseData != null) { Stream istreamData = responseData.GetResponseStream(); var csvData = new ReadCSV(istreamData, true, CSVFormat.English); TextWriter tw = new StreamWriter(output); tw.WriteLine("date,time,open price,high price,low price,close price,volume,adjusted price"); while (csvData.Next()) { DateTime date = csvData.GetDate("date"); double adjustedClose = csvData.GetDouble("adj close"); double open = csvData.GetDouble("open"); double close = csvData.GetDouble("close"); double high = csvData.GetDouble("high"); double low = csvData.GetDouble("low"); var volume = (long) csvData.GetDouble("volume"); var line = new StringBuilder(); line.Append(NumericDateUtil.DateTime2Long(date)); line.Append(outputFormat.Separator); line.Append(NumericDateUtil.Time2Int(date)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(open, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(high, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(low, Precision)); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(close, Precision)); line.Append(outputFormat.Separator); line.Append(volume); line.Append(outputFormat.Separator); line.Append(outputFormat.Format(adjustedClose, Precision)); tw.WriteLine(line.ToString()); } tw.Close(); } } catch (WebException ex) { throw new QuantError(ex); } }
/// <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); }
public ICollection<LoadedMarketData> Load(TickerSymbol ticker, IList<MarketDataType> dataNeeded, DateTime from, DateTime to) { ICollection<LoadedMarketData> is2 = new List<LoadedMarketData>(); HttpWebResponse response = (HttpWebResponse) WebRequest.Create(x38c212309d8d5dd3(ticker, from, to)).GetResponse(); using (Stream stream = response.GetResponseStream()) { DateTime time; double num; double num2; double num3; double num4; double num5; double num6; LoadedMarketData data; ReadCSV dcsv = new ReadCSV(stream, true, CSVFormat.DecimalPoint); goto Label_005B; Label_003F: data.SetData(MarketDataType.Open, num2); Label_0049: data.SetData(MarketDataType.Volume, num6); is2.Add(data); Label_005B: if (dcsv.Next()) { goto Label_01AF; } dcsv.Close(); stream.Close(); if ((((uint) num) - ((uint) num5)) <= uint.MaxValue) { goto Label_0125; } if ((((uint) num) & 0) == 0) { goto Label_00B0; } Label_00A4: data.SetData(MarketDataType.Low, num5); goto Label_003F; Label_00B0: data.SetData(MarketDataType.AdjustedClose, num); do { data.SetData(MarketDataType.Open, num2); if ((((uint) num) - ((uint) num6)) > uint.MaxValue) { goto Label_0049; } data.SetData(MarketDataType.Close, num3); data.SetData(MarketDataType.High, num4); } while ((((uint) num5) - ((uint) num3)) > uint.MaxValue); if (((uint) num2) >= 0) { goto Label_00A4; } goto Label_003F; Label_0125: if (((uint) num2) >= 0) { return is2; } goto Label_005B; Label_013C: num6 = dcsv.GetDouble("volume"); data = new LoadedMarketData(time, ticker); if ((((uint) num2) | 2) == 0) { goto Label_017C; } goto Label_00B0; Label_016E: num2 = dcsv.GetDouble("open"); Label_017C: num3 = dcsv.GetDouble("close"); num4 = dcsv.GetDouble("high"); num5 = dcsv.GetDouble("low"); goto Label_013C; Label_01AF: time = dcsv.GetDate("date"); num = dcsv.GetDouble("adj close"); if ((((uint) num3) + ((uint) num6)) <= uint.MaxValue) { goto Label_016E; } goto Label_00B0; } }