More efficient Matlab code to assign the nth iteration a line combination appears in the table (looking from top to bottom)

1 view (last 30 days)
I'm looking for a more efficient way to create a column in my table of stock options that assigns the nth value it has appeared in that table so far, moving from top to bottom.
First, I can show you want I'm talking about using the logic I have in Excel to create a Key that assigns the iteration a stock with an options contract x business days until expiration (BDTE) appears, using a key "BDTE" - "Iteration." In the Excel formula, it takes the total frequency of a given BDTE for an Underlying Symbol (TSLA in this case), and subtracts the number of times that same Ticker / BDTE combo appears in the rest of the table.
In Matlab, I tried using Parfor to create the iterations, but this code snippet takes ages to run, like 40 min, when the rest of my code takes like 5 minutes. Do you have any suggestions on logic to make this code more efficient?
count_call = zeros(call_height,1);
parfor h = 1:height(call_summary)
count_call(h) = sum((call_summary.UnderlyingSymbol == call_summary{h,'UnderlyingSymbol'}).*(call_summary.BDTE == call_summary{h,'BDTE'}).*(call_summary.DataDate >= call_summary{h,'DataDate'}));
end
call_summary(call_array,'Key1') = array2table(strcat(string(call_summary{call_array,'BDTE'}),'-',string(count_call(call_array,1))));
Thank you in advance for any ideas you have!
  1 Comment
dpb
dpb on 25 Oct 2022
First idea is that we'll need to have a set of the data to work from and then a definition of what you're actually trying to do. We can't do nuthin' with just an image to look at and nobody's going to try to figure out what is going on from just such a isolated code snippet, sorry...

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Functions in Microsoft Excel 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!