public void TestBollingerStrategy()
        {
            var bolStrategy = new TradeStrategyLib.Models.BollingerStrategy(25, 2, 2, 1000000.00, 150);
            var backtest    = new StrategyBacktester(bolStrategy, _data);

            backtest.Compute();

            var pnlHistory = backtest.GetPnLHistory();
            var totalPnl   = backtest.GetTotalPnl();
            var maxDD      = backtest.GetMaximumDrawdown();
            var vol        = backtest.GetStrategyVol();

            // Check if results are empty
            // NOTE FRZ: This test should be more rigorous with expected results to test
            // but I don't have the time.
            Assert.IsNotNull(pnlHistory);
            Assert.IsNotNull(totalPnl);
            Assert.IsNotNull(maxDD);
            Assert.IsNotNull(vol);
        }
Beispiel #2
0
        /// <summary>
        /// Callback method for Launch MA Test button.
        /// Launches the MA strategy backtest.
        /// </summary>
        /// <param name="control">Exposes method to ribbon</param>
        public void TestBollinger(CustomUI.IRibbonControl control)
        {
            #region TestBollinger sanity checks
            // --> On imported data
            var importer = DataImporter.DataImporter.Instance;
            List <DataTypes.Quote> data = importer.GetData();
            if (data == null)
            {
                MessageBox.Show("Please import data before lauching test");
                return;
            }
            // --> On strategy parameters
            if (this._bolAmount == null)
            {
                MessageBox.Show("Please input amount to invest in strategy");
                return;
            }
            if (this._bolShortLevel == null)
            {
                MessageBox.Show("Please input Moving Average Short Level parameter");
                return;
            }
            if (this._bolUpperBound == null)
            {
                MessageBox.Show("Please input Upper Bound coefficient parameter");
                return;
            }
            if (this._bolLowerBound == null)
            {
                MessageBox.Show("Please input Lower Bound coefficient parameter");
                return;
            }
            if (this._bolTakeProfitInBps == null)
            {
                MessageBox.Show("Please input Moving Average Take Profit parameter");
                return;
            }
            #endregion

            // Compute the backtest and get the results
            var bol_Strategy = new TradeStrategyLib.Models.BollingerStrategy((int)this._bolShortLevel, (double)this._bolUpperBound,
                                                                             (double)this._bolLowerBound, (double)this._bolAmount,
                                                                             (double)this._bolTakeProfitInBps);
            var bol_Backtest = new StrategyBacktester(bol_Strategy, data);
            bol_Backtest.Compute();

            List <double> bol_pnlHistory = bol_Backtest.GetPnLHistory();
            if (!bol_pnlHistory.Any())
            {
                MessageBox.Show("Bollinger strategy did not generate any trades on this " +
                                "time interval");
                return;
            }
            List <DateTime> bol_dates    = bol_Backtest.GetDates();
            double          bol_totalPnl = bol_Backtest.GetTotalPnl();
            double?         maxDD        = bol_Backtest.GetMaximumDrawdown();
            double          vol          = bol_Backtest.GetStrategyVol();

            // Write the results
            DataWriter.WriteBacktestResults("Bollinger", bol_totalPnl, maxDD, vol, bol_pnlHistory, bol_dates);

            // Ensure all COM objects are realeased
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }