Lean  $LEAN_TAG$
FuturesChain.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;
19 
21 {
22  /// <summary>
23  /// Represents an entire chain of futures contracts for a single underlying
24  /// This type is <see cref="IEnumerable{FuturesContract}"/>
25  /// </summary>
26  public class FuturesChain : BaseChain<FuturesContract, FuturesContracts>
27  {
28  /// <summary>
29  /// Initializes a new instance of the <see cref="FuturesChain"/> class
30  /// </summary>
31  /// <param name="canonicalFutureSymbol">The symbol for this chain.</param>
32  /// <param name="time">The time of this chain</param>
33  /// <param name="flatten">Whether to flatten the data frame</param>
34  public FuturesChain(Symbol canonicalFutureSymbol, DateTime time, bool flatten = true)
35  : base(canonicalFutureSymbol, time, MarketDataType.FuturesChain, flatten)
36  {
37  }
38 
39  /// <summary>
40  /// Initializes a new instance of the <see cref="FuturesChain"/> class
41  /// </summary>
42  /// <param name="canonicalFutureSymbol">The symbol for this chain.</param>
43  /// <param name="time">The time of this chain</param>
44  /// <param name="contracts">The list of contracts that form this chain</param>
45  /// <param name="flatten">Whether to flatten the data frame</param>
46  public FuturesChain(Symbol canonicalFutureSymbol, DateTime time, IEnumerable<FutureUniverse> contracts, bool flatten = true)
47  : this(canonicalFutureSymbol, time, flatten)
48  {
49  foreach (var contractData in contracts)
50  {
51  if (contractData.Symbol.ID.Date.Date < time.Date) continue;
52  Contracts[contractData.Symbol] = new FuturesContract(contractData);
53  }
54  }
55 
56  /// <summary>
57  /// Initializes a new instance of the <see cref="FuturesChain"/> class as a clone of the specified instance
58  /// </summary>
59  private FuturesChain(FuturesChain other)
60  : base(other)
61  {
62  }
63 
64  /// <summary>
65  /// Return a new instance clone of this object, used in fill forward
66  /// </summary>
67  /// <returns>A clone of the current object</returns>
68  public override BaseData Clone()
69  {
70  return new FuturesChain(this);
71  }
72  }
73 }