function x = krgSingleStockOptimizer(strategy,k,tradeData,Lambda)
%KRGSINGLESTOCKOPTIMIZER Single stock optimization objective function.

%   Copyright 2016-2020 The MathWorks, Inc.

% Determine which strategy is being used
[~,povFlag,timeFlag,tsvpFlag] = krg.krgDataFlags(tradeData);
if povFlag
  tradeData.POV = strategy;
elseif timeFlag
  tradeData.TradeTime = strategy;
elseif tsvpFlag
  tradeData.TradeSchedule = strategy;
end

% Calculate costs, x is the total cost
mi = marketImpact(k,tradeData);
tr = timingRisk(k,tradeData);
pa = priceAppreciation(k,tradeData);
x = (mi + pa) + Lambda .* tr;
