コード例 #1
0
ファイル: MarketPrices.cs プロジェクト: miguelqvd/QSTK.Net
 public static MarketPrices ReadData(IEnumerable<string> symbols,
                                             string dataItem, TimeSeries timeSeries)
 {
     List<string> symbolsList = symbols.OrderBy(x => x).ToList();
     MarketPrices allData2 = For(symbolsList, dataItem, timeSeries);
     return allData2;
 }
コード例 #2
0
ファイル: DataAccessTests.cs プロジェクト: miguelqvd/QSTK.Net
        public void BasicDataAccessTest()
        {
            var da = DataAccess.GetInstance();

            var timestamps = new TimeSeries(new[] { new DateTime(2012, 08, 30) });
            IEnumerable<string> symbols = new List<string> { @"$DJI" };
            da.GetMarketData(symbols, "Close", timestamps);
        }
コード例 #3
0
ファイル: DataAccess.cs プロジェクト: miguelqvd/QSTK.Net
        /// <summary>
        /// Read data into a DataFrame, but check to see if it is in a cache first.
        /// @param TimeSeries: List of TimeSeries for which the data values are needed. TimeSeries must be sorted.
        /// @param symbols: The list of symbols for which the data values are needed
        /// @param dataItem: The dataItem needed. Like open, close, volume etc.  May be a list, in which case a list of DataFrame is returned.
        /// @param bIncDelist: If true, delisted securities will be included.
        /// @note: If a symbol is not found then a message is printed. All the values in the column for that stock will be NaN. Execution then 
        /// continues as usual. No errors are raised at the moment.
        /// </summary>
        public MarketPrices GetMarketData(IEnumerable<string> symbols, string dataItem, TimeSeries timeSeries)
        {
            string key = GetCacheKey(timeSeries, symbols, dataItem);

            MarketPrices data = ReadCache(key);
            if (data != null) return data;
            data = MarketPrices.ReadData(symbols, dataItem, timeSeries);
            CacheData(key, data);
            return data;
        }
コード例 #4
0
ファイル: MarketPrices.cs プロジェクト: miguelqvd/QSTK.Net
 private void ReadStock(string dataItem, string symbol, TimeSeries timeSeries)
 {
     try
     {
         StockPrices prices = StockPrices.ReadStock(symbol, dataItem, timeSeries);
         Add(symbol, prices);
     }
     catch (FileNotFoundException)
     {
         Console.WriteLine("  Missing stock data for '" + symbol + "'.  Ignoring.");
     }
 }
コード例 #5
0
ファイル: MarketPrices.cs プロジェクト: miguelqvd/QSTK.Net
        private static MarketPrices For(IEnumerable<string> symbols, string dataColumnName, TimeSeries timeSeries)
        {
            var r = new MarketPrices();

            Console.WriteLine("Reading market data...");
            Stopwatch stopwatch = Stopwatch.StartNew();

            foreach (string symbol in symbols)
                r.ReadStock(dataColumnName, symbol, timeSeries);
            
            stopwatch.Stop();
            Console.WriteLine("  Elapsed time: " + stopwatch.Elapsed);
            
            return r;
        }
コード例 #6
0
ファイル: StockPrices.cs プロジェクト: miguelqvd/QSTK.Net
        public static StockPrices ReadStock(string symbol, string dataColumnName, TimeSeries dayOffsets)
        {
            var prices = new StockPrices(dayOffsets.Count);
            string filePath = DataAccess.GetInstance().GetFilePath(symbol);
            using (var csv = new CsvReader2(filePath))
            {
                while (csv.Read())
                {
                    var date = csv.GetDateTime("Date");
                    int offset = dayOffsets.GetOffsetDaysFromStart(date);
                    if (offset < 0)
                        continue;

                    var price = csv.GetFloat(dataColumnName);
                    prices.Set(offset, price);
                }
            }
            return prices;
        }
コード例 #7
0
ファイル: DataAccess.cs プロジェクト: miguelqvd/QSTK.Net
        private string GetCacheKey(TimeSeries tsList, IEnumerable<string> symbolList, string dataItem)
        {
            // Create the hash for the symbols
            int hashsyms = symbolList.Select(sym => sym.GetHashCode()).Aggregate(0, (current, hash) => (current + hash)%10000000);

            // Create the hash for the TimeSeries
            int hashts = tsList.Start.GetHashCode() + tsList.Count;

            string hashstr = "qstk-" + "-" + Math.Abs(hashsyms) + "-" + Math.Abs(hashts) + "-" + dataItem.GetHashCode();

            return hashstr;
        }