21 using System.Collections.Generic;
31 private readonly
bool _implementsDetermineTargetPercent;
72 foreach (var attributeName
in new[] {
"CreateTargets",
"OnSecuritiesChanged" })
74 if (!_model.HasAttr(attributeName))
76 throw new NotImplementedException($
"IPortfolioConstructionModel.{attributeName} must be implemented. Please implement this missing method on {model.GetPythonType()}");
82 _implementsDetermineTargetPercent = model.GetPythonMethod(
"DetermineTargetPercent") !=
null;
94 return _model.InvokeMethod<IEnumerable<IPortfolioTarget>>(nameof(
CreateTargets), algorithm, insights);
128 return _model.InvokeMethod<
bool>(nameof(
IsRebalanceDue), insights, algorithmUtc);
149 if (!_implementsDetermineTargetPercent)
155 Dictionary<Insight, double> dic;
157 if ((result as PyObject).TryConvert(out dic))
164 dic =
new Dictionary<Insight, double>();
165 foreach (var pyInsight
in result)
167 var insight = (pyInsight as PyObject).As<Insight>();
168 dic[insight] = result[pyInsight];