Python model interop: subclassable SlippageModel base, algorithm-level SetSlippageModel, None framework models, callable security seeder - #9678
Draft
jhonabreul wants to merge 2 commits into
Conversation
…el SetSlippageModel, None framework models, callable security seeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Python algorithms commonly subclass .NET models, pass callables as seeders, or pass
Noneas framework models. Today these crash at initialization with cryptic interop errors, e.g.:Changes:
SlippageModelconcrete base class (parallel toFeeModel) with a virtualGetSlippageApproximationreturning zero. Existing slippage models derive from it, so Python can subclass it.QCAlgorithm.SetSlippageModel(C# andPyObjectoverloads) applies a slippage model to all present and future securities. Later per-securitySecurity.SetSlippageModelcalls still win, and the model survives a laterSetBrokerageModel.BrokerageModelSecurityInitializer(IBrokerageModel, PyObject)constructor accepts anISecuritySeeder, a plain callable (wrapped intoFuncSecuritySeeder), orNone. Anything else raises a prescriptive error naming the accepted inputs.PyObjectsetters (SetAlpha,SetExecution,SetPortfolioConstruction,SetRiskManagement,SetUniverseSelection) acceptNoneas the corresponding null model.PythonWrapper.ValidateImplementationOfreports missing members as snake-cased Python signatures, e.g.get_slippage_approximation(asset, order).Deferred: clearer errors when instantiating a subclass of a .NET interface — needs a pythonnet-side change, cannot be intercepted from Lean.
Related Issue
N/A
Motivation and Context
These are the natural, type-checker-friendly ways to declare custom models from Python. They compile green and die at initialization with cryptic interop errors.
Requires Documentation Change
Docs can recommend subclassing
SlippageModeland document the new algorithm-levelset_slippage_model.How Has This Been Tested?
AlgorithmSlippageModelRegressionAlgorithm(C# + Python, identical statistics) covering the algorithm-level slippage model, per-security precedence, callable seeder, andNoneframework models.AlgorithmModelsTests,SecurityCustomModelTests,BrokerageModelSecurityInitializerTests, andPythonWrapperTestscover the new surfaces and error cases.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>