No, this is not related to interviews or cryptocurrencies! :)
It is for a non-profit personal web application designed to enhance a game.
This question involves both finance and coding.
I am developing this web app using Vue.js, so I prefer a JavaScript solution. However, an abstract approach or pseudo-code would also be helpful as I can translate it into JavaScript.
Here is the scenario:
Multiple locations (referred to as "stores") buy and sell various items at different prices.
Prices fluctuate randomly, possibly due to supply and demand, but that is not crucial to the problem.
There will be around 100-1000 locations and 10-100 different items.
The majority of locations (estimated 80-90%) will only deal with a few items.
Some locations (about 1-10%) will handle many items, if not all.
Around 50% of locations may only buy or sell, not both.
The objective is to display an extensive list of all locations that have a buying price for an item compared to locations that have a selling price for that same item (similar to permutations/combinations, but with expected gaps).
The final output should be a simple list/array of objects (keyed/value pairs).
A worst-case scenario could involve a paginated list of 99 million objects (1000 stores * (1000 - 1) stores * 100 items); however, there are anticipated gaps in the data, so ideally there would be significantly fewer than 1 million objects (ideally under 100,000; they do not all need to be live in memory and could be loaded from storage).
For example (sorted by Item and Buy Location for clarity):
Item Buy Location Buy Price Ratio Sell Price Sell Location
Item A Location A 4 0.5 2 Location B
Item A Location A 4 2.0 8 Location C
Item A Location B 6 0.66 4 Location A
Item A Location B 6 1.33 8 Location C
Item A Location C 10 0.4 4 Location A
Item A Location C 10 0.2 2 Location B
Item B Location A 3 0.33 1 Location B
Item B Location A 3 1.33 4 Location C
Item B Location B 3 0.66 2 Location A
Item B Location B 3 1.33 4 Location C
Item B Location C 5 0.4 2 Location A
Item B Location C 5 0.2 1 Location B
Each column in the list is sortable, with the default being "Ratio" to display the optimal combinations of buying and selling locations. When prices are updated, Vue.js automatically updates and resorts the list.
Currently, I have inefficient ideas on how to tackle this issue, which involve regenerating the entire list whenever a single price changes.
Since the final output must support arbitrary sorting, direct indexing or access to items is not plausible.
If the price for a specific location's item changes, there isn't a method to pinpoint and update that specific row or cell.
I suspect that my approach is lacking efficiency, and I believe this task has been addressed before in scalable ways.
For instance, creating a straightforward buy/sell price chart across multiple exchanges.
While considering exploring open-source cryptocurrency bot code, this seems more like a finance-related challenge that I wish to comprehend rather than a programming one that I intend to replicate.
How would you go about implementing this?
What kind of dataset(s) would you utilize?
Thank you!