Esempio n. 1
0
        public void JobDatesAreRespectedByAddUniverseAtInitialize()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(CoarseFundamentalTop3Algorithm),
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "3" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "-40.620%" },
                { "Drawdown", "0.300%" },
                { "Expectancy", "0" },
                { "Net Profit", "-0.285%" },
                { "Sharpe Ratio", "-9.435" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "-0.802" },
                { "Beta", "0.569" },
                { "Annual Standard Deviation", "0.032" },
                { "Annual Variance", "0.001" },
                { "Information Ratio", "-48.662" },
                { "Tracking Error", "0.024" },
                { "Treynor Ratio", "-0.531" },
                { "Total Fees", "$3.00" }
            },
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             startDate: new DateTime(2014, 03, 24),
                                             endDate: new DateTime(2014, 03, 25));
        }
Esempio n. 2
0
        public void InitialCashAmountIsRespected()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(BasicTemplateDailyAlgorithm),
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "246.584%" },
                { "Drawdown", "1.100%" },
                { "Expectancy", "0" },
                { "Net Profit", "3.464%" },
                { "Sharpe Ratio", "10.117" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "1.939" },
                { "Beta", "-0.12" },
                { "Annual Standard Deviation", "0.161" },
                { "Annual Variance", "0.026" },
                { "Information Ratio", "-4.537" },
                { "Tracking Error", "0.221" },
                { "Treynor Ratio", "-13.579" },
                { "Total Fees", "$32.60" }   // 10x times more than original BasicTemplateDailyAlgorithm
            },
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             initialCash: 1000000); // 1M vs 100K that is set in BasicTemplateDailyAlgorithm (10x)
        }
Esempio n. 3
0
        public void JobDatesAreRespected()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(BasicTemplateDailyAlgorithm),
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "17.560%" },
                { "Drawdown", "30.300%" },
                { "Expectancy", "0" },
                { "Net Profit", "38.142%" },
                { "Sharpe Ratio", "0.682" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "0.209" },
                { "Beta", "-0.136" },
                { "Annual Standard Deviation", "0.272" },
                { "Annual Variance", "0.074" },
                { "Information Ratio", "0.018" },
                { "Tracking Error", "0.422" },
                { "Treynor Ratio", "-1.363" },
                { "Total Fees", "$6.62" }
            },
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             startDate: new DateTime(2008, 10, 10),
                                             endDate: new DateTime(2010, 10, 10));
        }
