コード例 #1
0
        public void Initialize(string[] args)
        {
            _config = LoadConfig(args);
            _file.File.Copy(_config.ConfigPath, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            string path = _config.AlgorithmLocation;

            if (!string.IsNullOrEmpty(path))
            {
                _file.File.Copy(path, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.IO.Path.GetFileName(path)), true);
                string pdb = path.Replace(System.IO.Path.GetExtension(path), ".pdb");

                //due to locking issues, need to manually clean to update pdb
                if (!_file.File.Exists(pdb))
                {
                    _file.File.Copy(pdb, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.IO.Path.GetFileName(pdb)), true);
                }
            }

            OptimizerAppDomainManager.Initialize(_config);

            OptimizerFitness fitness = (OptimizerFitness)Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName, false, BindingFlags.Default, null,
                                                                                                        new[] { _config }, null, null);

            _manager.Initialize(_config, fitness);
            _manager.Start();
        }
コード例 #2
0
        /// <summary>
        /// Applies standard filters to eliminate some false positive optimizer results
        /// </summary>
        /// <param name="result">The statistic results</param>
        /// <param name="fitness">The calling fitness</param>
        /// <returns></returns>
        public bool IsSuccess(Dictionary <string, decimal> result, OptimizerFitness fitness)
        {
            if (!fitness.Config.EnableFitnessFilter)
            {
                return(true);
            }

            //using config ignore a result with negative return or disable this single filter and still apply others
            if (fitness.GetType() != typeof(CompoundingAnnualReturnFitness) && !fitness.Config.IncludeNegativeReturn && result["CompoundingAnnualReturn"] < 0)
            {
                return(false);
            }

            //must meet minimum trading activity if configured
            if (fitness.Config.MinimumTrades > 0 && result["TotalNumberOfTrades"] < fitness.Config.MinimumTrades)
            {
                return(false);
            }

            //Consider not trading a failure
            if (result["TotalNumberOfTrades"] == 0)
            {
                return(false);
            }

            //Consider 100% loss rate a failure
            if (result["LossRate"] == 1)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            _config = LoadConfig(args);
            File.Copy(_config.ConfigPath, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            string path = _config.AlgorithmLocation;

            if (!string.IsNullOrEmpty(path))
            {
                File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(path)), true);
                string pdb = path.Replace(Path.GetExtension(path), ".pdb");
                if (File.Exists(pdb))
                {
                    File.Copy(pdb, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pdb)), true);
                }
            }

            AppDomainManager.Initialize(_config);

            OptimizerFitness instance = (OptimizerFitness)Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName, false, BindingFlags.Default, null,
                                                                                                         new[] { _config }, null, null);

            var manager = new GeneManager(_config, instance);

            manager.Start();

            Console.ReadKey();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            _config = LoadConfig(args);
            string path = _config.ConfigPath;

            System.IO.File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            path = _config.AlgorithmLocation;
            if (!string.IsNullOrEmpty(path))
            {
                System.IO.File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(path)), true);
                string pdb = path.Replace(Path.GetExtension(path), ".pdb");
                if (File.Exists(pdb))
                {
                    System.IO.File.Copy(pdb, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pdb)), true);
                }
            }

            _writerLock = new object();

            using (_writer = System.IO.File.AppendText("optimizer.txt"))
            {
                AppDomainManager.Initialize(_config);

                OptimizerFitness instance = (OptimizerFitness)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName, false, BindingFlags.Default, null,
                                                                                                                               new[] { _config }, null, null);

                var manager = new GeneticManager(_config, instance, new LogManager());
                manager.Start();
            }

            Console.ReadKey();
        }
コード例 #5
0
 public void Initialize(IOptimizerConfiguration config, OptimizerFitness fitness)
 {
     _config   = config;
     _fitness  = fitness;
     _executor = new SmartThreadPoolTaskExecutor()
     {
         MinThreads = 1
     };
     _executor.MaxThreads = _config.MaxThreads > 0 ? _config.MaxThreads : 8;
 }
