The function should provide the equilibrium price based on the columns: A column: BUY, B column: PRICE, C column: SELL, and should be accessible in the Excel sheet as =equilibrium(A3:C22). These columns function as a stock market, where there's a price ​(e.g., 10) at which they want to sell (e.g., 348) units and buy (e.g., 227) units.
It should cumulate the sales quantity column from bottom to top and the purchase quantity column from top to bottom, named kumbuy and kumsell respectively.
It should find the minimum individually from the two cumulative columns row by row, named kummin.
It should find where (which row) among the values of kummin is repeated, and name the found rows as kumminrep.
In the rows of kumminrep, it should find the corresponding prices from the PRICE column, named kumminrepprice.
For each row of kumminrepprice, it should take the respective element from the BUY and SELL columns, and take the maximum for each separately, then subtract the corresponding row of kummin individually.
It should find in which row the minimum of these obtained values ​​is located, and return the associated price, named equilibriumprice, and write it in the selected cell
Here is the calculation by hand;
Képernyőkép 2024-04-18 135435.jpg