Lean  $LEAN_TAG$
UniverseSettings.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;
18 using System.Collections.Generic;
19 
21 {
22  /// <summary>
23  /// Defines settings required when adding a subscription
24  /// </summary>
25  public class UniverseSettings
26  {
27  /// <summary>
28  /// The resolution to be used
29  /// </summary>
30  public Resolution Resolution { get; set; }
31 
32  /// <summary>
33  /// The leverage to be used
34  /// </summary>
35  public decimal Leverage { get; set; }
36 
37  /// <summary>
38  /// True to fill data forward, false otherwise
39  /// </summary>
40  public bool FillForward { get; set; }
41 
42  /// <summary>
43  /// If configured, will be used to determine universe selection schedule and filter or skip selection data
44  /// that does not fit the schedule
45  /// </summary>
46  public Schedule Schedule { get; set; }
47 
48  /// <summary>
49  /// True to allow extended market hours data, false otherwise
50  /// </summary>
51  public bool ExtendedMarketHours { get; set; }
52 
53  /// <summary>
54  /// Defines the minimum amount of time a security must be in
55  /// the universe before being removed.
56  /// </summary>
57  /// <remarks>When selection takes place, the actual members time in the universe
58  /// will be rounded based on this TimeSpan, so that relative small differences do not
59  /// cause an unexpected behavior <see cref="Universe.CanRemoveMember"/></remarks>
60  public TimeSpan MinimumTimeInUniverse { get; set; }
61 
62  /// <summary>
63  /// Defines how universe data is normalized before being send into the algorithm
64  /// </summary>
66 
67  /// <summary>
68  /// Defines how universe data is mapped together
69  /// </summary>
70  /// <remarks>This is particular useful when generating continuous futures</remarks>
71  public DataMappingMode DataMappingMode { get; set; }
72 
73  /// <summary>
74  /// The continuous contract desired offset from the current front month.
75  /// For example, 0 (default) will use the front month, 1 will use the back month contra
76  /// </summary>
77  public int ContractDepthOffset { get; set; }
78 
79  /// <summary>
80  /// Allows a universe to specify which data types to add for a selected symbol
81  /// </summary>
82  public List<Tuple<Type, TickType>> SubscriptionDataTypes { get; set; }
83 
84  /// <summary>
85  /// True if universe selection can run asynchronous
86  /// </summary>
87  public bool? Asynchronous { get; set; }
88 
89  /// <summary>
90  /// Initializes a new instance of the <see cref="UniverseSettings"/> class
91  /// </summary>
92  /// <param name="resolution">The resolution</param>
93  /// <param name="leverage">The leverage to be used</param>
94  /// <param name="fillForward">True to fill data forward, false otherwise</param>
95  /// <param name="extendedMarketHours">True to allow extended market hours data, false otherwise</param>
96  /// <param name="minimumTimeInUniverse">Defines the minimum amount of time a security must remain in the universe before being removed</param>
97  /// <param name="dataNormalizationMode">Defines how universe data is normalized before being send into the algorithm</param>
98  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
99  /// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
100  /// For example, 0 (default) will use the front month, 1 will use the back month contract</param>
101  /// <param name="asynchronous">True if universe selection can run asynchronous</param>
102  /// <param name="selectionDateRule">If provided, will be used to determine universe selection schedule</param>
103  public UniverseSettings(Resolution resolution, decimal leverage, bool fillForward, bool extendedMarketHours, TimeSpan minimumTimeInUniverse, DataNormalizationMode dataNormalizationMode = DataNormalizationMode.Adjusted,
104  DataMappingMode dataMappingMode = DataMappingMode.OpenInterest, int contractDepthOffset = 0, bool? asynchronous = null, IDateRule selectionDateRule = null)
105  {
106  Resolution = resolution;
107  Leverage = leverage;
108  FillForward = fillForward;
109  DataMappingMode = dataMappingMode;
110  ContractDepthOffset = contractDepthOffset;
111  ExtendedMarketHours = extendedMarketHours;
112  MinimumTimeInUniverse = minimumTimeInUniverse;
113  DataNormalizationMode = dataNormalizationMode;
114  Asynchronous = asynchronous;
115  Schedule = new Schedule();
116  if (selectionDateRule != null)
117  {
118  Schedule.On(selectionDateRule);
119  }
120  }
121 
122  /// <summary>
123  /// Initializes a new instance of the <see cref="UniverseSettings"/> class
124  /// </summary>
125  public UniverseSettings(UniverseSettings universeSettings)
126  {
127  Resolution = universeSettings.Resolution;
128  Leverage = universeSettings.Leverage;
129  FillForward = universeSettings.FillForward;
130  DataMappingMode = universeSettings.DataMappingMode;
131  ContractDepthOffset = universeSettings.ContractDepthOffset;
132  ExtendedMarketHours = universeSettings.ExtendedMarketHours;
133  MinimumTimeInUniverse = universeSettings.MinimumTimeInUniverse;
134  DataNormalizationMode = universeSettings.DataNormalizationMode;
135  SubscriptionDataTypes = universeSettings.SubscriptionDataTypes;
136  Asynchronous = universeSettings.Asynchronous;
137  Schedule = universeSettings.Schedule.Clone();
138  }
139  }
140 }