I've created this snippet for you with comments.
clear all;
close all;
T = readtable('Optionprices.xlsx');
dates = unique(T.Date);
for i = 1:numel(dates)
idx = ismember(T.Date, {datestr(dates(i))});
currentTable = T(idx,:);
aoe = size(currentTable,1);
for j = 1:aoe
currentTable.NearestPrice(j) = abs(currentTable.Price(j) - currentTable.Strike(j));
end
[~,I] = min(currentTable.NearestPrice);
vector = zeros(aoe,1);
vector(I) = currentTable.Strike(I);
currentTable.NearestPrice = vector;
T(idx,:) = currentTable;
end
writetable(T,'OptionpricesV2.xlsx');
Because you're new to all this, I suggest reading some of the documentation and try to make your own snippets. The people here are glad to help but next time you should also provide a bit of code of what you've already tried.
Best Answer