ORDERID | TRADER | STKCODE | QUANTITY | PRICE | TRADETYPE | FEE | TIMESTAMP | 1 | AAA | 222222 | 100 | 10 | Buy | 0.2 | 5/9/2016 13:38 | 2 | BBB | 333333 | 1000 | 8.8 | Sell | 10.56 | 5/9/2016 10:37 | 3 | AAA | 222222 | 100 | 11 | Sell | 1.32 | 5/10/2016 13:38 | 4 | BBB | 333333 | 800 | 9 | Buy | 1.6 | 5/11/2016 14:58 | 5 | BBB | 333333 | 400 | 9.2 | Buy | 0.8 | 5/16/2016 10:28 | 6 | AAA | 555555 | 600 | 15.5 | Buy | 2 | 5/16/2016 10:31 |
数据如上所示,逗号作为字段之间的分隔符。
Note: Either long a stock (buy first, and sell later) or short a stock (sell first, and buy later) first is allowed For a trader, total Buy Quantity and Sell Quantity might not be equal, in that case, just calculate the realized profit or loss Transaction fee should be considered as cost, and all fees are realized
要求得到如下结果:
AAA 96.48
BBB -252.96
每个账号每个股票的盈亏情况,
使用MR或你擅长的任何语言都可以。
补充内容 (2018-5-10 14:02):
DESCRIPTION
Here we have a list of stock orders for some users in the same period. We want to sort these users according to their realized profit, i.e. how much they have already earned.
Please note that:
Either long a stock (buy first, and sell later) or short a stock (sell first, and buy later) first is allowed
For a trader, total Buy Quantity and Sell Quantity might not be equal, in that case, just calculate the realized profit or loss
Transaction fee should be considered as cost, and all fees are realized
INPUT
Input is in TSV format, i.e. columns are separated by tab, like:
OrderId Trader StkCode Quantity Price TradeType Fee Timestamp
1 AAA 222222 100 10 Buy 0.2 2016-05-09 13:38:24
2 BBB 333333 1000 8.8 Sell 10.56 2016-05-09 10:37:16
3 AAA 222222 100 11 Sell 1.32 2016-05-10 13:38:24
4 BBB 333333 800 9.0 Buy 1.6 2016-05-11 14:58:30
5 BBB 333333 400 9.2 Buy 0.8 2016-05-16 10:28:24
6 AAA 555555 600 15.5 Buy 2.0 2016-05-16 10:31:33
7 ...
OUTPUT
Output should be TSV format too, including 2 columns: Trader, profit/loss. Header is not needed.
For example, given the input above, the correct output is:
AAA 96.48
BBB -252.96
REQUIREMENT
Please write code that takes orders as input, and outputs users’ profits, sorted in descending order.
You may use any language you like. Your solution will be graded on the following criteria:
Code readability, quality, and design. In terms of quality, please write your code as if it would eventually be pushed into production.
Correctness / performance (speed/memory footprint
|