Beispiel #1
0
        public void StartTest(InputData inputData, FxAdvisorCore.SimpleAdvisor strategy, Account Account, bool isCloseAtTheEnd)
        {
            this.inputData   = inputData;
            this.strategy    = strategy;
            this.TestAccount = Account;

            //System.Threading.Thread t = new Thread(new ThreadStart(Run));
            //t.Start();
            Run(isCloseAtTheEnd);
        }
Beispiel #2
0
        public void StartTest(InputData inputData, FxAdvisorCore.SimpleAdvisor strategy, Account Account)
        {
            this.inputData   = inputData;
            this.strategy    = strategy;
            this.TestAccount = Account;

            //System.Threading.Thread t = new Thread(new ThreadStart(Run));
            //t.Start();
            StartTest(inputData, strategy, Account, true);
        }
Beispiel #3
0
 public HistorySimulator(BasicParam customParam, bool IsTestingMode, FxAdvisorCore.SimpleAdvisor advisor, StrategyParameter currentStrategyParam, string symbol, IMeta meta)
 {
     this.CustomParam  = customParam;
     this.IsSuccessful = false;
     if (IsTestingMode)
     {
         rootPath = System.Configuration.ConfigurationManager.AppSettings["QuotesFullPath"];
     }
     this.Advisor = advisor;
     this.CurrentStrategyParam = currentStrategyParam;
     this.Symbol = InputData.ConvertToStandardName(symbol);
     this.Meta   = meta;
 }
Beispiel #4
0
        public void StartTest(InputData inputData, FxAdvisorCore.SimpleAdvisor strategy, FuturePredictor fPred, bool debugMode, int notReadOnlyTimePercent)
        {
            this.inputData  = inputData;
            this.strategy   = strategy;
            this.fPredictor = fPred;

            if (notReadOnlyTimePercent < 0 || notReadOnlyTimePercent > 100)
            {
                throw new ArgumentException("notReadOnlyTimePercent should be from 0 to 100 instead of " + notReadOnlyTimePercent);
            }
            this.ReadOnlyPoint = (notReadOnlyTimePercent * this.inputData.Data.Count) / 100;

            this.fPredictor.Orders = ordersCollection;
            Run(debugMode);
            this.fPredictor.Orders = null;
        }
        public double StandardOptimizationFunction(StrategyParameter sParam, string directory,
                                                   FxAdvisorCore.SimpleAdvisor advisor, ConfigReader configReader, out StrategyResultStatistics srResult)
        {
            srResult = new StrategyResultStatistics();
            if (!IsValid(sParam))
            {
                return(Double.MinValue);
            }

            string cacheKey = CreateKey(SampleData.Symbol, sParam, SampleData.Data.First().DateTime, SampleData.Data.Last().DateTime);

            if (cacheResult.ContainsKey(cacheKey))
            {
                return(cacheResult[cacheKey]);
            }

            using (Log4Smart.Logger logger = new Log4Smart.Logger(false))
            {
                string strategyName = System.Configuration.ConfigurationManager.AppSettings["ExportAdvisorName"];
                try
                {
                    Engine engine = new Engine(logger, logger);
                    advisor.TesterInit(sParam, logger);
                    Account acc = new Account(DefaultAccount.Balance, DefaultAccount.Commission);
                    engine.StartTest(SampleData, advisor, acc);
                    srResult = acc.Statistics;
                    if (!engine.IsTestSuccessfull)
                    {
                        if (string.IsNullOrEmpty(directory))
                        {
                            directory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                        }

                        string fullDir = directory + string.Format("/errors/{0}/{1}/{2}/", SampleData.Symbol, Guid.NewGuid().ToString(), StartTime.ToString("yyyyMMdd"));
                        configReader.SaveCurrentParameters(strategyName, sParam, fullDir);
                        logger.SaveLogToFile(fullDir, "error");
                        cacheResult[cacheKey] = Double.MinValue;

                        return(Double.MinValue);
                    }
                    if (sParam.Contains("MinAmountOrdersFLP") && acc.Statistics.NumberOrders < sParam["MinAmountOrdersFLP"] && string.IsNullOrEmpty(directory))
                    {
                        cacheResult[cacheKey] = Double.MinValue;
                        return(Double.MinValue);
                    }

                    if (!string.IsNullOrEmpty(directory))
                    {
                        string fullDir = directory + "/" + this.StartTime.ToString("yyyyMMdd") + "_" + (acc.Balance.ToString()) + "$";
                        configReader.SaveCurrentParameters(strategyName, sParam, fullDir);
                        logger.SaveLogToFile(fullDir, "allData");
                    }
                    if (DefaultAccount.Commission > 0)
                    {
                        cacheResult[cacheKey] = acc.Statistics.CalculateConfidenceIntervalLow;
                    }
                    else
                    {
                        cacheResult[cacheKey] = 10 - acc.Statistics.CalculateConfidenceIntervalHigh;
                    }

                    return(cacheResult[cacheKey]);
                }
                catch (Exception exc)
                {
                    (logger as Log4Smart.IStrategyLogger).AddMessage("{0}", exc.ToString());
                    if (string.IsNullOrEmpty(directory))
                    {
                        directory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    }

                    string fullDir = directory + string.Format("/errors/{0}/{1}/", SampleData.Symbol, StartTime.ToString("yyyyMMdd"));
                    configReader.SaveCurrentParameters(strategyName, sParam, fullDir);
                    logger.SaveLogToFile(fullDir, "error");
                    cacheResult[cacheKey] = Double.MinValue;

                    return(Double.MinValue);
                }
            }
        }