loop based on a condition in another column
Mostrar comentarios más antiguos
I'm working with a 694672x4 table containing the PermNo., date, CUSIP and stock price of a multitude of shares. The data is sorted such that the full time series of a stock is listed below the full time series of the following stock and so forth. (Pls see photo below). I am trying to calculate the daily returns of each stock individually, however I struggle with the way the data is structured. As you can see, column 3 contains the CUSIP which is an individual identifier to every stock in the sample. I am now trying to tell MatLab to calculate the daily returns (using (diff(log(X))))for all rows with the same identifier and start from scratch once the identifier changes. Unfortunately, I cannot provide any initial code as I don't know where to start...
Thank you in advance!
4 comentarios
Walter Roberson
el 18 de Mzo. de 2021
Simon Jurgies
el 18 de Mzo. de 2021
Jan
el 18 de Mzo. de 2021
func = @(x) diff(log(x))
Walter Roberson
el 18 de Mzo. de 2021
Probably you will need
func = @(x) {diff(log(x))}
That is because you will be processing vectors, and diff() of a vector is a vector (one shorter), but splitapply() requires that you return a scalar.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Big Data Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!