# Trying to find all possible combinations

I am trying to find all the combination of options trades that make the highest profit. Each trade has a maximum profit and maximum loss. I have a list of maximum losses e.g. [5298, 1100, 500]. Each number corresponds to a trade. The combination of maximum losses must be under the money I have in my account, for example, 9000. I'm trying to subtract each number in the maximum loss array from the money in my account and repeatimg it until it gets to 0 or a negative number. It then advances to the next number. This will miss many combinations because it doesn't try the first AND second AND third at the same time. Does anyone know of an algorithm or know how to find and algorithm to find such combinations or have a better idea than mine? This is the pseudocode I have come up with:

for loop through max loss array
find difference between moneyInAccount and max loss[0]
if difference > maxLoss[0] then
difference = difference - maxLoss[0]
or else index to next maxLoss
if maxLoss[1] > difference
then difference - difference - maxLoss[1]
and so on

• Welcome to Computer Science! This looks like a nice problem. Can you raise a specific question for people to answer instead of asking people to do something? (Trivia: one question mark is required.) Can you show a simple non-trivial example? If this problem comes from an online source such as a programming contest or coding camp, can you provide a URL? If it comes from a book or a paper, a reference? All those information motivate and help people answer the question faster and better. Please add those information in the question since people and search engine are not expected to look at comments. Commented Oct 11, 2018 at 21:11
• Can you state your problem more formally? Commented Oct 11, 2018 at 21:58
• I edited it, but I don't know how formal it is. Commented Oct 12, 2018 at 3:02
• Searching for "find all combinations" yields dozens of results. That should show you two things: a) you might have found your answer searching; b) your title is not very helpful. Commented Oct 12, 2018 at 11:43

Each of your options has a maximum loss, and some value to you. (I'm not quite sure what your value function here is -- is it the maximum profit? Or maybe $$(max\,\,profit - max\,\,loss)/2$$?) You have a cap on how much loss you'll assume as risk: your available money. Given that cap, you want to maximize your value.