Esempio n. 1
0
 private static void Stop(TestSignals signal)
 {
     signal.Exit();
     foreach (Process p in Running)
     {
         p.WaitForExit();
     }
     Running.Clear();
 }
Esempio n. 2
0
        protected void CalculateTradingResults()
        {
            double[]             trainingSignals = TrainingSignals.ToArray(); // cache values
            IEnumerable <double> trainingReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceChangeVariable, ProblemData.TrainingIndices);

            double[]             testSignals = TestSignals.ToArray(); // cache values
            IEnumerable <double> testReturns = ProblemData.Dataset.GetDoubleValues(ProblemData.PriceChangeVariable, ProblemData.TestIndices);

            OnlineCalculatorError errorState;
            double trainingSharpeRatio = OnlineSharpeRatioCalculator.Calculate(trainingReturns, trainingSignals, ProblemData.TransactionCosts, out errorState);

            TrainingSharpeRatio = errorState == OnlineCalculatorError.None ? trainingSharpeRatio : double.NaN;
            double testSharpeRatio = OnlineSharpeRatioCalculator.Calculate(testReturns, testSignals, ProblemData.TransactionCosts, out errorState);

            TestSharpeRatio = errorState == OnlineCalculatorError.None ? testSharpeRatio : double.NaN;

            double trainingProfit = OnlineProfitCalculator.Calculate(trainingReturns, trainingSignals, ProblemData.TransactionCosts, out errorState);

            TrainingProfit = errorState == OnlineCalculatorError.None ? trainingProfit : double.NaN;
            double testProfit = OnlineProfitCalculator.Calculate(testReturns, testSignals, ProblemData.TransactionCosts, out errorState);

            TestProfit = errorState == OnlineCalculatorError.None ? testProfit : double.NaN;
        }
Esempio n. 3
0
        private static int RunAll(ICollection <string> args)
        {
            if (args.Count == 0)
            {
                args = new List <string>(Tests.Keys);
            }

            int failures = 0;

            foreach (string key in args)
            {
                try
                {
                    Tests[key]();
                    int clientRuns = 3;
                    foreach (int numclients in new[] { 5 })
                    {
                        foreach (int numthreads in new[] { 3 })
                        {
                            foreach (int repeated in new[] { -50000 })
                            {
                                foreach (int recordSize in new[] { 1000 })
                                {
                                    TestSignals signal = new TestSignals(Guid.NewGuid().ToString("N"));
                                    try
                                    {
                                        using (Semaphore clients = new Semaphore(numclients, numclients, signal.Name + ".clients"))
                                        {
                                            Start("server", key, signal, recordSize);
                                            signal.ReadyWait();

                                            for (int ixclient = 0; ixclient < numclients; ixclient++)
                                            {
                                                Start("client", key, signal, ixclient, numthreads, clientRuns, repeated, recordSize);
                                                signal.ReadyWait(ixclient);
                                            }
                                            signal.Begin();

                                            int lockCount = 0;
                                            try
                                            {
                                                for (int ixclient = 0; ixclient < numclients; ixclient++)
                                                {
                                                    clients.WaitOne();
                                                    lockCount++;
                                                }
                                            }
                                            finally
                                            {
                                                for (int ixclient = 0; ixclient < lockCount; ixclient++)
                                                {
                                                    clients.Release();
                                                }
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        Stop(signal);
                                        signal.Dispose();
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("test '{0}' failed: {1}", key, e.Message);
                    failures++;
                }
            }
            return(failures);
        }