Skip to content

Commit 35ead80

Browse files
committed
Addressed PR comments
1 parent 4faea7b commit 35ead80

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Common/Algorithm/Framework/Portfolio/SignalExports/Collective2SignalExport.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public class Collective2SignalExport : BaseSignalExport
5151
/// </summary>
5252
private IAlgorithm _algorithm;
5353

54+
/// <summary>
55+
/// Flag to track if the warning has already been printed.
56+
/// </summary>
57+
private bool _isWarningPrinted;
58+
5459
/// <summary>
5560
/// The name of this signal export
5661
/// </summary>
@@ -209,14 +214,18 @@ private bool ConvertTypeOfSymbol(Symbol targetSymbol, out string typeOfSymbol)
209214
/// <returns>Number of shares hold of the given position</returns>
210215
protected int ConvertPercentageToQuantity(IAlgorithm algorithm, PortfolioTarget target)
211216
{
212-
if (algorithm.Securities[target.Symbol].Price == 0 && target.Quantity == 0)
213-
{
214-
algorithm.Debug($"Warning: The price for {target.Symbol} is 0, and the target quantity is 0. Returning 0 as the calculated quantity.");
215-
return 0;
216-
}
217217
var numberShares = PortfolioTarget.Percent(algorithm, target.Symbol, target.Quantity);
218218
if (numberShares == null)
219219
{
220+
if (algorithm.Securities[target.Symbol].Price == 0 && target.Quantity == 0)
221+
{
222+
if (!_isWarningPrinted)
223+
{
224+
_isWarningPrinted = true;
225+
algorithm.Debug($"Warning: The price for {target.Symbol} is 0, and the target quantity is 0. Will return 0 all similar cases.");
226+
}
227+
return 0;
228+
}
220229
throw new InvalidOperationException($"Collective2 failed to calculate target quantity for {target}");
221230
}
222231

0 commit comments

Comments
 (0)