Optimize stocks for the investment

43 Views Asked by At

I don't know the problem name exactly, but it should be related to stock investment strategy. I have budget A = 30 Consider this list: myList = [[10,15], [11,13], [9,10]] for each element the first is expected return value, and second is the price.

Buying the first and second items maximize the return [10,15], [11,13] as 13 + 15 < 30 and return value is 21.

I have prioritize them based on value per price:

-------------
9,  10,  0.9
11, 13, 0.846
10, 15, 0.666
-------------

I Try to pick elements until my budget cannot afford element. Of course, this is not the right answer since it return [9,10], [11,13] and value 20.

I would appreciate any hint or link or even problem name.

1

There are 1 best solutions below

1
On BEST ANSWER

I think you have posed the knapsack problem:

The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.

The problem is essentially difficult (in a well defined technical sense). There are clever computer programs that find the answer, but for long lists they are not as fast as you'd hope.

https://en.wikipedia.org/wiki/Knapsack_problem