Beispiel #1
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 TestMovingAverage(CustomUI.IRibbonControl control)
        {
            #region TestMovingAverage 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._maAmount == null)
            {
                MessageBox.Show("Please input amount to invest in strategy");
                return;
            }
            if (this._maLongLevel == null)
            {
                MessageBox.Show("Please input Moving Average Long Level in strategy");
                return;
            }
            if (this._maShortLevel == null)
            {
                MessageBox.Show("Please input Moving Average Short Level parameter");
                return;
            }
            if (this._maTakeProfitInBps == null)
            {
                MessageBox.Show("Please input Moving Average Take Profit parameter");
                return;
            }
            #endregion

            // Compute the backtest and get the results
            var strategy = new TradeStrategyLib.Models.MAStrategy((int)this._maShortLevel, (int)this._maLongLevel,
                                                                  (double)this._maAmount, (double)this._maTakeProfitInBps);
            var backtest = new StrategyBacktester(strategy, data);
            backtest.Compute();

            List <double> pnlHistory = backtest.GetPnLHistory();
            if (!pnlHistory.Any())
            {
                MessageBox.Show("Moving average strategy did not generate any trades on this" +
                                " time interval");
                return;
            }

            List <DateTime> dates    = backtest.GetDates();
            double          totalPnl = backtest.GetTotalPnl();
            double?         maxDD    = backtest.GetMaximumDrawdown();
            double          vol      = backtest.GetStrategyVol();

            // Write the results
            DataWriter.WriteBacktestResults("Moving Average", totalPnl, maxDD, vol, pnlHistory, dates);

            // Ensure all COM objects are released
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        public void TestMAStrategy()
        {
            var maStrategy = new TradeStrategyLib.Models.MAStrategy(25, 100, 1000000.00, 150);
            var backtest   = new StrategyBacktester(maStrategy, _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 #3
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 TestParabolicSAR(CustomUI.IRibbonControl control)
        {
            #region TestParabolicSAR 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._SARAmount == null)
            {
                MessageBox.Show("Please input amount to invest in strategy");
                return;
            }
            if (this._SARAccFactorLevel == null)
            {
                MessageBox.Show("Please input Accelerator Factor parameter");
                return;
            }
            if (this._SARMaxAccFactorLevel == null)
            {
                MessageBox.Show("Please input Maximum Accelerator Factor parameter");
                return;
            }
            if (this._SARTakeProfitInBps == null)
            {
                MessageBox.Show("Please input SAR Take Profit parameter");
                return;
            }
            #endregion

            // Compute the backtest and get the results
            var Strategy = new TradeStrategyLib.Models.ParabolicSARStrategy((double)this._SARAccFactorLevel,
                                                                            (double)this._SARMaxAccFactorLevel,
                                                                            (double)this._SARAccFactorStep,
                                                                            (double)this._SARAmount,
                                                                            (double)this._SARTakeProfitInBps);
            var Backtest = new StrategyBacktester(Strategy, data);
            Backtest.Compute();

            List <double> pnlHistory = Backtest.GetPnLHistory();
            if (!pnlHistory.Any())
            {
                MessageBox.Show("Parabolic SAR strategy did not generate any trades " +
                                "in this time interval.");
                return;
            }
            List <DateTime> dates    = Backtest.GetDates();
            double          totalPnl = Backtest.GetTotalPnl();
            double?         maxDD    = Backtest.GetMaximumDrawdown();
            double          vol      = Backtest.GetStrategyVol();

            // Write the results
            DataWriter.WriteBacktestResults("Parabolic SAR", totalPnl, maxDD, vol, pnlHistory, dates);

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