Lean  $LEAN_TAG$
CoarseFundamentalUniverseSelectionModel.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using System.Collections.Generic;
18 using Python.Runtime;
21 
23 {
24  /// <summary>
25  /// Portfolio selection model that uses coarse selectors. For US equities only.
26  /// </summary>
28  {
29  private readonly Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>> _coarseSelector;
30  /// <summary>
31  /// Initializes a new instance of the <see cref="CoarseFundamentalUniverseSelectionModel"/> class
32  /// </summary>
33  /// <param name="coarseSelector">Selects symbols from the provided coarse data set</param>
34  /// <param name="universeSettings">Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed</param>
36  Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>> coarseSelector,
37  UniverseSettings universeSettings = null
38  )
39  : base(false, universeSettings)
40  {
41  _coarseSelector = coarseSelector;
42  }
43 
44  /// <summary>
45  /// Initializes a new instance of the <see cref="CoarseFundamentalUniverseSelectionModel"/> class
46  /// </summary>
47  /// <param name="coarseSelector">Selects symbols from the provided coarse data set</param>
48  /// <param name="universeSettings">Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed</param>
50  PyObject coarseSelector,
51  UniverseSettings universeSettings = null
52  )
53  : base(false, universeSettings)
54  {
55  Func<IEnumerable<CoarseFundamental>, object> func;
56  if (coarseSelector.TryConvertToDelegate(out func))
57  {
58  _coarseSelector = func.ConvertToUniverseSelectionSymbolDelegate();
59  }
60  }
61 
62  /// <inheritdoc />
63  public override IEnumerable<Symbol> SelectCoarse(QCAlgorithm algorithm, IEnumerable<CoarseFundamental> coarse)
64  {
65  return _coarseSelector(coarse);
66  }
67  }
68 }