N investors want to buy the stocks of a company . The stock’s trend is represented by the probability distribution D, where in the first column there are the increases / decreases of the stock compared to the previous time interval, and in the second column there are the probability of the adjacent increase/decrease. At the beginning all investors have the same amount of money (100$) but have different investment strategy described by the matrix S (Nx2) where each row indicates the strategy of an investors, in the first column there are the values below which the investor buys the stock, and in the second column there are the values above which the investor sells it. If the stock price goes to 0 the investment end.
I have to write the function Simulates that have the following input:
- IC, the initial capital (it’s the same for all investors, eg 100$)
- T, a vector containing time intervals (eg. 100 days)
- S, (eg. S= [15 20;16 21;14 18; 15 19]; )
- D (eg. D = [10 0.20;5 0.3; -4 0.35; -2 .15]; )
The output is Total, a matrix that contains the trend of each investors by time (NxT).
Ps the initial stock price is 18$ for example.
Right now I have a problem, because I don’t find a solution in order to calculate the trading of each investors by considering the fact that the budget for each investments has an amount limit and the investors can’t disinvest if they didn't invest previously.
function [Total] = Simulates (IC,T,S,D)
initial_stock_price = 18;
initial_value = fix(IC/ initial_stock_price)* initial_stock_price;
Cum = cumsum(D(:,2));
SimulateStock =nan(1,T);
SimulateStock (1) = initial_stock_price *(1+D(sum(cumulata<rand)+1,1)/100);
for i=2:T
SimulateStock (i) = SimulateStock (i-1)*(1+D(sum(cumulata<rand)+1,1)/100);
end
buy = SimulateStock <= S(:,1);
sell = SimulateStock >= S(:,2);
end