Monthly traded value

dates

Monthly traded value

Robinhood Pandas Interview Question

Robinhood's finance team reports the total value of shares traded each month, counting both buys and sells.

Using the trades DataFrame, find each month, written as text such as "2024-01", and the total value traded that month as traded_value, rounded to 2 decimal places. A trade's value is the number of shares times the price. Sort the rows by month, earliest first. Assign the answer to result.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist
  • ML Engineer

tradesDataFrame18 rows

Column NameType
trade_idint64
user_idint64
symbolstr
sidestr
sharesint64
pricefloat64
executed_atstr

tradesExample Input

trade_iduser_idsymbolsidesharespriceexecuted_at
61001801AAPLbuy10185.22024-01-04 09:35:12
61002802TSLAbuy5238.452024-01-09 10:02:44
61003801NVDAbuy2495.12024-01-22 13:15:05
61004803AMZNbuy8151.32024-01-30 15:42:18
61005802TSLAsell5187.92024-02-06 09:48:31
61006804AAPLbuy3188.852024-02-13 11:21:09
61007801AAPLsell4182.32024-02-20 14:05:57
61008803NVDAbuy1721.332024-02-27 10:30:00
61009805AMZNbuy12175.12024-03-01 09:31:40
61010804TSLAbuy6199.42024-03-08 12:44:23

Example Output

monthtraded_value
2024-015244.85
2024-022956.58
2024-033297.6

Explanation

In January, four trades were worth 1,852.00, 1,192.25, 990.20 and 1,210.40, which adds up to 5,244.85. Buys and sells both count toward the value traded, and the months are listed from earliest to latest.

The example above is a small slice of the data. Your code runs against the full DataFrames.