Answered step by step
Verified Expert Solution
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
In part 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
volumecheck a computation request for your program
Each trade print is on a separate line. Each line contains the following spacedelimited fields:
the string "print"
timestamp int: the time at which the volumecheck command was issued, denoted as seconds since market open
security string: the name of the security for which to calculate
example input
print SILVER
print PEARL
volumecheck SILVER
print PEARL
input is guaranteed to be valid, note that
input is guaranteed to be nondecreasing ie each timestamp will be greater than or equal to the previous one.
string values are unquoted
all numerical values fit in standard bit primitive types
TASK
Your first goal is to calculate the running volume of trades on the market with perminute granularity.
Each time that a "volumecheck is received, print the volume and previous trade price of this security traded within the trailing seconds
you may use the following definitions:
if a volumecheck arrives at time T include all trades both printed before the volumecheck and with timestamp greater than T
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 and the price is NA
implementations should be efficient for many volume checks,ie still efficient if Ovolume checks Otrade prints
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started