Esempio n. 4
0
        public void FilterReturnsUniverseRegression()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("FilterUniverseRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "2" },
                { "Average Win", "0%" },
                { "Average Loss", "-0.02%" },
                { "Compounding Annual Return", "-1.629%" },
                { "Drawdown", "0.000%" },
                { "Expectancy", "-1" },
                { "Net Profit", "-0.021%" },
                { "Sharpe Ratio", "0" },
                { "Probabilistic Sharpe Ratio", "0%" },
                { "Loss Rate", "100%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "0" },
                { "Beta", "0" },
                { "Annual Standard Deviation", "0" },
                { "Annual Variance", "0" },
                { "Information Ratio", "0" },
                { "Tracking Error", "0" },
                { "Treynor Ratio", "0" },
                { "Total Fees", "$1.00" },
                { "OrderListHash", "e6bf5bf0ba1475d11fcb7524e04e6295" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 5
0
        public void RunRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("CustomConsolidatorRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "49" },
                { "Average Win", "0.25%" },
                { "Average Loss", "-0.01%" },
                { "Compounding Annual Return", "65.750%" },
                { "Drawdown", "0.300%" },
                { "Expectancy", "2.577" },
                { "Net Profit", "1.067%" },
                { "Sharpe Ratio", "6.873" },
                { "Probabilistic Sharpe Ratio", "89.382%" },
                { "Loss Rate", "80%" },
                { "Win Rate", "20%" },
                { "Profit-Loss Ratio", "16.88" },
                { "Alpha", "0.34" },
                { "Beta", "0.351" },
                { "Annual Standard Deviation", "0.068" },
                { "Annual Variance", "0.005" },
                { "Information Ratio", "0.865" },
                { "Tracking Error", "0.118" },
                { "Treynor Ratio", "1.336" },
                { "Total Fees", "$69.81" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
        public void RunRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("CustomConsolidatorRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "32" },
                { "Average Win", "0.42%" },
                { "Average Loss", "-0.02%" },
                { "Compounding Annual Return", "66.060%" },
                { "Drawdown", "0.300%" },
                { "Expectancy", "2.979" },
                { "Net Profit", "1.071%" },
                { "Sharpe Ratio", "8.939" },
                { "Probabilistic Sharpe Ratio", "88.793%" },
                { "Loss Rate", "81%" },
                { "Win Rate", "19%" },
                { "Profit-Loss Ratio", "20.22" },
                { "Alpha", "0.528" },
                { "Beta", "0.35" },
                { "Annual Standard Deviation", "0.08" },
                { "Annual Variance", "0.006" },
                { "Information Ratio", "1.287" },
                { "Tracking Error", "0.141" },
                { "Treynor Ratio", "2.045" },
                { "Total Fees", "$51.40" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 7
0
        public void FilterReturnsUniverseRegression()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("FilterUniverseRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "4" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "0%" },
                { "Drawdown", "0%" },
                { "Expectancy", "0" },
                { "Net Profit", "0%" },
                { "Sharpe Ratio", "0" },
                { "Probabilistic Sharpe Ratio", "0%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "0" },
                { "Beta", "0" },
                { "Annual Standard Deviation", "0" },
                { "Annual Variance", "0" },
                { "Information Ratio", "0" },
                { "Tracking Error", "0" },
                { "Treynor Ratio", "0" },
                { "Total Fees", "$2.00" },
                { "OrderListHash", "8b881cea3597910adf985b0d70c0e8bb" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 8
0
        public void RunPythonSliceGetByTypeRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("SliceGetByTypeRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "284.284%" },
                { "Drawdown", "2.200%" },
                { "Expectancy", "0" },
                { "Net Profit", "1.736%" },
                { "Sharpe Ratio", "8.894" },
                { "Probabilistic Sharpe Ratio", "67.609%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "-0.004" },
                { "Beta", "0.997" },
                { "Annual Standard Deviation", "0.222" },
                { "Annual Variance", "0.049" },
                { "Information Ratio", "-14.547" },
                { "Tracking Error", "0.001" },
                { "Treynor Ratio", "1.979" },
                { "Total Fees", "$3.45" },
                { "OrderListHash", "46d026d39478ff13853319c2f891af39" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 9
0
        public void RunPythonSliceGetByTypeRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("SliceGetByTypeRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "277.455%" },
                { "Drawdown", "2.200%" },
                { "Expectancy", "0" },
                { "Net Profit", "1.713%" },
                { "Sharpe Ratio", "8.755" },
                { "Probabilistic Sharpe Ratio", "67.311%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "-0.003" },
                { "Beta", "0.997" },
                { "Annual Standard Deviation", "0.219" },
                { "Annual Variance", "0.048" },
                { "Information Ratio", "-14.15" },
                { "Tracking Error", "0.001" },
                { "Treynor Ratio", "1.924" },
                { "Total Fees", "$3.26" },
                { "OrderListHash", "421674107" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 10
0
        public void FilterReturnsListRegression()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("BasicTemplateOptionsFilterUniverseAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "0%" },
                { "Drawdown", "0%" },
                { "Expectancy", "0" },
                { "Net Profit", "0%" },
                { "Sharpe Ratio", "0" },
                { "Probabilistic Sharpe Ratio", "0%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "0" },
                { "Beta", "0" },
                { "Annual Standard Deviation", "0" },
                { "Annual Variance", "0" },
                { "Information Ratio", "0" },
                { "Tracking Error", "0" },
                { "Treynor Ratio", "0" },
                { "Total Fees", "$1.00" },
                { "Fitness Score", "0" },
                { "Kelly Criterion Estimate", "0" },
                { "Kelly Criterion Probability Value", "0" },
                { "Sortino Ratio", "0" },
                { "Return Over Maximum Drawdown", "0" },
                { "Portfolio Turnover", "0" },
                { "Total Insights Generated", "0" },
                { "Total Insights Closed", "0" },
                { "Total Insights Analysis Completed", "0" },
                { "Long Insight Count", "0" },
                { "Short Insight Count", "0" },
                { "Long/Short Ratio", "100%" },
                { "Estimated Monthly Alpha Value", "$0" },
                { "Total Accumulated Estimated Alpha Value", "$0" },
                { "Mean Population Estimated Insight Value", "$0" },
                { "Mean Population Direction", "0%" },
                { "Mean Population Magnitude", "0%" },
                { "Rolling Averaged Population Direction", "0%" },
                { "Rolling Averaged Population Magnitude", "0%" },
                { "OrderListHash", "1935621950" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 11
0
        public void AlgorithmCompletesWhenCallingErroLogOnInit(Type algorithmType)
        {
            var parameters = new RegressionTests.AlgorithmStatisticsTestParameters("QuantConnect.Tests.Engine.AlgorithmLogTests+" + algorithmType.Name,
                                                                                   Activator.CreateInstance <BasicTemplateDailyAlgorithm>().ExpectedStatistics,
                                                                                   Language.CSharp,
                                                                                   AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameters.Algorithm,
                                             parameters.Statistics,
                                             parameters.AlphaStatistics,
                                             parameters.Language,
                                             parameters.ExpectedFinalStatus,
                                             algorithmLocation: "QuantConnect.Tests.dll");
        }
Esempio n. 12
0
        public void StopsAlgorithm()
        {
            Config.Set("algorithm-manager-time-loop-maximum", "0.05");
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(TrainingInitializeRegressionAlgorithm),
                                                                                  new Dictionary <string, string>(),
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.RuntimeError);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus);
        }
Esempio n. 13
0
        public void InvalidConfigurationAddSecurity()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(BasicTemplateDailyAlgorithm),
                                                                                  new Dictionary <string, string>(),
                                                                                  Language.CSharp,
                                                                                  // will throw on initialization
                                                                                  AlgorithmStatus.Running);

            var result = AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                                          parameter.Statistics,
                                                          parameter.AlphaStatistics,
                                                          parameter.Language,
                                                          parameter.ExpectedFinalStatus);

            // algorithm was never set
            Assert.IsEmpty(result.AlgorithmManager.AlgorithmId);
        }
Esempio n. 14
0
        public void InvalidConfigurationHistoryRequest()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(TestInvalidConfigurationAlgorithm),
                                                                                  new Dictionary <string, string>(),
                                                                                  Language.CSharp,
                                                                                  // will throw on initialization
                                                                                  AlgorithmStatus.Running);

            var result = AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                                          parameter.Statistics,
                                                          parameter.AlphaStatistics,
                                                          parameter.Language,
                                                          parameter.ExpectedFinalStatus,
                                                          setupHandler: "TestInvalidConfigurationSetupHandler");

            // algorithm was never set
            Assert.IsEmpty(result.AlgorithmManager.AlgorithmId);
            // let's assert initialize was called by the history call failed
            Assert.AreEqual(1, TestInvalidConfigurationAlgorithm.Count);
        }
Esempio n. 15
0
        public void SetBenchmarksSecurityTypes(SecurityType securityType)
        {
            _algorithm = BenchmarkTestSetupHandler.TestAlgorithm = new TestBenchmarkAlgorithm(securityType);
            _algorithm.StartDateToUse = new DateTime(2014, 05, 03);
            _algorithm.EndDateToUse   = new DateTime(2014, 05, 04);

            var results = AlgorithmRunner.RunLocalBacktest(nameof(TestBenchmarkAlgorithm),
                                                           new Dictionary <string, string> {
                { "Total Trades", "0" }
            },
                                                           null,
                                                           Language.CSharp,
                                                           AlgorithmStatus.Completed,
                                                           setupHandler: "BenchmarkTestSetupHandler");


            var benchmark = _algorithm.Benchmark as SecurityBenchmark;

            Assert.IsNotNull(benchmark);
            Assert.AreEqual(securityType, benchmark.Security.Type);
            Assert.IsNull(_algorithm.RunTimeError);
        }
        public void ClearsOtherCashAmounts()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(nameof(TestInitialCashAmountAlgorithm),
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "1" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "214.949%" },
                { "Drawdown", "1.200%" },
                { "Expectancy", "0" },
                { "Net Profit", "3.464%" },
                { "Sharpe Ratio", "16.598" },
                { "Probabilistic Sharpe Ratio", "98.038%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "-0.004" },
                { "Beta", "0.998" },
                { "Annual Standard Deviation", "0.133" },
                { "Annual Variance", "0.018" },
                { "Information Ratio", "-28.017" },
                { "Tracking Error", "0" },
                { "Treynor Ratio", "2.209" },
                { "Total Fees", "$34.45" }   // 10x times more than original BasicTemplateDailyAlgorithm
            },
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             initialCash: 1000000, // 1M vs 100K that is set in BasicTemplateDailyAlgorithm (10x)
                                             setupHandler: "TestInitialCashAmountSetupHandler");

            Assert.AreEqual(0, TestInitialCashAmountSetupHandler.TestAlgorithm.Portfolio.CashBook["EUR"].Amount);
            Assert.AreEqual(Currencies.USD, TestInitialCashAmountSetupHandler.TestAlgorithm.AccountCurrency);
        }
Esempio n. 17
0
        public void MonitorsAlgorithmState(AlgorithmStatus algorithmStatus)
        {
            AlgorithmManagerAlgorithmStatusTest.Loops           = 0;
            AlgorithmManagerAlgorithmStatusTest.AlgorithmStatus = algorithmStatus;
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("QuantConnect.Tests.Engine.AlgorithmManagerTests+AlgorithmManagerAlgorithmStatusTest",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "0" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "0%" },
                { "Drawdown", "0%" },
                { "Expectancy", "0" },
                { "Net Profit", "0%" },
                { "Sharpe Ratio", "0" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "0" },
                { "Beta", "0" },
                { "Annual Standard Deviation", "0" },
                { "Annual Variance", "0" },
                { "Information Ratio", "0" },
                { "Tracking Error", "0" },
                { "Treynor Ratio", "0" },
                { "Total Fees", "$0.00" }
            },
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             algorithmLocation: "QuantConnect.Tests.dll");

            Assert.AreEqual(1, AlgorithmManagerAlgorithmStatusTest.Loops);
        }
        public BacktestingResultHandler GetResults(string algorithm, DateTime algoStart, DateTime algoEnd)
        {
            // Required, otherwise LocalObjectStoreTests overwrites the "object-store-root" config value
            // and causes the algorithm to error out.
            Config.Reset();

            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters(algorithm,
                                                                                  new Dictionary <string, string>(),
                                                                                  Language.CSharp,
                                                                                  AlgorithmStatus.Completed);

            // The AlgorithmRunner uses the `RegressionResultHandler` but doesn't do any sampling.
            // It defaults to the behavior of the `BacktestingResultHandler` class in `results.ProcessSynchronousEvents()`
            var backtestResults = AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                                                   parameter.Statistics,
                                                                   parameter.AlphaStatistics,
                                                                   parameter.Language,
                                                                   parameter.ExpectedFinalStatus,
                                                                   startDate: algoStart,
                                                                   endDate: algoEnd);

            return(backtestResults.Results);
        }
Esempio n. 19
0
        public void RunPythonDictionaryFeatureRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("PythonDictionaryFeatureRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "3" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "-100%" },
                { "Drawdown", "99.600%" },
                { "Expectancy", "0" },
                { "Net Profit", "-99.552%" },
                { "Sharpe Ratio", "-0.126" },
                { "Probabilistic Sharpe Ratio", "1.663%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "3.017" },
                { "Beta", "-2.026" },
                { "Annual Standard Deviation", "7.946" },
                { "Annual Variance", "63.138" },
                { "Information Ratio", "-0.375" },
                { "Tracking Error", "7.962" },
                { "Treynor Ratio", "0.494" },
                { "Total Fees", "$0.00" },
                { "OrderListHash", "218e1e2f47242e521724787eb661c639" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             initialCash: 100000);
        }
Esempio n. 20
0
        public void RunPythonDictionaryFeatureRegressionAlgorithm()
        {
            var parameter = new RegressionTests.AlgorithmStatisticsTestParameters("PythonDictionaryFeatureRegressionAlgorithm",
                                                                                  new Dictionary <string, string> {
                { "Total Trades", "3" },
                { "Average Win", "0%" },
                { "Average Loss", "0%" },
                { "Compounding Annual Return", "-100%" },
                { "Drawdown", "99.600%" },
                { "Expectancy", "0" },
                { "Net Profit", "-99.604%" },
                { "Sharpe Ratio", "-0.126" },
                { "Probabilistic Sharpe Ratio", "1.658%" },
                { "Loss Rate", "0%" },
                { "Win Rate", "0%" },
                { "Profit-Loss Ratio", "0" },
                { "Alpha", "3.904" },
                { "Beta", "-2.545" },
                { "Annual Standard Deviation", "7.95" },
                { "Annual Variance", "63.196" },
                { "Information Ratio", "-0.367" },
                { "Tracking Error", "7.968" },
                { "Treynor Ratio", "0.393" },
                { "Total Fees", "$0.00" },
                { "OrderListHash", "0bf01ae8e3f415e3de14ddd11ab0c447" }
            },
                                                                                  Language.Python,
                                                                                  AlgorithmStatus.Completed);

            AlgorithmRunner.RunLocalBacktest(parameter.Algorithm,
                                             parameter.Statistics,
                                             parameter.AlphaStatistics,
                                             parameter.Language,
                                             parameter.ExpectedFinalStatus,
                                             initialCash: 100000);
        }
Esempio n. 21
0
        public void WarmupDifferentResolutions(Resolution resolution, SecurityType securityType)
        {
            _algorithm = TestSetupHandler.TestAlgorithm = new TestWarmupAlgorithm(resolution);

            _algorithm.SecurityType = securityType;
            if (securityType == SecurityType.Forex)
            {
                _algorithm.StartDateToUse = new DateTime(2014, 05, 03);
                _algorithm.EndDateToUse   = new DateTime(2014, 05, 04);
            }
            else if (securityType == SecurityType.Equity)
            {
                _algorithm.StartDateToUse = new DateTime(2013, 10, 09);
                _algorithm.EndDateToUse   = new DateTime(2013, 10, 10);
            }
            else if (securityType == SecurityType.Crypto)
            {
                _algorithm.StartDateToUse = new DateTime(2018, 04, 06);
                _algorithm.EndDateToUse   = new DateTime(2018, 04, 07);
            }

            AlgorithmRunner.RunLocalBacktest(nameof(TestWarmupAlgorithm),
                                             new Dictionary <string, string> {
                { "Total Trades", "1" }
            },
                                             null,
                                             Language.CSharp,
                                             AlgorithmStatus.Completed,
                                             setupHandler: "TestSetupHandler");

            int estimateExpectedDataCount;

            switch (resolution)
            {
            case Resolution.Tick:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 4) * 60;
                break;

            case Resolution.Second:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60 * 60;
                break;

            case Resolution.Minute:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60;
                break;

            case Resolution.Hour:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6);
                break;

            case Resolution.Daily:
                // Warmup is 2 days. During warmup we expect the daily data point which goes from T-2 to T-1, once warmup finished,
                // we will get T-1 to T data point which is let through but the data feed since the algorithm starts at T
                estimateExpectedDataCount = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }

            Log.Debug($"WarmUpDataCount: {_algorithm.WarmUpDataCount}. Resolution {resolution}. SecurityType {securityType}");
            Assert.GreaterOrEqual(_algorithm.WarmUpDataCount, estimateExpectedDataCount);
        }
        public void WarmupDifferentResolutions(Resolution resolution, SecurityType securityType)
        {
            _algorithm = TestSetupHandler.TestAlgorithm = new TestWarmupAlgorithm(resolution);

            _algorithm.SecurityType = securityType;
            if (securityType == SecurityType.Forex)
            {
                _algorithm.StartDateToUse = new DateTime(2014, 05, 03);
                _algorithm.EndDateToUse   = new DateTime(2014, 05, 04);
            }
            else if (securityType == SecurityType.Equity)
            {
                _algorithm.StartDateToUse = new DateTime(2013, 10, 09);
                _algorithm.EndDateToUse   = new DateTime(2013, 10, 10);
            }
            else if (securityType == SecurityType.Crypto)
            {
                _algorithm.StartDateToUse = new DateTime(2018, 04, 06);
                _algorithm.EndDateToUse   = new DateTime(2018, 04, 07);
            }

            AlgorithmRunner.RunLocalBacktest(nameof(TestWarmupAlgorithm),
                                             new Dictionary <string, string> {
                { "Total Trades", "1" }
            },
                                             null,
                                             Language.CSharp,
                                             AlgorithmStatus.Completed,
                                             setupHandler: "TestSetupHandler");

            int estimateExpectedDataCount;

            switch (resolution)
            {
            case Resolution.Tick:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 4) * 60 * 60;
                break;

            case Resolution.Second:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60 * 60;
                break;

            case Resolution.Minute:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6) * 60;
                break;

            case Resolution.Hour:
                estimateExpectedDataCount = 2 * (securityType == SecurityType.Forex ? 19 : 6);
                break;

            case Resolution.Daily:
                estimateExpectedDataCount = 2;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }

            Log.Trace($"WarmUpDataCount: {_algorithm.WarmUpDataCount}. Resolution {resolution}. SecurityType {securityType}");
            Assert.GreaterOrEqual(_algorithm.WarmUpDataCount, estimateExpectedDataCount);
        }