# Untitled unknown
plain_text
a month ago
2.8 kB
2
Indexable
Never
```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.

Score=SignOfEdge(Edge^2∗∣Quantity∣)

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

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.

Input:
A number trade lines in the following format:

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

TheoUpdate <Asset> <Value>

Example:

TheoUpdate 1 100
Output:
A line of output for each trade in the input, in the format

Example:

Alice 25
Bob 36
Alice 74
Test 1
Test Input
TheoUpdate 1 100
Expected Output
Alice 25.00
Bob 36.00
Alice 74.00
Test 2
Test Input
TheoUpdate 1 100
Expected Output
Alice 2.00
Alice 2.00
Test 3
Test Input
TheoUpdate 1 100
Expected Output