/* * 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.Runtime.CompilerServices; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Interfaces; using QuantConnect.Securities.Positions; using static QuantConnect.StringExtensions; namespace QuantConnect { /// /// Provides user-facing message construction methods and static messages for the namespace /// public static partial class Messages { /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class PortfolioTarget { /// /// Returns a string message saying the portfolio target percent is invalid /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string InvalidTargetPercent(IAlgorithm algorithm, decimal percent) { return Invariant($@"The portfolio target percent: { percent}, does not comply with the current 'Algorithm.Settings' 'MaxAbsolutePortfolioTargetPercentage': { algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or 'MinAbsolutePortfolioTargetPercentage': { algorithm.Settings.MinAbsolutePortfolioTargetPercentage}. Skipping"); } /// /// Returns a string message saying the given symbol was not found in the portfolio /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string SymbolNotFound(QuantConnect.Symbol symbol) { return Invariant($"{symbol} not found in portfolio. Request this data when initializing the algorithm."); } /// /// Returns a string message saying it was impossible to compute the order quantity of the given symbol. It also /// explains the reason why it was impossible /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string UnableToComputeOrderQuantityDueToNullResult(QuantConnect.Symbol symbol, GetMaximumLotsResult result) { return Invariant($"Unable to compute order quantity of {symbol}. Reason: {result.Reason} Returning null."); } /// /// Parses the given portfolio target into a string message containing basic information about it /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToString(Algorithm.Framework.Portfolio.PortfolioTarget portfolioTarget) { var str = Invariant($"{portfolioTarget.Symbol}: {portfolioTarget.Quantity.Normalize()}"); if (!string.IsNullOrEmpty(portfolioTarget.Tag)) { str += $" ({portfolioTarget.Tag})"; } return str; } /// /// Returns a string message saying the insight direction is invalid for the given symbol /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string InvalidInsightDirection(QuantConnect.Symbol symbol, InsightDirection insightDirection) { return Invariant($"Invalid insight direction {insightDirection} for symbol: {symbol}."); } } } }