Esempio n. 1
0
        private static void Main(string[] args)
        {
            // create a virtual trade manager
            var virtualTradeManager = new VirtualTradeManager();

            // create day trading strategy
            var strategy = new DayTradingStrategy("NEOUSD");

            // create new backtester
            var tester = new BackTester();

            // test the strategy on bitfinex
            tester.Test(new ExchangeBitfinexAPI(), strategy);
        }
Esempio n. 2
0
        /// <summary>
        /// Backtest strategy for the specified symbol.
        /// </summary>
        /// <param name="api">exchange api</param>
        /// <param name="strategy">strategy to test</param>
        public void Test(ExchangeAPI api, IStrategy strategy, DateTime startTime)
        {
            // Get candle sticks
            var allCandles = _cache.Load(strategy.Symbol);

            if (allCandles == null)
            {
                allCandles = DownloadCandlesFromExchange(api, strategy.Symbol, startTime, DateTime.Now);

                _cache.Save(strategy.Symbol, allCandles);
            }

            // convert from utc->local date/teim
            foreach (var candle in allCandles)
            {
                candle.Timestamp = candle.Timestamp.AddHours(2);
            }


            // backtest strategy
            var virtualTradeManager = new VirtualTradeManager();

            for (int i = allCandles.Count - 50; i > 0; i--)
            {
                virtualTradeManager.Candle = allCandles[i];
                strategy.OnCandle(allCandles, i, virtualTradeManager);
            }


            // dump all trades to console
            foreach (var trade in virtualTradeManager.Trades)
            {
                ((VirtualTrade)trade).Dump();
            }

            // show results
            Console.WriteLine("");
            Console.WriteLine("Backtesting results");
            Console.WriteLine($"Symbol                : {strategy.Symbol} on {api.Name}");
            Console.WriteLine($"Period                : {allCandles[allCandles.Count - 1].Timestamp:dd-MM-yyyy HH:mm} / {allCandles[0].Timestamp:dd-MM-yyyy HH:mm}");

            Console.WriteLine($"Starting capital      : $ 1000");
            Console.WriteLine($"Ending capital        : $ {virtualTradeManager.AccountBalance:0.00}");
            virtualTradeManager.DumpStatistics();
            Console.ReadLine();
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            var startTime = new DateTime(2018, 5, 14, 0, 0, 0);
            var settings  = new Settings();

            // create a virtual trade manager
            var virtualTradeManager = new VirtualTradeManager();

            // create day trading strategy
            var strategy = new DayTradingStrategy("ETHBTC", settings);

            // create new backtester
            var tester = new BackTester();

            // test the strategy on bitfinex
            tester.Test(new ExchangeBitfinexAPI(), strategy, startTime);
        }