/* * 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 Newtonsoft.Json; using ProtoBuf; using static QuantConnect.StringExtensions; namespace QuantConnect.Data.Market { /// /// Split event from a security /// [ProtoContract(SkipConstructor = true)] public class Split : BaseData { /// ///Gets the type of split event, warning or split. /// [JsonProperty] [ProtoMember(10)] public SplitType Type { get; private set; } /// /// Gets the split factor /// [JsonProperty] [ProtoMember(11)] public decimal SplitFactor { get; set; } /// /// Gets the price at which the split occurred /// This is typically the previous day's closing price /// [ProtoMember(12)] public decimal ReferencePrice { get { return Value; } set { Value = value; } } /// /// Initializes a new instance of the Split class /// public Split() { Type = SplitType.SplitOccurred; DataType = MarketDataType.Auxiliary; } /// /// Initializes a new instance of the Split class /// /// The symbol /// The date /// The price at the time of the split /// The split factor to be applied to current holdings /// The type of split event, warning or split occurred public Split(Symbol symbol, DateTime date, decimal price, decimal splitFactor, SplitType type) : this() { Type = type; Time = date; Symbol = symbol; ReferencePrice = price; SplitFactor = splitFactor; } /// /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object /// each time it is called. /// /// Subscription data config setup object /// Line of the source document /// Date of the requested data /// true if we're in live mode, false for backtesting mode /// Instance of the T:BaseData object generated by this line of the CSV public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { // this is implemented in the SubscriptionDataReader.CheckForSplit throw new NotImplementedException("This method is not supposed to be called on the Split type."); } /// /// Return the URL string source of the file. This will be converted to a stream /// /// Configuration object /// Date of this source file /// true if we're in live mode, false for backtesting mode /// String URL of source file. public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { // this data is derived from map files and factor files in backtesting return null; } /// /// Formats a string with the symbol and value. /// /// string - a string formatted as SPY: 167.753 public override string ToString() { var type = Type == SplitType.Warning ? "Split Warning" : "Split"; return Invariant($"{type}: {Symbol}: {SplitFactor} | {ReferencePrice}"); } /// /// Return a new instance clone of this object, used in fill forward /// /// /// This base implementation uses reflection to copy all public fields and properties /// /// A clone of the current object public override BaseData Clone() { return new Split(Symbol, Time, Price, SplitFactor, Type); } } }