Ejemplo n.º 1
0
        public double EstimateFunction(StrategyParameter sParam, string directory)
        {
            if (previosResult.ContainsKey(sParam.ToString()))
            {
                return(previosResult[sParam.ToString()]);
            }

            using (Log4Smart.Logger logger = new Log4Smart.Logger(false))
            {
                Engine             engine   = new Engine(logger, logger);
                SuperAdaptStrategy strategy = new SuperAdaptStrategy(sParam, logger);
                int     initialMoney        = 10000000;
                Account acc = new Account(initialMoney);

                engine.StartTest(SampleData, strategy, acc);
                if (!engine.IsTestSuccessfull)
                {
                    logger.SaveLogToFile("errors", SampleData.Symbol + "_" + StartTime.ToString("yyyyMMdd"));
                    previosResult[sParam.ToString()] = 0;
                    return(0);
                }
                if (directory != string.Empty)
                {
                    logger.SaveLogToFile(directory + "/" + this.StartTime.ToString("yyyyMMdd") + "_" + (acc.Balance.ToString()) + "$", "allData");
                }

                previosResult[sParam.ToString()] = acc.Balance;
                return(acc.Balance);
            }
        }
Ejemplo n.º 2
0
 protected void InitComment()
 {
     if (TestingMode)
     {
         return;
     }
     TickComment.Clear();
     previousID       = -1;
     previousIDstring = string.Empty;
     TickComment.Append(param.ToString());
     IsWasChanged = false;
 }
Ejemplo n.º 3
0
        public override double OptimizationFunction(StrategyParameter sParam, string directory)
        {
            if (!IsValid(sParam))
            {
                return(0);
            }

            if (previosResult.ContainsKey(sParam.ToString()))
            {
                return(previosResult[sParam.ToString()]);
            }

            using (Log4Smart.Logger logger = new Log4Smart.Logger(false))
            {
                Engine             engine   = new Engine(logger, logger);
                MartinGaleStrategy strategy = new MartinGaleStrategy(sParam, logger);
                int     initialMoney        = 10000000;
                Account acc = new Account(initialMoney);
                engine.StartTest(SampleData, strategy, acc);
                if (!engine.IsTestSuccessfull)
                {
                    logger.SaveLogToFile(directory + "/errors", SampleData.Symbol + "_" + StartTime.ToString("yyyyMMdd"));
                    previosResult[sParam.ToString()] = 0;
                    return(0);
                }

                if (directory != string.Empty)
                {
                    logger.SaveLogToFile(directory + "/" + this.StartTime.ToString("yyyyMMdd") + "_" + (acc.Balance.ToString()) + "$", "allData");
                }

                if (acc.Balance > initialMoney && this.EstimationFunctionType == EstimationFunctionType.MostMoney8Deviation)
                {
                    previosResult[sParam.ToString()] = initialMoney + (acc.Balance - initialMoney) * (1 - acc.Statistics.GetDeviation);
                }
                else
                {
                    previosResult[sParam.ToString()] = acc.Balance;
                }
                return(previosResult[sParam.ToString()]);
            }
        }
Ejemplo n.º 4
0
 public SuperAdaptStrategy(StrategyParameter param, IStrategyLogger logger)
 {
     this.logger = logger;
     this.param  = param;
     this.logger.AddMessage("Start strategy with parameter {0}", param.ToString());
 }
 static string CreateKey(string symbol, StrategyParameter sParam, DateTime start, DateTime end)
 {
     return(symbol + sParam.ToString() + start.Ticks.ToString() + end.Ticks.ToString());
 }