FunctionRacerProblemsRace

Deepest Fall per Ticker

MediumpandasPython

prices has columns ticker and close, in day order. For a ticker, the fall on a day is how far its close sits below its highest close so far, as a share of that high: (high - close) / high. Return a dict from each ticker to its largest fall.

Example 1

prices {"ticker":["A","B","A","B","A","B"],"close":[100,50,80,60,120,30]}
returns {"A":0.2,"B":0.5}

A falls from 100 to 80, which is 0.2. B reaches 60 and then drops to 30, which is 0.5.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems