Lean  $LEAN_TAG$
QCAlgorithm.Framework.Python.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 Python.Runtime;
22 
23 namespace QuantConnect.Algorithm
24 {
25  public partial class QCAlgorithm
26  {
27  /// <summary>
28  /// Sets the alpha model
29  /// </summary>
30  /// <param name="alpha">Model that generates alpha</param>
31  [DocumentationAttribute(AlgorithmFramework)]
32  public void SetAlpha(PyObject alpha)
33  {
34  IAlphaModel model;
35  if (alpha.TryConvert(out model))
36  {
37  SetAlpha(model);
38  }
39  else
40  {
41  Alpha = new AlphaModelPythonWrapper(alpha);
42  }
43  }
44 
45  /// <summary>
46  /// Adds a new alpha model
47  /// </summary>
48  /// <param name="alpha">Model that generates alpha to add</param>
49  [DocumentationAttribute(AlgorithmFramework)]
50  public void AddAlpha(PyObject alpha)
51  {
52  IAlphaModel model;
53  if (alpha.TryConvert(out model))
54  {
55  AddAlpha(model);
56  }
57  else
58  {
60  }
61  }
62 
63  /// <summary>
64  /// Sets the execution model
65  /// </summary>
66  /// <param name="execution">Model defining how to execute trades to reach a portfolio target</param>
67  [DocumentationAttribute(AlgorithmFramework)]
68  [DocumentationAttribute(TradingAndOrders)]
69  public void SetExecution(PyObject execution)
70  {
71  IExecutionModel model;
72  if (execution.TryConvert(out model))
73  {
74  SetExecution(model);
75  }
76  else
77  {
78  Execution = new ExecutionModelPythonWrapper(execution);
79  }
80  }
81 
82  /// <summary>
83  /// Sets the portfolio construction model
84  /// </summary>
85  /// <param name="portfolioConstruction">Model defining how to build a portfolio from alphas</param>
86  [DocumentationAttribute(AlgorithmFramework)]
87  [DocumentationAttribute(TradingAndOrders)]
88  public void SetPortfolioConstruction(PyObject portfolioConstruction)
89  {
91  if (portfolioConstruction.TryConvert(out model))
92  {
94  }
95  else
96  {
98  }
99  }
100 
101  /// <summary>
102  /// Sets the universe selection model
103  /// </summary>
104  /// <param name="universeSelection">Model defining universes for the algorithm</param>
105  [DocumentationAttribute(AlgorithmFramework)]
106  [DocumentationAttribute(Universes)]
107  public void SetUniverseSelection(PyObject universeSelection)
108  {
110  if (!universeSelection.TryConvert(out model))
111  {
112  model = new UniverseSelectionModelPythonWrapper(universeSelection);
113  }
114  SetUniverseSelection(model);
115  }
116 
117  /// <summary>
118  /// Adds a new universe selection model
119  /// </summary>
120  /// <param name="universeSelection">Model defining universes for the algorithm to add</param>
121  [DocumentationAttribute(AlgorithmFramework)]
122  [DocumentationAttribute(Universes)]
123  public void AddUniverseSelection(PyObject universeSelection)
124  {
126  if (!universeSelection.TryConvert(out model))
127  {
128  model = new UniverseSelectionModelPythonWrapper(universeSelection);
129  }
130  AddUniverseSelection(model);
131  }
132 
133  /// <summary>
134  /// Sets the risk management model
135  /// </summary>
136  /// <param name="riskManagement">Model defining how risk is managed</param>
137  [DocumentationAttribute(AlgorithmFramework)]
138  [DocumentationAttribute(TradingAndOrders)]
139  public void SetRiskManagement(PyObject riskManagement)
140  {
141  IRiskManagementModel model;
142  if (riskManagement.TryConvert(out model))
143  {
144  SetRiskManagement(model);
145  }
146  else
147  {
148  RiskManagement = new RiskManagementModelPythonWrapper(riskManagement);
149  }
150  }
151 
152  /// <summary>
153  /// Adds a new risk management model
154  /// </summary>
155  /// <param name="riskManagement">Model defining how risk is managed to add</param>
156  [DocumentationAttribute(AlgorithmFramework)]
157  [DocumentationAttribute(TradingAndOrders)]
158  public void AddRiskManagement(PyObject riskManagement)
159  {
160  IRiskManagementModel model;
161  if (!riskManagement.TryConvert(out model))
162  {
163  model = new RiskManagementModelPythonWrapper(riskManagement);
164  }
165  AddRiskManagement(model);
166  }
167  }
168 }