Lean  $LEAN_TAG$
Messages.Algorithm.Framework.Portfolio.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System.Runtime.CompilerServices;
17 
20 
21 using static QuantConnect.StringExtensions;
22 
23 namespace QuantConnect
24 {
25  /// <summary>
26  /// Provides user-facing message construction methods and static messages for the <see cref="Algorithm.Framework.Portfolio"/> namespace
27  /// </summary>
28  public static partial class Messages
29  {
30  /// <summary>
31  /// Provides user-facing messages for the <see cref="Algorithm.Framework.Portfolio.PortfolioTarget"/> class and its consumers or related classes
32  /// </summary>
33  public static class PortfolioTarget
34  {
35  [MethodImpl(MethodImplOptions.AggressiveInlining)]
36  public static string InvalidTargetPercent(IAlgorithm algorithm, decimal percent)
37  {
38  return Invariant($@"The portfolio target percent: {
39  percent}, does not comply with the current 'Algorithm.Settings' 'MaxAbsolutePortfolioTargetPercentage': {
40  algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or 'MinAbsolutePortfolioTargetPercentage': {
41  algorithm.Settings.MinAbsolutePortfolioTargetPercentage}. Skipping");
42  }
43 
44  [MethodImpl(MethodImplOptions.AggressiveInlining)]
45  public static string SymbolNotFound(QuantConnect.Symbol symbol)
46  {
47  return Invariant($"{symbol} not found in portfolio. Request this data when initializing the algorithm.");
48  }
49 
50  [MethodImpl(MethodImplOptions.AggressiveInlining)]
51  public static string UnableToComputeOrderQuantityDueToNullResult(QuantConnect.Symbol symbol, GetMaximumLotsResult result)
52  {
53  return Invariant($"Unable to compute order quantity of {symbol}. Reason: {result.Reason} Returning null.");
54  }
55 
56  [MethodImpl(MethodImplOptions.AggressiveInlining)]
57  public static string ToString(Algorithm.Framework.Portfolio.PortfolioTarget portfolioTarget)
58  {
59  var str = Invariant($"{portfolioTarget.Symbol}: {portfolioTarget.Quantity.Normalize()}");
60  if (!string.IsNullOrEmpty(portfolioTarget.Tag))
61  {
62  str += $" ({portfolioTarget.Tag})";
63  }
64 
65  return str;
66  }
67  }
68  }
69 }