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  /// <summary>
36  /// Returns a string message saying the portfolio target percent is invalid
37  /// </summary>
38  [MethodImpl(MethodImplOptions.AggressiveInlining)]
39  public static string InvalidTargetPercent(IAlgorithm algorithm, decimal percent)
40  {
41  return Invariant($@"The portfolio target percent: {
42  percent}, does not comply with the current 'Algorithm.Settings' 'MaxAbsolutePortfolioTargetPercentage': {
43  algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or 'MinAbsolutePortfolioTargetPercentage': {
44  algorithm.Settings.MinAbsolutePortfolioTargetPercentage}. Skipping");
45  }
46 
47  /// <summary>
48  /// Returns a string message saying the given symbol was not found in the portfolio
49  /// </summary>
50  [MethodImpl(MethodImplOptions.AggressiveInlining)]
51  public static string SymbolNotFound(QuantConnect.Symbol symbol)
52  {
53  return Invariant($"{symbol} not found in portfolio. Request this data when initializing the algorithm.");
54  }
55 
56  /// <summary>
57  /// Returns a string message saying it was impossible to compute the order quantity of the given symbol. It also
58  /// explains the reason why it was impossible
59  /// </summary>
60  [MethodImpl(MethodImplOptions.AggressiveInlining)]
62  {
63  return Invariant($"Unable to compute order quantity of {symbol}. Reason: {result.Reason} Returning null.");
64  }
65 
66  /// <summary>
67  /// Parses the given portfolio target into a string message containing basic information about it
68  /// </summary>
69  [MethodImpl(MethodImplOptions.AggressiveInlining)]
70  public static string ToString(Algorithm.Framework.Portfolio.PortfolioTarget portfolioTarget)
71  {
72  var str = Invariant($"{portfolioTarget.Symbol}: {portfolioTarget.Quantity.Normalize()}");
73  if (!string.IsNullOrEmpty(portfolioTarget.Tag))
74  {
75  str += $" ({portfolioTarget.Tag})";
76  }
77 
78  return str;
79  }
80  }
81  }
82 }