I'm a bit stuck with this one and tried some stuff mentioned here but didn't help. Basically, I've got these arrays:
returns = np.array([0.01, 0.2, 0.05, -0.01, 0.3, -0.5])
weights = np.array([0.3, 0.25, 0.2, 0.15, 0.1, 0])
The idea is to create dynamic weighting in which highest weight matches with highest return. I tried sorting two arrays (or lists) depending on one another but it doesn't help (as mentioned here: Sorting list based on values from another list?), since it really depends on weight initialization.
Desired output would be (weights change their position depending on max/min and in between values of the returns array):
returns = np.array([0.01, 0.2, 0.05, -0.01, 0.3, -0.5])
weights = np.array([0.15, 0.25, 0.2, 0.1, 0.3, 0])
This generally would go row by row through some simple iteration but I cannot seem to crack the problem first. Sorting both separately and then matching ascending / descending order) is no good, since returns array has to be unsorted. Any ideas?