Moving window with condition check for Stock Price

4 visualizaciones (últimos 30 días)
Akshay Arora
Akshay Arora el 6 de Feb. de 2020
Hi ALl,
I would like to create a moving window of 30 days for a total term of (20*252 = 5040 days) and check if the stock price is greater than the target for 20 days in the consecutive 30 day window.
I am simulating the stock price and creating a matrix of [10^5, 5040], now I want a matrix which will check the condition i.e. the stock price should be greater than the target for 20 days in a moving window of consecutive 30-days.
Also I want to record the day when the condition is first met and use it to discount my stock price to T = 0.
I am using the following code to simulate my stock price
Days_window = 30;
Target = 16;
Days_check = 20; %Number of days to calculate end stock price
T = 5040; %Time from Valuation to Performance End Date
rfr = 0.0231; %Risk Free Rate
q = 0.00; %Dividend Yield
vol = 0.20; %Volatility of Companies for Simulation
s0 = 12.5; %Performance Start Date Stock Price
dt = 1/252;
T_Adj = 5010;
numsims = 10^5;
z = randn(numsims,T);
S = s0*cumprod(exp((rfr - q - 0.5*vol^2)*dt+sqrt(dt)*vol*z),2);
S is a matrix of [100000x5040]
Any help would be appriciated.
Thanks

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by