16 using Newtonsoft.Json;
17 using Newtonsoft.Json.Linq;
36 public decimal?
Current {
get;
private set; }
46 public Target(
string target,
Extremum extremum, decimal? targetValue): base(target, targetValue)
74 if (
string.IsNullOrEmpty(jsonBacktestResult))
76 throw new ArgumentNullException(nameof(jsonBacktestResult), $
"Target.MoveAhead(): {Messages.OptimizerObjectivesCommon.NullOrEmptyBacktestResult}");
79 var token = GetTokenInJsonBacktest(jsonBacktestResult,
Target);
84 var computedValue = token.Value<
string>().ToNormalizedDecimal();
102 Reached?.Invoke(
this, EventArgs.Empty);
106 public static JToken GetTokenInJsonBacktest(
string jsonBacktestResult,
string target)
108 var jObject = JObject.Parse(jsonBacktestResult);
109 var path = target.Replace(
"[",
string.Empty, StringComparison.InvariantCultureIgnoreCase)
110 .Replace(
"]",
string.Empty, StringComparison.InvariantCultureIgnoreCase)
111 .Replace(
"\'",
string.Empty, StringComparison.InvariantCultureIgnoreCase).Split(
".");
113 foreach (var key
in path)
115 if (jObject.TryGetValue(key, StringComparison.OrdinalIgnoreCase, out token))
117 if (token is not JValue)
119 jObject = token.ToObject<JObject>();