public void Initialize(
            EvaluationResultContext context,
            IDictionary <ParameterAttribute, object> parameterValues,
            DateTime startDate,
            DateTime endDate,
            TradeMetric metric)
        {
            if (context == null || parameterValues == null || metric == null)
            {
                throw new ArgumentNullException();
            }

            var serializableParameterValues = new SerializableParameterValues();

            serializableParameterValues.Initialize(parameterValues);

            for (var i = 0; i < serializableParameterValues.Parameters.Length; ++i)
            {
                _parameterValueProperties[i].SetValue(this, serializableParameterValues.Parameters[i].Value);
            }

            for (var i = 0; i < metric.ERatios.Length; ++i)
            {
                _eRatioProperties[i].SetValue(this, metric.ERatios[i]);
            }

            StartDate               = startDate;
            EndDate                 = endDate;
            InitialEquity           = metric.InitialEquity;
            FinalEquity             = metric.FinalEquity;
            NetProfit               = metric.NetProfit;
            ProfitRatio             = metric.ProfitRatio;
            AnnualProfitRatio       = metric.AnnualProfitRatio;
            TotalTradingTimes       = metric.TotalTradingTimes;
            ProfitTimesRatio        = metric.ProfitTimesRatio;
            AverageProfitPerTrading = metric.AverageProfitPerTrading;
            AverageLossPerTrading   = metric.AverageLossPerTrading;
            MaxDrawDown             = metric.MaxDrawDown;
            MaxDrawDownRatio        = metric.MaxDrawDownRatio;
            Mar         = metric.Mar;
            Expectation = ProfitTimesRatio * AverageProfitPerTrading - (1.0 - ProfitTimesRatio) * AverageLossPerTrading;

            var b = AverageProfitPerTrading / AverageLossPerTrading;

            BestFactor = (b * ProfitTimesRatio - (1.0 - ProfitTimesRatio)) / b;

            ContextId        = context.ContextId;
            ContextDirectory = context.RootDirectory;
        }
        public EvaluationResultContext CreateNewContext()
        {
            ++_contextId;

            var contextRootDirectory = Path.Combine(_rootDirectory, _contextId.ToString(CultureInfo.InvariantCulture));

            if (!Directory.Exists(contextRootDirectory))
            {
                Directory.CreateDirectory(contextRootDirectory);
            }

            var context = new EvaluationResultContext(_contextId, contextRootDirectory);

            return(context);
        }