/// <summary> /// Creates a new universe and adds it to the algorithm /// </summary> /// <param name="dataType">The data type</param> /// <param name="securityType">The security type the universe produces</param> /// <param name="name">A unique name for this universe</param> /// <param name="resolution">The epected resolution of the universe data</param> /// <param name="market">The market for selected symbols</param> /// <param name="universeSettings">The subscription settings to use for newly created subscriptions</param> /// <param name="pySelector">Function delegate that performs selection on the universe data</param> public void AddUniverse(Type dataType, SecurityType securityType, string name, Resolution resolution, string market, UniverseSettings universeSettings, PyObject pySelector) { var marketHoursDbEntry = _marketHoursDatabase.GetEntry(market, name, securityType); var dataTimeZone = marketHoursDbEntry.DataTimeZone; var exchangeTimeZone = marketHoursDbEntry.ExchangeHours.TimeZone; var symbol = QuantConnect.Symbol.Create(name, securityType, market); var config = new SubscriptionDataConfig(dataType, symbol, resolution, dataTimeZone, exchangeTimeZone, false, false, true, true, isFilteredSubscription: false); var selector = PythonUtil.ToFunc <IEnumerable <IBaseData>, object[]>(pySelector); AddUniverse(new FuncUniverse(config, universeSettings, SecurityInitializer, d => selector(d) .Select(x => x is Symbol ? (Symbol)x : QuantConnect.Symbol.Create((string)x, securityType, market)))); }
/// <summary> /// Sets the specified function as the benchmark, this function provides the value of /// the benchmark at each date/time requested /// </summary> /// <param name="benchmark">The benchmark producing function</param> public void SetBenchmark(PyObject benchmark) { using (Py.GIL()) { var pyBenchmark = PythonUtil.ToFunc <DateTime, decimal>(benchmark); if (pyBenchmark != null) { SetBenchmark(pyBenchmark); return; } SetBenchmark((Symbol)benchmark.AsManagedObject(typeof(Symbol))); } }
/// <summary> /// Creates a new universe and adds it to the algorithm. This is for coarse fundamental US Equity data and /// will be executed on day changes in the NewYork time zone (<see cref="TimeZones.NewYork"/> /// </summary> /// <param name="pycoarse">Defines an initial coarse selection</param> public void AddUniverse(PyObject pycoarse) { var coarse = PythonUtil.ToFunc <IEnumerable <CoarseFundamental>, object[]>(pycoarse); if (coarse != null) { AddUniverse(c => coarse(c).Select(x => (Symbol)x)); return; } var type = (Type)pycoarse.GetPythonType().AsManagedObject(typeof(Type)); AddUniverse((dynamic)pycoarse.AsManagedObject(type)); }
/// <summary> /// Sets the <see cref="ContractFilter"/> to a new universe selection function /// </summary> /// <param name="universeFunc">new universe selection function</param> public void SetFilter(PyObject universeFunc) { var pyUniverseFunc = PythonUtil.ToFunc <FutureFilterUniverse, FutureFilterUniverse>(universeFunc); SetFilter(pyUniverseFunc); }
/// <summary> /// Creates a new user defined universe that will fire on the requested resolution during market hours. /// </summary> /// <param name="securityType">The security type of the universe</param> /// <param name="name">A unique name for this universe</param> /// <param name="resolution">The resolution this universe should be triggered on</param> /// <param name="market">The market of the universe</param> /// <param name="universeSettings">The subscription settings used for securities added from this universe</param> /// <param name="pySelector">Function delegate that accepts a DateTime and returns a collection of string symbols</param> public void AddUniverse(SecurityType securityType, string name, Resolution resolution, string market, UniverseSettings universeSettings, PyObject pySelector) { var selector = PythonUtil.ToFunc <DateTime, object[]>(pySelector); AddUniverse(securityType, name, resolution, market, universeSettings, d => selector(d).Select(x => (string)x)); }
/// <summary> /// Creates a new universe and adds it to the algorithm. This can be used to return a list of string /// symbols retrieved from anywhere and will loads those symbols under the US Equity market. /// </summary> /// <param name="name">A unique name for this universe</param> /// <param name="pySelector">Function delegate that accepts a DateTime and returns a collection of string symbols</param> public void AddUniverse(string name, PyObject pySelector) { var selector = PythonUtil.ToFunc <DateTime, object[]>(pySelector); AddUniverse(name, d => selector(d).Select(x => (string)x)); }
/// <summary> /// Sets the <see cref="ContractFilter"/> to a new universe selection function /// </summary> /// <param name="universeFunc">new universe selection function</param> public void SetFilter(PyObject universeFunc) { var pyUniverseFunc = PythonUtil.ToFunc <OptionFilterUniverse, OptionFilterUniverse>(universeFunc); SetFilter(pyUniverseFunc); }
/// <summary> /// Creates a new universe and adds it to the algorithm. This is for coarse fundamental US Equity data and /// will be executed on day changes in the NewYork time zone (<see cref="TimeZones.NewYork"/> /// </summary> /// <param name="pycoarse">Defines an initial coarse selection</param> public void AddUniverse(PyObject pycoarse) { var coarse = PythonUtil.ToFunc <IEnumerable <CoarseFundamental>, object[]>(pycoarse); AddUniverse(c => coarse(c).Select(x => (Symbol)x)); }