public void EvaluateTest()
        {
            var originalHours = CurrentHours(_config);

            OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, new Dictionary <string, Dictionary <string, decimal> >());

            OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain).Add("key", new Dictionary <string, decimal>()
            {
                { "SharpeRatio", 123m }
            });

            //will not adapt on first result
            Assert.AreEqual(originalHours, CurrentHours(_config));
            _unit.Evaluate(Mock.Of <IChromosome>());
            Assert.AreEqual(originalHours, CurrentHours(_config));

            var fitness = _unit.Evaluate(Mock.Of <IChromosome>());

            var actualHours = CurrentHours(_config);

            //sharpe improved by 50%, period window should increase by 24 hours

            Assert.AreEqual(72, Math.Round(actualHours));

            actualHours = CurrentHours(_config);
            fitness     = _unit.Evaluate(Mock.Of <IChromosome>());
            actualHours = CurrentHours(_config);

            //50% again

            Assert.AreEqual(108, Math.Round(actualHours));
        }
        public void ExtendFailureKeysTest()
        {
            var failure = new Dictionary <string, decimal> {
                { "SharpeRatio", -10m }
            };
            var success = new Dictionary <string, decimal> {
                { "SharpeRatio", 1.5m }
            };
            var extending = new DateTime(2001, 1, 1);

            var failureKey = JsonConvert.SerializeObject(new Dictionary <string, object> {
                { "startDate", _config.StartDate }, { "period", 123 }
            });
            var successKey = JsonConvert.SerializeObject(new Dictionary <string, object> {
                { "startDate", _config.StartDate }, { "period", 456 }
            });
            var expectedKey = JsonConvert.SerializeObject(new Dictionary <string, object> {
                { "startDate", extending }, { "period", 123 }
            });

            OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain).Add(failureKey, failure);
            OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain).Add(successKey, success);

            _unit.ExtendFailureKeysWrapper(extending);

            Assert.AreEqual(1.5m, OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain)[successKey]["SharpeRatio"]);
            Assert.AreEqual(-10m, OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain)[expectedKey]["SharpeRatio"]);
        }
Example #3
0
 private Dictionary<string, Dictionary<string, decimal>> GetResults()
 {
     if (ScenarioContext.Current.Get<OptimizerConfiguration>().UseSharedAppDomain)
     {
         return SingleAppDomainManager.GetResults();
     }
     else
     {
         return OptimizerAppDomainManager.GetResults();
     }
 }