GetResults() публичный статический Метод

public static GetResults ( ) : Dictionary>
Результат Dictionary>
Пример #1
0
        public Dictionary <string, decimal> Run(Dictionary <string, object> items, IOptimizerConfiguration config)
        {
            Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain);

            _config = config;

            _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid()).ToString();

            if (_config.StartDate.HasValue && _config.EndDate.HasValue)
            {
                if (!items.ContainsKey("startDate"))
                {
                    items.Add("startDate", _config.StartDate);
                }
                if (!items.ContainsKey("endDate"))
                {
                    items.Add("endDate", _config.EndDate);
                }
            }

            string jsonKey = JsonConvert.SerializeObject(items);

            if (results.ContainsKey(jsonKey))
            {
                return(results[jsonKey]);
            }

            //just ignore id gene
            foreach (var pair in items.Where(i => i.Key != "Id"))
            {
                if (pair.Value is DateTime?)
                {
                    var cast = ((DateTime?)pair.Value);
                    if (cast.HasValue)
                    {
                        Config.Set(pair.Key, cast.Value.ToString("O"));
                    }
                }
                else
                {
                    Config.Set(pair.Key, pair.Value.ToString());
                }
            }

            if (EngineContext.SystemHandlers == null || EngineContext.Engine == null)
            {
                LaunchLean();
            }

            RunJob();

            if (_resultsHandler.FullResults != null && _resultsHandler.FullResults.Any())
            {
                results.Add(jsonKey, _resultsHandler.FullResults);
                OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results);
            }

            return(_resultsHandler.FullResults);
        }
Пример #2
0
        public Dictionary <string, decimal> Run(Dictionary <string, object> items)
        {
            Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain);

            _config = OptimizerAppDomainManager.GetConfig(AppDomain.CurrentDomain);

            _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid()).ToString();
            items.Remove("Id");

            if (_config.StartDate.HasValue && _config.EndDate.HasValue)
            {
                if (!items.ContainsKey("startDate"))
                {
                    items.Add("startDate", _config.StartDate);
                }
                if (!items.ContainsKey("endDate"))
                {
                    items.Add("endDate", _config.EndDate);
                }
            }

            string plain = string.Join(",", items.Select(s => s.Value));

            if (results.ContainsKey(plain))
            {
                return(results[plain]);
            }

            foreach (var pair in items)
            {
                if (pair.Value is DateTime?)
                {
                    var cast = ((DateTime?)pair.Value);
                    if (cast.HasValue)
                    {
                        Config.Set(pair.Key, cast.Value.ToString("O"));
                    }
                }
                else
                {
                    Config.Set(pair.Key, pair.Value.ToString());
                }
            }

            LaunchLean();

            results.Add(plain, _resultsHandler.FullResults);
            OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results);

            return(_resultsHandler.FullResults);
        }
Пример #3
0
        public virtual void Initialize()
        {
            var fullResults = OptimizerAppDomainManager.GetResults();
            //let's exclude non-trading tests and any marked as error/failure with -10 Sharpe
            var hasTraded = fullResults.Where(d => d.Value["TotalNumberOfTrades"] != 0 && d.Value["SharpeRatio"] > -10);

            SharpeData  = hasTraded.ToDictionary(k => k.Key, v => (double)v.Value["SharpeRatio"]);
            ReturnsData = hasTraded.ToDictionary(k => k.Key, v => (double)v.Value["CompoundingAnnualReturn"]);

            N = SharpeData.Count();
            var statistics = new DescriptiveStatistics(ReturnsData.Select(d => d.Value));

            V = new DescriptiveStatistics(SharpeData.Select(s => s.Value)).Variance;
            //measure only trading days
            T        = ((Config.EndDate - Config.StartDate).Value.TotalDays / 365) * days;
            Skewness = statistics.Skewness;
            Kurtosis = statistics.Kurtosis;
        }
Пример #4
0
        protected void ExtendFailureKeys(DateTime extending)
        {
            var failures = OptimizerAppDomainManager.GetResults().Where(r => r.Value["SharpeRatio"] == -10m);

            var previousKey  = JsonConvert.SerializeObject(Config.StartDate);
            var extendingKey = JsonConvert.SerializeObject(extending);

            var switching = new List <Tuple <string, string> >();

            foreach (var item in failures)
            {
                var after = item.Key.Replace(previousKey, extendingKey);
                switching.Add(Tuple.Create(item.Key, after));
            }

            foreach (var item in switching)
            {
                var before = OptimizerAppDomainManager.GetResults()[item.Item1];
                OptimizerAppDomainManager.GetResults().Remove(item.Item1);
                OptimizerAppDomainManager.GetResults().Add(item.Item2, before);
            }
        }
        public Dictionary <string, decimal> Run(Dictionary <string, object> items, IOptimizerConfiguration config)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain);

            _config = config;

            _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid().ToString("N")).ToString();

            if (_config.StartDate.HasValue && _config.EndDate.HasValue)
            {
                if (!items.ContainsKey("startDate"))
                {
                    items.Add("startDate", _config.StartDate);
                }
                if (!items.ContainsKey("endDate"))
                {
                    items.Add("endDate", _config.EndDate);
                }
            }

            string jsonKey = JsonConvert.SerializeObject(items.Where(i => i.Key != "Id"));

            if (!config.EnableRunningDuplicateParameters && results.ContainsKey(jsonKey))
            {
                return(results[jsonKey]);
            }

            //just ignore id gene
            foreach (var pair in items.Where(i => i.Key != "Id"))
            {
                if (pair.Value is DateTime?)
                {
                    var cast = ((DateTime?)pair.Value);
                    if (cast.HasValue)
                    {
                        Config.Set(pair.Key, cast.Value.ToString("O"));
                    }
                }
                else
                {
                    Config.Set(pair.Key, pair.Value.ToString());
                }
            }

            LogProvider.TraceLogger.Trace($"id: {_id} started.");
            LaunchLean();
            LogProvider.TraceLogger.Trace($"id: {_id} finished.");

            if (_resultsHandler.FullResults != null && _resultsHandler.FullResults.Any())
            {
                if (config.EnableRunningDuplicateParameters && results.ContainsKey(jsonKey))
                {
                    results.Remove(jsonKey);
                }
                results.Add(jsonKey, _resultsHandler.FullResults);
                OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results);
            }

            return(_resultsHandler.FullResults);
        }