mail@pastecode.io avatarunknown
a month ago
2.8 kB
Programming challenge description:
When a trader buys or sells an asset, that trade is said to have a certain amount of "edge" defined as the difference between the trade price and a theoretical value. Theoretical value is what the Trader or Firm thinks the asset is worth, and can change throughout the day.


Traders typically want to execute trades that have positive edge, that is buying an asset for lower than the theoretical value, or selling an asset for higher than the theoretical value.

For example: TradePrice = 95, TheoreticalValue = 100, Edge = 100-95 = 5

As a Firm, we want to track which traders are making the best decisions, so we calculate a score for each trade.


Notice that negative edge will result in a negative score, indicating a bad trade.

Given a series of trades, print the trader with the highest cumulative score after each trade.

Additional Details
A "Buy" trade will have positive quantity, and "Sell" trades will be denoted by negative (-) quantity.

Theoretical Values can be updated periodically. Your solution should use the most recent theoretical value when calculating edge. If an asset does not have an available theoretical value at the time of trade, assume Edge = 0 and save the trade price as the theoretical value. Theo Updates are not retroactive, so any existing trade for that asset should NOT be updated

Trades may happen with negative edge. They are valid and should be included in a traders cumulative score.

If more than one trader has the highest cumulative score, use lexicographical ordering of TraderName to break the tie.

A number trade lines in the following format:

Trade <TraderName> <Asset> <Quantity> <Price>

Interlaced with 1 or more theo update lines in the following format:

TheoUpdate <Asset> <Value>


TheoUpdate 1 100
Trade Alice 1 1 95
Trade Bob 1 1 94
Trade Alice 1 -1 107
A line of output for each trade in the input, in the format

<TraderName> <Score>


Alice 25
Bob 36
Alice 74
Test 1
Test Input
Download Test 1 Input
TheoUpdate 1 100
Trade Alice 1 1 95
Trade Bob 1 1 94
Trade Alice 1 -1 107
Expected Output
Download Test 1 Output
Alice 25.00
Bob 36.00
Alice 74.00
Test 2
Test Input
Download Test 2 Input
TheoUpdate 1 100
Trade Alice 1 -2 101
Trade Bob 1 -2 99
Expected Output
Download Test 2 Output
Alice 2.00
Alice 2.00
Test 3
Test Input
Download Test 3 Input
TheoUpdate 1 100
Trade Alice 1 400 99
Trade Bob 1 5 90
Expected Output
Download Test 3 Output
Alice 400.00
Bob 500.00
Test 4
Test Input
Download Test 4 Input
TheoUpdate 1 100
TheoUpdate 2 200
Trade Alice 1 1 98
Trade Bob 2 1 199
Expected Output
Download Test 4 Output
Alice 4.00
Alice 4.00