The solution code provides a definition of a daily rate of return function as follows:

(1) def simple_rate_of_return(adj_closings):

(2)…daily_simple_ror = np.diff(adj_closings)/adj_closings[:-1]

(3)…return daily_simple_ror

Can someone explain line (2) above? Specifically, how does the syntax of the np.diff() function work?

this is the first time I’ve seen this function. I understand how np.diff() works over a single array.

The “(adj_closings)/adj_closings[:-1]” part is what I’m looking to clarify.

Thanks!