public void TestSARStrategy()
        {
            var sarStrategy = new TradeStrategyLib.Models.ParabolicSARStrategy(20, 100, 5, 1000000.00, 150);
            var backtest    = new StrategyBacktester(sarStrategy, _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);
        }
Exemplo n.º 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 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();
        }