PL Calculation HackerRank 笔试OA代写

2. PL Calculation
Summary: given position entry table and corresponding market data, calculate resulting
profit/loss.
Detailed: we have a detailed record of all trades that occurred over a period of time. They are
written as
{(date of the trade, ticker (instrument/stock id)) : change in quantity). E.g, a history of buying 10
shares of Apple
on day 1, selling 25 shares on day 3, and buying 10 shares on day 4 will be written as
{
(“day 1”, “AAPL’) : 10,
(“day 3”, “AAPL”) : -25,
(“day 4”, “AAPL”) : 10
Besides that, we have history of stock prices for each day, in native currency; mapping of which
currency is native
for which stock (assume it’s a constant over time); and USD fx rates for each day (how many
dollars each unit of that
currency costs on that day).
We want to calculate net profit(loss) resulting from all recorded trades, with the assumption that
we liquidate all
positions in the last day of price history. That is, for each instrument, we add a trade that brings
our holdings in
that instrument to 0; in the example above, such a trade would be buying 5 shares of Apple.
Profit/loss from trade in native currency: pl = (price when sold – price when bought) *
quantity_of trade.