Define loss as minus the net daily account return, so a positive loss number means the account fell. Sort n equally weighted losses from smallest to largest. For 0 < alpha < 1, this lesson uses the empirical inverse-CDF quantile: VaR at level alpha is loss number ceil(n × alpha), counting from one.
Define empirical expected shortfall as the average of the worst (1 - alpha) probability mass. With equally weighted observations and an integer tail count, average exactly that many largest losses. With a fractional tail count, include the next boundary observation only with the fractional weight required. For tied boundary values, that allocation gives the same weighted loss whichever tied observation supplies the fraction. Other software conventions may differ; identify the one actually used.