コード例 #6
0
        public void Initialize(string[] args)
        {
            _config = LoadConfig(args);
            _file.File.Copy(_config.ConfigPath, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            string path = _config.AlgorithmLocation;

            if (!string.IsNullOrEmpty(path) && (path.Contains('\\') || path.Contains('/')))
            {
                _file.File.Copy(path, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.IO.Path.GetFileName(path)), true);
                string pdb = path.Replace(System.IO.Path.GetExtension(path), ".pdb");

                //due to locking issues, need to manually clean to update pdb
                if (!_file.File.Exists(pdb))
                {
                    _file.File.Copy(pdb, System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.IO.Path.GetFileName(pdb)), true);
                }
            }

            if (_config.UseSharedAppDomain)
            {
                SingleAppDomainManager.Initialize();
            }
            else
            {
                OptimizerAppDomainManager.Initialize();
            }

            OptimizerFitness fitness = (OptimizerFitness)Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName, false, BindingFlags.Default, null,
                                                                                                        new object[] { _config, new FitnessFilter() }, null, null);

            if (_manager == null)
            {
                if (new[] { typeof(SharpeMaximizer), typeof(NFoldCrossReturnMaximizer), typeof(NestedCrossSharpeMaximizer), typeof(NFoldCrossSharpeMaximizer) }.Contains(fitness.GetType()))
                {
                    _manager = new MaximizerManager();
                    if (fitness.GetType() == typeof(OptimizerFitness))
                    {
                        LogProvider.ErrorLogger.Info("Fitness for shared app domain was switched to the default: SharpeMaximizer.");
                        fitness = new SharpeMaximizer(_config, new FitnessFilter());
                    }
                }
                else
                {
                    _manager = new GeneManager();
                }
            }

            _manager.Initialize(_config, fitness);
            _manager.Start();
        }
コード例 #7
0
        public override double Evaluate(IChromosome chromosome)
        {
            this.Name = "DualPeriodSharpe";

            var dualConfig = Clone <OptimizerConfiguration>((OptimizerConfiguration)Config);
            var start      = Config.StartDate.Value;
            var end        = Config.EndDate.Value;
            var diff       = end - start;

            dualConfig.StartDate = end;
            dualConfig.EndDate   = end + diff;

            var dualFitness = new OptimizerFitness(dualConfig, this.Filter);

            var    first  = base.Evaluate(chromosome);
            double second = -10;

            if (first > -10)
            {
                second = dualFitness.Evaluate(chromosome);
            }

            var fitness = new FitnessResult
            {
                Fitness = (first + second) / 2
            };

            fitness.Value = (decimal)base.GetValueFromFitness(fitness.Fitness);

            var output = string.Format($"Start: {Config.StartDate}, End: {Config.EndDate}, Start: {dualConfig.StartDate}, End: {dualConfig.EndDate}, "
                                       + $"Id: {((Chromosome)chromosome).Id}, Dual Period {this.Name}: {fitness.Value}");

            Program.Logger.Info(output);

            Config.StartDate = start;
            Config.EndDate   = end;

            return(fitness.Fitness);
        }
コード例 #8
0
 public GeneManager(IOptimizerConfiguration config, OptimizerFitness fitness)
 {
     _config  = config;
     _fitness = fitness;
 }
コード例 #9
0
 public void Initialize(IOptimizerConfiguration config, OptimizerFitness fitness)
 {
     _config  = config;
     _fitness = fitness;
     // _executor.MaxThreads = _config.MaxThreads > 0 ? _config.MaxThreads : 8;
 }
コード例 #10
0
 public GeneticManager(IOptimizerConfiguration config, OptimizerFitness fitness, ILogManager logManager)
 {
     _config     = config;
     _fitness    = fitness;
     _logManager = logManager;
 }