Каким образом можно распараллелить алгоритм?
Добрый день, форумчане.
Каким образом можно распараллелить этот алгоритм? Нужно использовать GPU вычисления. А в идеале запустить в несколько потоков. Ну мне хотя бы понять, как увеличить скорость расчёта за счет распараллеливания.
startStockPrice = 100; % Stock price starts at $100.
strike = 95; % Strike price for the option ($).
barrier = 150; % Barrier price for the option ($).
riskFreeRate = 0.005; % 0.5 annual percent.
timeToExpiry = 2; % Lifetime of the option in years.
volatility = 0.20; % 20% annual volatility.
M=1e7;
Start = cputime; % time
if startStockPrice < barrier
final_vals=startStockPrice*exp((riskFreeRate - 0.5*volatility^2)*timeToExpiry + volatility*sqrt(timeToExpiry)*randn(M,1));
end
if startStockPrice < barrier
option_values=max(strike-final_vals,0); % Evaluate the Put option options
present_vals=exp(-riskFreeRate*timeToExpiry)*option_values; % Discount under r-n assumption
else
% Hit the barrier, so the option is withdrawn.
present_vals = 0;
end
put_value=mean(present_vals); % Take the average
display(put_value)
Elapsed = cputime - Start %Measure the execution time
Источник: Stack Overflow на русском