/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Text;
using System.Linq;
using Python.Runtime;
using QuantConnect.Util;
using System.Collections;
using System.Collections.Generic;
namespace QuantConnect.Data
{
///
/// Historical data abstraction
///
/// The data this collection can enumerate
public class DataHistory : IEnumerable
{
private readonly Lazy _count;
private readonly Lazy _dataframe;
///
/// The data we hold
///
protected IEnumerable Data { get; }
///
/// The current data point count
///
public int Count => _count.Value;
///
/// This data pandas data frame
///
public PyObject DataFrame => _dataframe.Value;
///
/// Creates a new instance
///
public DataHistory(IEnumerable data, Lazy dataframe)
{
Data = data.Memoize();
_dataframe = dataframe;
// let's be lazy
_count = new(() => Data.Count());
}
///
/// Default to string implementation
///
public override string ToString()
{
var builder = new StringBuilder();
foreach (var dataPoint in Data)
{
builder.AppendLine(dataPoint.ToString());
}
return builder.ToString();
}
///
/// Returns an enumerator for the data
///
public IEnumerator GetEnumerator()
{
return Data.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}