Skip to content

Commit

Permalink
Addressed new PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueNina committed Jan 13, 2025
1 parent 35ead80 commit e21ca0d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Collective2SignalExport : BaseSignalExport
/// <summary>
/// Flag to track if the warning has already been printed.
/// </summary>
private bool _isWarningPrinted;
private bool _isZeroPriceWarningPrinted;

/// <summary>
/// The name of this signal export
Expand Down Expand Up @@ -217,12 +217,12 @@ protected int ConvertPercentageToQuantity(IAlgorithm algorithm, PortfolioTarget
var numberShares = PortfolioTarget.Percent(algorithm, target.Symbol, target.Quantity);
if (numberShares == null)
{
if (algorithm.Securities[target.Symbol].Price == 0 && target.Quantity == 0)
if (algorithm.Securities.TryGetValue(target.Symbol, out var security) && security.Price == 0 && target.Quantity == 0)
{
if (!_isWarningPrinted)
if (!_isZeroPriceWarningPrinted)
{
_isWarningPrinted = true;
algorithm.Debug($"Warning: The price for {target.Symbol} is 0, and the target quantity is 0. Will return 0 all similar cases.");
_isZeroPriceWarningPrinted = true;
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.");
}
return 0;
}
Expand Down

0 comments on commit e21ca0d

Please sign in to comment.