Calculate running hold duration

2 vues (au cours des 30 derniers jours)
david crowley
david crowley le 8 Sep 2021
Réponse apportée : KSSV le 8 Sep 2021
I have a table that lists the history of stock transaction (extract attached). I require assistance to find out how long I've held each stock for?
For example, I held AAP within the 12 stocks (fixed scalar) I held on 31/12/1999 and 7/1/2000. However it was not held in the portfolio of 14/1/2000. This would mean the hold period for this stock is two weeks (2 weeks). I require this calculation to go into a separate table.
Row 1 - '31-Dec-1999' 'AAP'
Row 13 - '07-Jan-2000' 'AAP'
Can someone please assist as to how i can go about implementing this?

Réponse acceptée

KSSV
KSSV le 8 Sep 2021
% T = readtable('example.xlsx') ;
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/732154/example.xlsx');
idx = strcmp(T.(2),{'''AAP'''}) ;
T(idx,:)
ans = 2×2 table
date code _________________ _________ {''31-Dec-1999''} {''AAP''} {''07-Jan-2000''} {''AAP''}

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by