/*
* 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.Linq;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace QuantConnect.Data.Auxiliary
{
///
/// Collection of factors for continuous contracts and their back months contracts for a specific mapping mode and date
///
public class MappingContractFactorRow : IFactorRow
{
///
/// Gets the date associated with this data
///
public DateTime Date { get; set; }
///
/// Backwards ratio price scaling factors for the front month [index 0] and it's 'i' back months [index 0 + i]
///
///
public IReadOnlyList BackwardsRatioScale { get; set; } = new List();
///
/// Backwards Panama Canal price scaling factors for the front month [index 0] and it's 'i' back months [index 0 + i]
///
///
public IReadOnlyList BackwardsPanamaCanalScale { get; set; } = new List();
///
/// Forward Panama Canal price scaling factors for the front month [index 0] and it's 'i' back months [index 0 + i]
///
///
public IReadOnlyList ForwardPanamaCanalScale { get; set; } = new List();
///
/// Allows the consumer to specify a desired mapping mode
///
public DataMappingMode? DataMappingMode { get; set; }
///
/// Empty constructor for json converter
///
public MappingContractFactorRow()
{
}
///
/// Writes factor file row into it's file format
///
/// Json formatted
public string GetFileFormat(string source = null)
{
return JsonConvert.SerializeObject(this);
}
///
/// Parses the lines as factor files rows while properly handling inf entries
///
/// The lines from the factor file to be parsed
/// The minimum date from the factor file
/// An enumerable of factor file rows
public static List Parse(IEnumerable lines, out DateTime? factorFileMinimumDate)
{
factorFileMinimumDate = null;
var rows = new List();
// parse factor file lines
foreach (var line in lines)
{
var row = JsonConvert.DeserializeObject(line);
if(!row.DataMappingMode.HasValue || Enum.IsDefined(typeof(DataMappingMode), row.DataMappingMode.Value))
{
rows.Add(row);
}
}
if (rows.Count > 0)
{
factorFileMinimumDate = rows.Min(ffr => ffr.Date).AddDays(-1);
}
return rows;
}
}
}