record the number of column when the value first hits the threshold. "Monte Carlo simulation finding "t" when the threshold is met for 100,000 iteration".
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi all,
I am fairly new to Matlab and programming in general, but I have an interesting problem to solve.
I have a transpose of a matrix(100,000x2521) values, the number of rows represent the number of iteration that is 100,000 and number of columns represent total number of trading days in 10 years (252 in 1 year).
I want to record the column number when the first 20th day happens within 30 days when the stock price >= 12.
I have the following output till now
S(2521, 10^5) ---> this is the stock price matrix generated using the geometric brownian motion formula.
S = S0*[ones(1,nsims); ...
cumprod(exp(r-sig^2/2)*dt+sig*sqrt(dt)*randn(steps,nsims)),1)]; % where steps = 2521 and nsims = 10^5; double matrix
S_Check = S>=12; % logical
S_cumsum = cumsum(S_Check); % logical
S_cumsum_T = S_cumsum' % Transpose
I have the following code till now, S_cumsum_t will indicate at what column the value >= 20; I want to record the column number when the first value = 20. I want to repeat this process 10^5 times and then calculate the average of the recorded column number i.e. (sum(colummn number for each iteration)/10^5).
I am unable to wrap my head around this problen since two days, I have tried a lot of different things but failed.
Any help would be greatly appreciated and for would be of great help.
Thanks in advence !!
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Monte-Carlo에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!