how to simulate different investments
1 view (last 30 days)
Show older comments
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; % because I can’t buy a fraction of a stock
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);
% in this way I’ve simulated the stock price by time intervals
end
buy = SimulateStock <= S(:,1); %where the i-th investor could buys
sell = SimulateStock >= S(:,2); %where the i-th investor could sells
end
0 Comments
Answers (1)
per isakson
on 22 Apr 2021
Edited: per isakson
on 28 Apr 2021
Based on your question, I've made a small object oriented demo.
You don't prescribe how many shares an investor will trade in one day. I assume an investor will trade zero or one share per day.
(Another purpose was to try out "Ran in 2021a".)
With your input example the stock price may from start rise to levels where none of the investors will trade. In that case Total will be equal to zero(4,100).
%%
IC = 100;
T = (1:100);
S = [15 20; 16 21; 14 18; 15 19];
D = [10 0.20; 5 0.3; -4 0.35; -2 0.15];
ISP = 18;
%%
[Total,stock_price] = Simulates( IC, T, S, D, ISP );
disp('simulate_different_investments')
disp( stock_price(1:min(9,end)) )
disp( Total(:,1:min(9,end)) )
0 Comments
See Also
Categories
Find more on Transaction Cost Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!