Example #1
0
        public async Task GetHistoricalData_ValidSymbol_ReturnsData()
        {
            var data = await _downloadService.GetHistoricalData(_stock, DateTime.Now.AddDays(-10), refresh : true);

            Assert.NotNull(data);
            //Assert.IsTrue(data.Quotes.Any());
            //Assert.AreEqual(data.Quotes.First().Value.Date, data.BeginDate);
            //Assert.AreEqual(data.Quotes.Last().Value.Date, data.EndDate);
        }
Example #2
0
        public async Task FullTest(int numberOfHiddenLayers, int numberOfNeurons)
        {
            _stock.Name = await _downloadService.GetName(_stock);

            _stock.HistoricalData = await _downloadService.GetHistoricalData(_stock, _startDate, refresh : true);

            _trainingSession =
                new TrainingSession(_portfolio, _stock)
            {
                NumberAnns                  = 5000,
                NumberHiddenLayers          = numberOfHiddenLayers,
                NumberNeuronsPerHiddenLayer = numberOfNeurons,
                TrainSamplePercentage       = 0.55
            };

            var timer = new Stopwatch();

            timer.Start();

            _trainingSession.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "BestProfitLossCalculator" && timer.ElapsedMilliseconds > 7000)
                {
                    Trace.Write($"\n{_trainingSession.AllNetworksPLsStdDevs.Count:N0}");
                    Trace.Write($" -> PL: {_trainingSession.BestProfitLossCalculator.PL:C2}");
                    Trace.Write($" ({_trainingSession.BestProfitLossCalculator.PLPercentage:P2})");
                    Trace.Write($" | median: {_trainingSession.AllNetworksPL:C2}");
                    Trace.Write($" | acc: {_trainingSession.BestProfitLossCalculator.PercentageWinningTransactions:P2}");
                    Trace.Write($" | study1: {_trainingSession.BestPrediction.BuyLevel}");
                    Trace.Write($" | study2: {_trainingSession.BestPrediction.SellLevel}");

                    timer.Restart();
                }
            };

            _trainingSession.FindBestAnn(new CancellationToken(), new NeuralStockSettings());

            Console.Write("PL: {0:C2}", _trainingSession.BestProfitLossCalculator.PL);
            Console.Write(" ({0:P2})", _trainingSession.BestProfitLossCalculator.PLPercentage);
            Console.Write(" | median: {0:C2}", _trainingSession.AllNetworksPL);
            Console.Write(" | acc: {0:P2}", _trainingSession.BestProfitLossCalculator.PercentageWinningTransactions);

            Assert.Pass();
        }
Example #3
0
            public static Data GetData(Stock stock, IDownloaderService downloaderService, HistoricalData historicalData)
            {
                Data result = new Data();

                result.Quotes = historicalData.Quotes.Values.Select(x => new Skender.Stock.Indicators.Quote
                {
                    Date   = x.Date,
                    Low    = Convert.ToDecimal(x.Low),
                    High   = Convert.ToDecimal(x.High),
                    Open   = Convert.ToDecimal(x.Open),
                    Close  = Convert.ToDecimal(x.Close),
                    Volume = Convert.ToDecimal(x.Volume)
                }).ToList();

                var market = new Stock()
                {
                    Country = new Others(), Symbol = stock.Country.Id == Singapore.CountryId ? "^STI" : "^PSI20"
                };

                market.HistoricalData = downloaderService.GetHistoricalData(market, historicalData.BeginDate, historicalData.EndDate).Result;

                var commodity = new Stock()
                {
                    Country = new Others(), Symbol = "O87.SI"
                };

                commodity.HistoricalData = downloaderService.GetHistoricalData(commodity, historicalData.BeginDate, historicalData.EndDate).Result;

                result.MarketQuotes    = new List <Skender.Stock.Indicators.Quote>();
                result.CommodityQuotes = new List <Skender.Stock.Indicators.Quote>();

                for (var i = 0; i < historicalData.Quotes.Count; i++)
                {
                    var date = historicalData.Quotes.ElementAt(i).Key;
                    var closestMarketDate    = market.HistoricalData.Quotes.Keys.LastOrDefault(x => x <= date);
                    var closestCommodityDate = commodity.HistoricalData.Quotes.Keys.LastOrDefault(x => x <= date);

                    if (closestMarketDate == default)
                    {
                        result.MarketQuotes.Add(new Skender.Stock.Indicators.Quote {
                            Date = date
                        });
                    }
                    else
                    {
                        result.MarketQuotes.Add(new Skender.Stock.Indicators.Quote
                        {
                            Date   = date,
                            Low    = Convert.ToDecimal(market.HistoricalData.Quotes[closestMarketDate].Low),
                            High   = Convert.ToDecimal(market.HistoricalData.Quotes[closestMarketDate].High),
                            Open   = Convert.ToDecimal(market.HistoricalData.Quotes[closestMarketDate].Open),
                            Close  = Convert.ToDecimal(market.HistoricalData.Quotes[closestMarketDate].Close),
                            Volume = Convert.ToDecimal(market.HistoricalData.Quotes[closestMarketDate].Volume)
                        });
                    }

                    if (closestCommodityDate == default)
                    {
                        result.CommodityQuotes.Add(new Skender.Stock.Indicators.Quote {
                            Date = date
                        });
                    }
                    else
                    {
                        result.CommodityQuotes.Add(new Skender.Stock.Indicators.Quote
                        {
                            Date   = date,
                            Low    = Convert.ToDecimal(commodity.HistoricalData.Quotes[closestCommodityDate].Low),
                            High   = Convert.ToDecimal(commodity.HistoricalData.Quotes[closestCommodityDate].High),
                            Open   = Convert.ToDecimal(commodity.HistoricalData.Quotes[closestCommodityDate].Open),
                            Close  = Convert.ToDecimal(commodity.HistoricalData.Quotes[closestCommodityDate].Close),
                            Volume = Convert.ToDecimal(commodity.HistoricalData.Quotes[closestCommodityDate].Volume)
                        });
                    }
                }

                return(result);
            }