Calculate running hold duration

2 views (last 30 days)
david crowley
david crowley on 8 Sep 2021
Answered: KSSV on 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?

Accepted Answer

KSSV
KSSV on 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''}

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!