Search code examples
javaarraysstatisticsmontecarlo

Use Monte Carlo method to find ideal quantum for minimum price


I have to calculate ideal quantum with Monte Carlo method for minimum price. If the number I calculate is greater than number I compare with(which is stock and when i iterate the cycle increase stock by 10) each number which is greater I multiply the difference by 50 and when is the number lesser then the stock I have to multiply each difference by 150. I am now in the state that I have array with 500 numbers and I don't know how to find the ideal quantum in the array if is that even possible.

EDIT>>My task is to find ideal quantum which means. If you have stock how much you have to buy. If you buy more than is the demand your goods in your stock lose quality and you have to pay for each good 50 euro. But if you buy less than demand you have to pay for each good 150. So you comply the demand.


Solution

  • Use a proper List implementation and also objects: make a class called Stock with the various operations to increase and decrease. You can then use the Java 8 stream API on the list to filter by your condition and then call the right method on the objects that pass the filter condition

    stocks.stream()             //convert list to stream
    .filter(stock -> ideal>stock.getValue())    //filters the line
    .map(Stock::multiplyBy150);         //call appropriate method on objects that pass the filter