Skip to content

Commit e21ca0d

Browse files
committed
Addressed new PR comments
1 parent 35ead80 commit e21ca0d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class Collective2SignalExport : BaseSignalExport
5454
/// <summary>
5555
/// Flag to track if the warning has already been printed.
5656
/// </summary>
57-
private bool _isWarningPrinted;
57+
private bool _isZeroPriceWarningPrinted;
5858

5959
/// <summary>
6060
/// The name of this signal export
@@ -217,12 +217,12 @@ protected int ConvertPercentageToQuantity(IAlgorithm algorithm, PortfolioTarget
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)
220+
if (algorithm.Securities.TryGetValue(target.Symbol, out var security) && security.Price == 0 && target.Quantity == 0)
221221
{
222-
if (!_isWarningPrinted)
222+
if (!_isZeroPriceWarningPrinted)
223223
{
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.");
224+
_isZeroPriceWarningPrinted = true;
225+
algorithm.Debug($"Warning: Collective2 failed to calculate target quantity for {target}. The price for {target.Symbol} is 0, and the target quantity is 0. Will return 0 for all similar cases.");
226226
}
227227
return 0;
228228
}

0 commit comments

Comments
 (0)