示例#1
0
        public void RunSinglePeriodBruteForceTest(object objParam)
        {
            try
            {
                TestParameters testParam = objParam as TestParameters;
                InputData      inData    = testParam.inData;
                DateTime       startDate = testParam.startDate;
                DateTime       endDate   = testParam.endDate;

                string outputPath = System.IO.Path.Combine(testParam.DefaultDirectory, inData.Symbol);
                if (!System.IO.Directory.Exists(outputPath))
                {
                    System.IO.Directory.CreateDirectory(outputPath);
                }

                List <StrategyParameter> listParams = testParam.OptimizationFunctionFactory.StratergyParameterRange.GetAllParameters();
                using (System.IO.StreamWriter completionLog = new System.IO.StreamWriter(string.Format("{2}\\ProgressIS_{0}_{1}.txt", inData.Symbol, startDate.ToString("yyyyMMdd"), outputPath)))
                {
                    List <KeyValuePair <StrategyParameter, StrategyResultStatistics> > listResult = new List <KeyValuePair <StrategyParameter, StrategyResultStatistics> >();

                    OptimizationFunctionIntND optTestFunction = testParam.OptimizationFunctionFactory.CreateOptimizationFunctionIntND(inData, startDate, EstimationFunctionType.RelativeStudent, new Account(10000000, 4));
                    bool IsCreateLogFiles = true;
                    foreach (StrategyParameter strategyParam in listParams)
                    {
                        StrategyResultStatistics sr;
                        double result;
                        if (IsCreateLogFiles)
                        {
                            optTestFunction.OptimizationFunction(strategyParam, out sr, outputPath);
                            IsCreateLogFiles = false;
                        }
                        else
                        {
                            result = optTestFunction.OptimizationFunction(strategyParam, out sr);
                        }

                        listResult.Add(new KeyValuePair <StrategyParameter, StrategyResultStatistics>(strategyParam, sr));
                        completionLog.WriteLine(listResult.Last().ToString());
                        completionLog.Flush();
                    }

                    IEnumerable <KeyValuePair <StrategyParameter, StrategyResultStatistics> > arrayResult =
                        listResult.OrderByDescending(p => p.Value.CalculateConfidenceIntervalLow);
                    using (System.IO.StreamWriter inSampleLog = new System.IO.StreamWriter(string.Format("{2}\\IS_{0}_{1}.txt", inData.Symbol, startDate.ToString("yyyyMMdd"), outputPath)))
                    {
                        DataContractSerializer ser = new DataContractSerializer(typeof(IEnumerable <KeyValuePair <StrategyParameter, StrategyResultStatistics> >));
                        ser.WriteObject(inSampleLog.BaseStream, arrayResult);
                    }
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
        /// <summary>
        /// Send the command to the undlerying socket
        /// </summary>
        /// <param name="command">The command to send</param>
        public string SendCommand(Command command)
        {
            try
            {
                semaphoreCommands.WaitOne();

                CheckForDisposed();

                if (command == null)
                {
                    throw new ArgumentNullException("command");
                }

                return(Dispatcher.Dispatch(command));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                semaphoreCommands.Release();
            }
        }