/src/main/java/net/finmath/montecarlo/assetderivativevaluation/products/LocalRiskMinimizingHedgePortfolio.java
final RandomVariable condExpectationValuationExpected = underlyingRabasedMartingaleSquared.getConditionalExpectation( underlyingRabasedMartingaleSquared) ;
final RandomVariable underlyingRabasedMartingaleSquaredExpected = condExpectationValuation.getConditionalExpectation ( underlyingRabasedMartingaleSquared ) ;
final RandomVariable derivativeRebased = productAtTimeNext.div(numeraireAtTimeNext); final RandomVariable derivativeRebasedExpected = condExpectationHedging.getConditionalExpectation(derivativeRebased); final RandomVariable derivativeRebasedMartingale = derivativeRebased.sub(derivativeRebasedExpected); final RandomVariable derivativeTimesUnderlying = derivativeRebasedMartingale.mult(underlyingRebasedMartingale); final RandomVariable derivativeTimesUnderlyingExpected = condExpectationValuation.getConditionalExpectation(derivativeTimesUnderlying); final RandomVariable underlyingRabasedMartingaleSquared = underlyingRebasedMartingale.squared(); <extra_id_0> final RandomVariable delta = derivativeTimesUnderlyingExpected.div(underlyingRabasedMartingaleSquaredExpected); final RandomVariable underlyingValue = model.getAssetValue(time,0); final RandomVariable numeraireValue = model.getNumeraire(time); final RandomVariable newNumberOfStocks = delta; final RandomVariable stocksToBuy = newNumberOfStocks.sub(amountOfUderlyingAsset); final RandomVariable numeraireAssetsToBuy = stocksToBuy.mult(underlyingValue).div(numeraireValue).mult(-1);