Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Begin a bar, for the specified date/time.
        /// </summary>
        /// <param name="dt">The date/time where the bar begins.</param>
        public void BeginBar(DateTime dt)
        {
            if (tw == null)
            {
                throw new EncogError("Must open file first.");
            }

            if (line != null)
            {
                throw new EncogError("Must call end bar");
            }

            line = new StringBuilder();
            line.Append(NumericDateUtil.DateTime2Long(dt));
            line.Append(format.Separator);
            line.Append(NumericDateUtil.Time2Int(dt));
        }