Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Throughout this problem, you are a broker interfacing with the Berkeley Exchange. Your program will read events from stdin and emit output to stdout. Part

Throughout this problem, you are a broker interfacing with the Berkeley Exchange. Your program will read events from stdin and emit output to stdout.
Part 1
In part 1, you are tasked with tracking market activity on the Exchange. Your program will read printed trades as they come in and , when requested, print market activity data for a particular security. More details below.
Input
the input is composed of a stream of data coming from the Berkeley Exchange, with two data types:
print (a record of a trade on the exchange)
volume-check (a computation request for your program)
Each trade print is on a separate line. Each line contains the following space-delimited fields:
1. the string "print"
2. timestamp (int): the time at which the volume-check command was issued, denoted as seconds since market open
3. security (string): the name of the security for which to calculate
example input
print 12 SILVER 10012
print 29 PEARL 2599
volume-check 49 SILVER
print 61 PEARL 25100
input is guaranteed to be valid, note that
input is guaranteed to be non-decreasing , i.e. each timestamp will be greater than or equal to the previous one.
string values are unquoted
all numerical values fit in standard 32-bit primitive types
TASK
Your first goal is to calculate the running volume of trades on the market , with per-minute granularity.
Each time that a "volume-check " is received, print the volume and previous trade price of this security traded within the trailing 60 seconds .
you may use the following definitions:
if a volume-check arrives at time T, include all trades both printed before the volume-check and with timestamp greater than T-60
volume is the sum of all relevant trade quantities
previous trade price is the price of the most recent print for this security
if no trades have been executed in the past minute for a particular security , the volume is 0 and the price is "NA"
implementations should be efficient for many volume checks,i.e. still efficient if O(volume checks )=O(trade prints)

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What are some challenges with using Biorenewable resources?

Answered: 1 week ago

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago