Hello guys,

i would like to extend the functionality of PortfolioTarget Class, which currently takes only Symbol and Quantity as arguments, with something like this:

class BasicPortfolioConstructionModel(PortfolioConstructionModel):
	def CreateTargets(self, algorithm: QCAlgorithm, insights: typing.List[Insight]):
        targets = []
        for insight in insights:
            target = Target(insight.Symbol, targetQty, insight.SourceModel, stop)
            targets.append(target)
        return targets
class Target(PortfolioTarget):
    def __init__(self, symbol, quantity, alpha, stop) -> None:
        super().__init__(symbol, quantity)
        self.alpha = alpha
        self.stop = stop

 

If I do that i get following error:

20210831 16:37:00.213 ERROR:: Extensions.SetRuntimeError(): Extensions.SetRuntimeError(): RuntimeError at 8/31/2021 4:37:00 PM UTC. Context: OnData Python.Runtime.PythonException: TypeError : No constructor matches given arguments: (<class 'QuantConnect.Symbol'>, <class 'int'>, <class 'str'>, <class 'int'>)
  File "/Lean/Algorithm.Python/BasicPortfolioConstructionModel.py", line 46, in CreateTargets
    target = Target(insight.Symbol, targetQty, insight.SourceModel, stop)
===
   at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
   at CallSite.Target(Closure , CallSite , Object , QCAlgorithm , Insight[] )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at QuantConnect.Algorithm.Framework.Portfolio.PortfolioConstructionModelPythonWrapper.CreateTargets(QCAlgorithm algorithm, Insight[] insights)+MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm/Portfolio/PortfolioConstructionModelPythonWrapper.cs:line 107
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at QuantConnect.Algorithm.QCAlgorithm.ProcessInsights(Insight[] insights) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm/QCAlgorithm.Framework.cs:line 178
   at QuantConnect.Algorithm.QCAlgorithm.OnFrameworkData(Slice slice) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm/QCAlgorithm.Framework.cs:line 163
   at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.OnFrameworkData(Slice slice) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 600
   at QuantConnect.Lean.Engine.AlgorithmManager.Run(AlgorithmNodePacket job, IAlgorithm algorithm, ISynchronizer synchronizer, ITransactionHandler transactions, IResultHandler results, IRealTimeHandler realtime, ILeanManager leanManager, IAlphaHandler alphas, CancellationToken token) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/AlgorithmManager.cs:line 117

 

My understanding is, that it can not extend it, due to the PortfolioTarget and IPortfolioTarget.

So, is it possible without rewriting the core.

Best Regards!