Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

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:

Key-Value Quantity Sequence number

Where key is a string, value is a rational floating-point number, quantity is a positive integer, and the sequence number is a positive integer.

Example:

1,2000,5,1;1,2050,5,2;2,3000,10,3

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:

1: 2000 # key: CurrentAverage(1) = ((0*0)+(2000*5))/5 1: 2025 # key: CurrentAverage(1) = ((2000*5)+(2050*5))/10 2: 3000 # key: CurrentAverage(2) = ((0*0)+(3000*10))/10

Test 1

Test Input

Download Test Input

1,2000,5,1;1,2030,15,2;1,2000,10,1;2,2050,15,5;1,2067,8,6;2,2050,5,7

Expected Output

Download Test Output

1: 2000 1: 2022.5 2: 2050 1: 2035.21 2: 2050

Test 2

Test Input

Download Test Input

1,2000,5,3;2,2040,5,2

Expected Output

Download Test Output

1: 2000

Test 3

Test Input

Download Test Input

1,2000,5,2;1,2050,5,4

Expected Output

Download Test Output

1: 2000 1: 2025

Test 4

Test Input

Download Test Input

1,2000,5,1;2,2050,15,2

Expected Output

Download Test Output

1: 2000 2: 2050

Step by Step Solution

3.58 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

Solution Calculate And Prints Weighted Moving Average def wmatradelnfo Split Trade Info String trade... 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

Recommended Textbook for

Contemporary Project Management

Authors: Timothy Kloppenborg

3rd edition

1285433351, 978-1285433356

More Books

Students explore these related Accounting questions

Question

What is project management?

Answered: 3 weeks ago