Feature 5988 WarmUpIndicator() method for indicators written in Python (#6027)
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
* Implement IIndicatorWarmUpPeriodProvider - Implement IIndicatorWarmUpPeriodProvider in PythonIndicator.cs - Make a unit test to check whether the WarmUpPeriod is working as expected - Make a regression test to check the new feature at a system level * Nit change * Change Period parameter for WarmUpPeriod parameter - Change regression test to check if the new parameter keep backwards compatibility with indicators that do not set WarmUpPeriod * Documentation change * Fix tests bugs - In CommonIndicatorTests.cs before finish the test it checks the period.value with the number of samples but for default the period.value was set to -1 * Change names * Change WarmUp and RegisterIndicator methods - Lean WarmUp indicator skip custom python indicators that don't define WarmUpPeriod parameter * Call WarmUpIndicator manually - Add a new "bridge" method called WarmUpIndicator in QCAlgorithm.Python.cs to set up everything to call WarmUpIndicator in QCAlgorithm.Indicators.cs - Change the regression algorithm to warm up the indicators manually * Remove unnecessary code and add more tests * Nit change * Revert "Nit change" This reverts commit da411f59c9e4295d75a11c6c581f615a938dd2c6. * Fix bugs * Try fix bugs * Add C# regression test - More nit changes - Fix bugs * Requested changes * Remove unnecessary code * Requested changes * Nit changes - Add new Python class to check a custom indicator, which doesn't inherits from PythonIndicator, warms up properly * Reduce redundant code * Fix bug and add more unit and regression tests * - Add more unit tests * Nit change * Test cleanup Co-authored-by: Martin-Molinero <martin@quantconnect.com>
This commit is contained in:
committed by
GitHub
parent
013b9ea850
commit
fc6ddc2120
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -281,6 +281,7 @@ namespace QuantConnect.Algorithm
|
||||
Func<IEnumerable<CoarseFundamental>, object> coarseFunc;
|
||||
Universe universe;
|
||||
|
||||
// TODO: to be removed when https://github.com/QuantConnect/pythonnet/issues/62 is solved
|
||||
if (pyObject.TryConvert(out universe))
|
||||
{
|
||||
return AddUniverse(universe);
|
||||
@@ -595,6 +596,7 @@ namespace QuantConnect.Algorithm
|
||||
/// <param name="selector">Selects a value from the BaseData send into the indicator, if null defaults to a cast (x => (T)x)</param>
|
||||
public void RegisterIndicator(Symbol symbol, PyObject indicator, IDataConsolidator consolidator, PyObject selector = null)
|
||||
{
|
||||
// TODO: to be removed when https://github.com/QuantConnect/pythonnet/issues/62 is solved
|
||||
IndicatorBase<IndicatorDataPoint> indicatorDataPoint;
|
||||
IndicatorBase<IBaseDataBar> indicatorDataBar;
|
||||
IndicatorBase<TradeBar> indicatorTradeBar;
|
||||
@@ -618,6 +620,39 @@ namespace QuantConnect.Algorithm
|
||||
RegisterIndicator(symbol, WrapPythonIndicator(indicator), consolidator, selector?.ConvertToDelegate<Func<IBaseData, IBaseData>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warms up a given indicator with historical data
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol whose indicator we want</param>
|
||||
/// <param name="indicator">The indicator we want to warm up</param>
|
||||
/// <param name="resolution">The resolution</param>
|
||||
/// <param name="selector">Selects a value from the BaseData send into the indicator, if null defaults to a cast (x => (T)x)</param>
|
||||
public void WarmUpIndicator(Symbol symbol, PyObject indicator, Resolution? resolution = null, PyObject selector = null)
|
||||
{
|
||||
// TODO: to be removed when https://github.com/QuantConnect/pythonnet/issues/62 is solved
|
||||
IndicatorBase<IndicatorDataPoint> indicatorDataPoint;
|
||||
IndicatorBase<IBaseDataBar> indicatorDataBar;
|
||||
IndicatorBase<TradeBar> indicatorTradeBar;
|
||||
|
||||
if (indicator.TryConvert(out indicatorDataPoint))
|
||||
{
|
||||
WarmUpIndicator(symbol, indicatorDataPoint, resolution, selector?.ConvertToDelegate<Func<IBaseData, decimal>>());
|
||||
return;
|
||||
}
|
||||
else if (indicator.TryConvert(out indicatorDataBar))
|
||||
{
|
||||
WarmUpIndicator(symbol, indicatorDataBar, resolution, selector?.ConvertToDelegate<Func<IBaseData, IBaseDataBar>>());
|
||||
return;
|
||||
}
|
||||
else if (indicator.TryConvert(out indicatorTradeBar))
|
||||
{
|
||||
WarmUpIndicator(symbol, indicatorTradeBar, resolution, selector?.ConvertToDelegate<Func<IBaseData, TradeBar>>());
|
||||
return;
|
||||
}
|
||||
|
||||
WarmUpIndicator(symbol, WrapPythonIndicator(indicator), resolution, selector?.ConvertToDelegate<Func<IBaseData, IBaseData>>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plot a chart using string series name, with value.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user