s ravi chandran wrote:
Here StockDepth is a class with two treemaps BidDepth and AskDepth(reverse sorted). The key to maps is stock price and value is a custom object containing volume. Would someone please tell me how I can improve it to add positions (index) and faster updation and access time using core java. One of the requirements I have is that when I find a matching stock, I have to send this information to a service too. That is even more hard to workout, as the place I am matching the stocks, I only have price and quantity, no stock information.
Hello, Ravi -- here are some questions to help move this along.
Is this a learning exercise to help develop basic java skills, or do you anticipate building an industrial-strength financial application? If you're just here to learn, you're in the right place.
How strong is your understanding of the problem domain -- i.e. practical knowledge of how electronic trading works? The deeper the better -- if you're not already very up to speed (well beyond the info contained on the linked Wikipedia page), that is a good place to start increasing your knowledge. It might change how you draw your entity diagram. For example, I have basic knowledge of the business needs of simple capital markets software, and I am not intuitively clear about the difference between the InstrumentDepth and StockDepth entities. A StockDepth feels like a type of InstrumentDepth. You may not need both; or if you need both, you might also need entities representing Currency, FixedIncome, Commodity, and other non-Equity tradable instruments.
What is the significance of the
word "Depth" in the class names?
Here StockDepth is a class with two treemaps BidDepth and AskDepth(reverse sorted). The key to maps is stock price and value is a custom object containing volume.
If the custom object just represents volume, it's definitely missing information -- i.e. the account (investor) that is making the ask or bid at that price level and volume. Is that already part of your design? You'll need it when you think about representing positions, unless I am misunderstanding things.
Very minor point: you say they are "treemaps", but I am reading that they are "sorted maps". Forgive me for picking a nit, but from a design point of view, you have decided you need maps whose price key is sorted (i.e.
java.util.SortedMap<Price, CustomObject> interface) -- and you create them using the
java.util.TreeMap concrete class. Again, that's assuming I haven't misunderstood -- tell me if I have.
Something I highly recommend even if this is just for fun -- don't use the
double (or
Double) data type to represent prices or money, because of limits to the precision of floating point data classes. It's a bad practice and
you should avoid falling into that habit. Do a little research to select a good library class for money, or just use
java.math.BigDecimal.
Let us know how this is going. And thumbs up for posting about this at a design level rather than throwing code at us.
--Scott