101
0/304
Loading content...
A portfolio accounting service records executed buy and sell operations in a transaction ledger.
Table: stocks
Data guarantees:
Task: Compute the final realized capital gain/loss per stock across all operations.
Profit convention:
Output requirements:
Supported submission environments:
stocks:
| stock_name | operation | operation_day | price |
|--------------|-----------|---------------|-------|
| Alpine AI | Buy | 1 | 120 |
| Alpine AI | Sell | 4 | 230 |
| Alpine AI | Buy | 6 | 200 |
| Alpine AI | Sell | 8 | 150 |
| Blue Harbor | Buy | 2 | 500 |
| Blue Harbor | Sell | 7 | 900 |[
{"stock_name":"Alpine AI","capital_gain_loss":60},
{"stock_name":"Blue Harbor","capital_gain_loss":400}
]Alpine AI has (230-120) + (150-200) = 60. Blue Harbor has one cycle: 900-500 = 400.
stocks:
| stock_name | operation | operation_day | price |
|---------------|-----------|---------------|-------|
| Quant Nova | Buy | 3 | 1000 |
| Quant Nova | Sell | 5 | 1000 |
| Quant Nova | Buy | 7 | 1400 |
| Quant Nova | Sell | 9 | 1200 |
| Retail Loop | Buy | 1 | 40 |
| Retail Loop | Sell | 2 | 20 |[
{"stock_name":"Quant Nova","capital_gain_loss":-200},
{"stock_name":"Retail Loop","capital_gain_loss":-20}
]Quant Nova has 0 on the first cycle and -200 on the second. Retail Loop has a single losing cycle of -20.
stocks:
| stock_name | operation | operation_day | price |
|----------------|-----------|---------------|-------|
| Harbor Metals | Buy | 10 | 30000 |
| Harbor Metals | Sell | 15 | 41000 |
| Harbor Metals | Buy | 20 | 25000 |
| Harbor Metals | Sell | 25 | 23000 |
| Urban Energy | Buy | 11 | 5000 |
| Urban Energy | Sell | 14 | 8000 |
| Urban Energy | Buy | 18 | 9000 |
| Urban Energy | Sell | 22 | 12000 |[
{"stock_name":"Harbor Metals","capital_gain_loss":9000},
{"stock_name":"Urban Energy","capital_gain_loss":6000}
]Harbor Metals: (41000-30000) + (23000-25000) = 9000. Urban Energy: (8000-5000) + (12000-9000) = 6000.
Constraints