Beispiel #1
0
        public ActionResult HandleCSVForm(NetworkSeed seed)
        {
            var stream = seed.File.InputStream;
            List <StockHistory> history = parseCSV(stream);
            var historyForTrain         = history.GetRange(0, (int)(history.Count * 0.8));

            #region hide
            historyForTrain = history;
            #endregion
            NNPredictor predictor = new NNPredictor(historyForTrain, parameters);

            var stock = new Stock
            {
                Name   = seed.Name,
                Ticker = seed.Ticker,
                Data   = BlobConverter <NNPredictor> .Encode(predictor)
            };
            db.Stocks.Add(stock);
            db.SaveChanges();
            var stockId = stock.Id;

            db.StocksHistory.AddRange(history.Select(x => { x.StockId = stockId; return(x); }));
            savePredictedStockHistory(history, stockId, predictor);
            db.SaveChanges();

            return(RedirectToAction("Edit"));
        }
Beispiel #2
0
        public IHttpActionResult MakePrediction(PredictionSeed seed)
        {
            NNPredictor predictor = BlobConverter <NNPredictor> .Decode(db.Stocks.Find(seed.id).Data);

            List <StockHistory> history  = new List <StockHistory>();
            StockHistory        firstDay = new StockHistory
            {
                Close  = seed.day1.Close,
                Volume = seed.day1.Volume
            };

            history.Add(firstDay);
            StockHistory secondDay = new StockHistory
            {
                Close  = seed.day2.Close,
                Volume = seed.day2.Volume
            };

            history.Add(secondDay);
            StockHistory thirdDay = new StockHistory
            {
                Close  = seed.day3.Close,
                Volume = seed.day3.Volume
            };

            history.Add(thirdDay);

            var output = predictor.Predict(history)[0][0];

            return(Ok(output));
        }
Beispiel #3
0
        private void savePredictedStockHistory(List <StockHistory> history, int id, NNPredictor predictor)
        {
            int size = parameters.LagWindowSize;

            for (int i = 0; i < history.Count - size; i++)
            {
                var output    = predictor.Predict(history.GetRange(i, size));
                var predicted = new PredictedStockHistory
                {
                    Date    = history[i + size].Date,
                    Close   = output[0][0],
                    StockId = id
                };
                db.PredictedStockHistories.Add(predicted);
            }
        }