QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.96k stars 3.29k forks source link

Support parameters change in real-time for live algorithms #8388

Open yul opened 3 weeks ago

yul commented 3 weeks ago

Expected Behavior

User is able to change parameters for an algorithm running on live mode and that may be handled by the algorithm to change it's state. For example, this can be EMA period: user changes it and the corresponding indicator is reset and warmed up from historical data, without the need to re-deploy algorithm. Also, maybe automatically log parameter values on deployment and when they change, to keep track of their actual values used in the algorithm.

Actual Behavior

Currently user has to re-deploy algorithm in order to update parameters.

Potential Solution

Not sure about implementation details, but for the user side QCAlgorithm class should probably have some callback, like def on_parameter_change(self, new_value, old_value), where it can pick up new parameter value and update algorithm state accordingly.

Checklist

Martin-Molinero commented 3 weeks ago

Hey @yul! Believe you can achieve similar functionality with the new command system, please take a look at https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/commands

yul commented 3 weeks ago

Hey @yul! Believe you can achieve similar functionality with the new command system, please take a look at https://www.quantconnect.com/docs/v2/writing-algorithms/live-trading/commands

I understand it can only be triggered via API, while I can do that, my clients who are not developers, but still want to use algorithms I develop would not be able to do that. And link generation would require sending notification, which looks like an awkward way to control an algorithm. I think it would be easier if user could just change parameter of the live instance.

AlexCatarino commented 2 weeks ago

Hi @yul, You can write a 30-line Python script to trigger command events that would be as easy as using parameters in the IDE, see Send Commands by API.

print(create_command(<project_id>, {'ema_fast': 10, 'sma_slow': 50}))
print(create_command(<project_id>, {'ema_fast': 5, 'sma_slow': 100}))