Please do that in C++, I need it immediately. Thanks You are given a series of t
ID: 3845088 • Letter: P
Question
Please do that in C++, I need it immediately. Thanks
You are given a series of trades. Each trade has a key, a value, a quantity, and a sequence number. For each trade, print the weighted moving average of all the trades for that particular key. Round your average to two decimal places. If the sequence number for any trade TT is less than the sequence number for any previous trade, throw out TT. Do not print anything for TT or factor it into your WMA.
M_{x+1} = {(M_x * Q_x)+(v_{x+1} * q_{x+1}) over Q_{x+1}}M x+1 = Q x+1 (M x Q x )+(v x+1 q x+1 )
Where M = weighted moving average, Q = total quantity, q = current quantity, and v = current value.
Input:
The input will be a semicolon delimited string of trades, with each trade being comma delimited. The parameters for each trade will be in order:
Where key is a string, value is a rational floating point number, quantity is a positive integer, and sequence number is a positive integer.
Example:
Output:
For each trade you do a calculation for, print on a new line {key}: {weighted moving average for key}
Example, from the example input above:
Test 1
Test Input
Download Test Input
Expected Output
Download Test Output
Test 2
Test Input
Download Test Input
Expected Output
Download Test Output
Test 3
Test Input
Download Test Input
Expected Output
Download Test Output
Test 4
Test Input
Download Test Input
Expected Output
Download Test Output
Explanation / Answer
onAcknowledgement()
{
If acknowledgement is for instr1
onMarketData(tick1, tick2)
}
OnMarketData(tick1, tick2)
{
buyPrice = tick2.bid- s
if buyorder present in instr1
replace it to buyPrice
else
send new order at buyPrice
sellPrice = tick2.ask + s
if sellorder present in instr2
replace it to sellPrice
else
send new order at sellPrice
}
#include<iostream>
onExecution{
if buy execution happened on instr1
send sell order on instr2
else if sell execution happened on instr1
send buy order on instr2
else if execution is on instr2
onMarketData(tick1, tick2);
}
onReject{
if reject on instr1
onMarketData(tick1, tick2)
}