/* * 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.Collections.Generic; namespace QuantConnect.Securities.Option.StrategyMatcher { /// /// Provides an implementation of that represents a constant value. /// public class ConstantOptionStrategyLegPredicateReferenceValue : IOptionStrategyLegPredicateReferenceValue { private readonly T _value; /// /// Gets the target of this value /// public PredicateTargetValue Target { get; } /// /// Initializes a new instance of the class /// /// The constant reference value /// The value target in relation to the public ConstantOptionStrategyLegPredicateReferenceValue(T value, PredicateTargetValue target) { _value = value; Target = target; } /// /// Returns the constant value provided at initialization /// public object Resolve(IReadOnlyList legs) { return _value; } } /// /// Provides methods for easily creating instances of /// public static class ConstantOptionStrategyLegReferenceValue { /// /// Creates a new instance of the class for /// the specified /// public static IOptionStrategyLegPredicateReferenceValue Create(object value) { if (value is DateTime) { return new ConstantOptionStrategyLegPredicateReferenceValue((DateTime) value, PredicateTargetValue.Expiration); } if (value is decimal) { return new ConstantOptionStrategyLegPredicateReferenceValue((decimal) value, PredicateTargetValue.Strike); } if (value is OptionRight) { return new ConstantOptionStrategyLegPredicateReferenceValue((OptionRight) value, PredicateTargetValue.Right); } throw new NotSupportedException($"{value?.GetType().GetBetterTypeName()} is not supported."); } } }