Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a collection of interfaces and classes. Please review the code for: bugs algorithm and data structure issues general quality issues The interface

You are given a collection of interfaces and classes. Please review the code for: bugs algorithm and data structure issues general quality issues The interface IMarketDataFeed has a method tick this will fire any listeners registered with this component. AverageHalfSpreadIndicator is a class that subscribes to ticks received by IMarketDataFeed. It does some calculation when a tick is received and then notifies its listeners. This class should receive ticks from IMarketDataFeed This class should notify any listeners when it has performed its calculation The calculation should be optimal in speed Please also consider the the case where this code lives in: a single threaded environment a multi-threaded environment

image text in transcribed

image text in transcribed

public interface MarketDataFeed { String getStock(); void tick(MarketTick tick); void addListener(Function MarketTick, void> listener); public interface Indicator { void indicatorUpdated (Double value); public class MarketTick { public Double bid; public Double ask; public Double last; public void setBid(Double bid) { this.bid = bid; } public void setAsk(Double ask) { this.ask = ask; 3 public void setLast(Double last){ this. last = last; } public Double getBid() { return bid; 25 26 28 public Double getAsk() { return ask; 31 public Double getLast() { return last; 34 35 public Double getMid() { return (bid + ask) / 2; public class AverageHalfSpread Indicator { private ArrayList lastTicks; private ArrayList> listeners; public void onTick(MarketTick tick) { lastTicks.add(tick); if (lastTicks.size() = 1000) { lastTicks.remove(0); long start = System.currentTimeMillis(); var halfSpreads = lastTicks.stream().map((x) System.err.println("Time to compute spreads: -> 100 * (x.getMid() x.getBid()) / x.getBid()).mapToDouble(x-> x); + String.valueOf (System.currentTimeMillis() start) + " ms"); Double averageHalfSpread = halfSpreads.sum() / 1000; indicatorUpdated(averagehalfSpread); public void indicatorUpdated (Double calcValue) { listeners.forEach(x -> X.apply(calcvalue)); } 2 3 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 public static void main(String[] args) { MarketDatafeed mdf = Testhelper.createMarketDataFeed (args); Indicator indicator = new AveragehalfSpreadIndicator(); mdf,addListener(indicator)s TestHelper.runtests(mdf, indicator)s

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago