Lean  $LEAN_TAG$
FutureHistory.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.Linq;
18 using Python.Runtime;
19 using QuantConnect.Data;
20 using QuantConnect.Python;
21 using System.Collections.Generic;
22 
24 {
25  /// <summary>
26  /// Class to manage information from History Request of Futures
27  /// </summary>
28  public class FutureHistory : DataHistory<Slice>
29  {
30  /// <summary>
31  /// Create a new instance of <see cref="FutureHistory"/>.
32  /// </summary>
33  /// <param name="data"></param>
34  public FutureHistory(IEnumerable<Slice> data)
35  : base(data, new Lazy<PyObject>(() => new PandasConverter().GetDataFrame(data), isThreadSafe: false))
36  {
37  }
38 
39  /// <summary>
40  /// Gets all data from the History Request that are written in a pandas.DataFrame
41  /// </summary>
42  [Obsolete("Please use the 'DataFrame' property")]
43  public PyObject GetAllData() => DataFrame;
44 
45  /// <summary>
46  /// Gets all expity dates in the future history
47  /// </summary>
48  /// <returns></returns>
49  public PyObject GetExpiryDates()
50  {
51  var expiry = Data.SelectMany(x => x.FuturesChains.SelectMany(y => y.Value.Contracts.Keys.Select(z => z.ID.Date).Distinct()));
52  using (Py.GIL())
53  {
54  return expiry.Distinct().ToList().ToPython();
55  }
56  }
57  }
58 }