Exemple #1
0
        public void TestCSVLoader()
        {
            var loader = new CSVFinal();

            loader.DateFormat = "yyyy.MM.dd hh:mm:ss";

            var tickerAAPL = new TickerSymbol("AAPL", "NY");

            var             desc       = new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true);
            MarketMLDataSet marketData = new MarketMLDataSet(loader, 5, 1);

            marketData.AddDescription(desc);
            marketData.SequenceGrandularity = Util.Time.TimeUnit.Hours;
            var begin = new DateTime(2006, 1, 1);
            var end   = new DateTime(2007, 7, 31);

            loader.GetFile((AssemblyDirectory + "\\smallCSV.csv"));
            marketData.Load(begin, end);
            marketData.Generate();
            // first test the points
            IEnumerator <TemporalPoint> itr = marketData.Points.GetEnumerator();

            itr.MoveNext();
            TemporalPoint point = itr.Current;

            Assert.AreEqual(0, point.Sequence);
            Assert.AreEqual(1, point.Data.Length);
            Assert.AreEqual(1.12884, point[0]);
            Assert.AreEqual(5, marketData.Points.Count);
        }
        public void TestCSVLoader()
        {
            var loader = new CSVFinal();
            loader.DateFormat = "yyyy.MM.dd hh:mm:ss";

            var tickerAAPL = new TickerSymbol("AAPL", "NY");

            var desc = new MarketDataDescription(tickerAAPL, MarketDataType.Close, true, true);
            MarketMLDataSet marketData = new MarketMLDataSet(loader, 5, 1);
            marketData.AddDescription(desc);
            marketData.SequenceGrandularity = Util.Time.TimeUnit.Hours;
            var begin = new DateTime(2006, 1, 1);
            var end = new DateTime(2007, 7, 31);
            loader.GetFile((AssemblyDirectory + "\\smallCSV.csv"));
            marketData.Load(begin, end);
            marketData.Generate();
            // first test the points
            IEnumerator<TemporalPoint> itr = marketData.Points.GetEnumerator();
            itr.MoveNext();
            TemporalPoint point = itr.Current;

            Assert.AreEqual(0, point.Sequence);
            Assert.AreEqual(1, point.Data.Length);
            Assert.AreEqual(1.12884, point[0]);
            Assert.AreEqual(5, marketData.Points.Count);
        }
        public static void Generate(FileInfo dataDir)
        {
            IMarketLoader loader = new YahooFinanceLoader();
            var market = new MarketMLDataSet(loader,
                                             Config.INPUT_WINDOW, Config.PREDICT_WINDOW);
            var desc = new MarketDataDescription(
                Config.TICKER, MarketDataType.AdjustedClose, true, true);
            market.AddDescription(desc);

            var end = DateTime.Now; // end today
            var begin = new DateTime(end.Ticks); // begin 30 days ago

            // Gather training data for the last 2 years, stopping 60 days short of today.
            // The 60 days will be used to evaluate prediction.
            begin = begin.AddDays(-60);
            end = end.AddDays(-60);
            begin = begin.AddYears(-2);

            market.Load(begin, end);
            market.Generate();
            EncogUtility.SaveEGB(FileUtil.CombinePath(dataDir, Config.TRAINING_FILE), market);

            // create a network
            BasicNetwork network = EncogUtility.SimpleFeedForward(
                market.InputSize,
                Config.HIDDEN1_COUNT,
                Config.HIDDEN2_COUNT,
                market.IdealSize,
                true);

            // save the network and the training
            EncogDirectoryPersistence.SaveObject(FileUtil.CombinePath(dataDir, Config.NETWORK_FILE), network);
        }
        public static MarketMLDataSet GrabData()
        {
            IMarketLoader loader = new YahooFinanceLoader();
            var result = new MarketMLDataSet(loader,
                                             Config.INPUT_WINDOW, Config.PREDICT_WINDOW);
            var desc = new MarketDataDescription(Config.TICKER,
                                                 MarketDataType.AdjustedClose, true, true);
            result.AddDescription(desc);

            var end = DateTime.Now; // end today
            var begin = new DateTime(end.Ticks); // begin 30 days ago
            begin = begin.AddDays(-60);

            result.Load(begin, end);
            result.Generate();

            return result;
        }
        public static void Generate(string fileName)
        {

          
            FileInfo dataDir = new FileInfo(@Environment.CurrentDirectory);
            IMarketLoader loader = new CSVFinal();
            var market = new MarketMLDataSet(loader,CONFIG.INPUT_WINDOW, CONFIG.PREDICT_WINDOW);
          //  var desc = new MarketDataDescription(Config.TICKER, MarketDataType.Close, true, true);

            var desc = new MarketDataDescription(CONFIG.TICKER, MarketDataType.Close, true, true);
            market.AddDescription(desc);
            string currentDirectory =@"c:\";
            loader.GetFile(fileName);

            var end = DateTime.Now; // end today
            var begin = new DateTime(end.Ticks); // begin 30 days ago

            // Gather training data for the last 2 years, stopping 60 days short of today.
            // The 60 days will be used to evaluate prediction.
            begin = begin.AddDays(-600);
            end = begin.AddDays(200);
           
            Console.WriteLine("You are loading date from:" + begin.ToShortDateString() + " To :" + end.ToShortDateString());

            market.Load(begin, end);
            market.Generate();
            EncogUtility.SaveEGB(FileUtil.CombinePath(dataDir, CONFIG.SVMTRAINING_FILE), market);

            // create a network
            //BasicNetwork network = EncogUtility.SimpleFeedForward(
            //    market.InputSize,
            //    CONFIG.HIDDEN1_COUNT,
            //    CONFIG.HIDDEN2_COUNT,
            //    market.IdealSize,
            //    true);


            SupportVectorMachine network = new SupportVectorMachine(CONFIG.INPUT_WINDOW, true);
            TrainNetworks(network, market);
            // save the network and the training
            EncogDirectoryPersistence.SaveObject(FileUtil.CombinePath(dataDir,CONFIG.SVMTRAINING_FILE), network);
        }
        public static MarketMLDataSet GrabData(string newfileLoad)
        {
            IMarketLoader loader = new CSVLoader();
            loader.GetFile(newfileLoad);

            var result = new MarketMLDataSet(loader,
                                             Config.INPUT_WINDOW, Config.PREDICT_WINDOW);
          //  var desc = new MarketDataDescription(Config.TICKER,
                                              //   MarketDataType.Close, true, true);

            var desc = new MarketDataDescription(Config.TICKER,
                                     MarketDataType.Trade, true, true);
            result.AddDescription(desc);

            var end = DateTime.Now; // end today
            var begin = new DateTime(end.Ticks); // begin 30 days ago
            begin = begin.AddDays(-150);

            result.Load(begin, end);
            result.Generate();

            return result;
        }