Calculate running hold duration

2 ビュー (過去 30 日間)
david crowley
david crowley 2021 年 9 月 8 日
回答済み: KSSV 2021 年 9 月 8 日
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?

採用された回答

KSSV
KSSV 2021 年 9 月 8 日
% 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''}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by