Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc; clear all;
- %% Init params
- opt = {'il','us','lin'};
- annualYield.il = 4 / 100; % [pct]
- annualYield.us = 4 / 100; % [pct]
- annualYield.lin = 0; % [pct]
- annualInflation.il = 0; % [pct]
- annualInflation.us = 0; % [pct]
- annualInflation.lin = 1.5 / 100; % [pct]
- tax.il = 25 / 100; % [pct]
- tax.us = 25 / 100; % [pct]
- tax.lin = 0; % [pct]
- dividendTax.il = 0; % [pct]
- dividendTax.us = 25 / 100; % [pct]
- dividendTax.lin = 0; % [pct]
- annualDividend.il = 2 / 100; % [pct]
- annualDividend.us = 2 / 100; % [pct]
- annualDividend.lin = 0; % [pct]
- annualfundExpense.us = 0.1 / 100; % [pct]
- annualfundExpense.il = 0.4 / 100; % [pct]
- annualfundExpense.lin = 0; % [pct]
- for iOpt=1:numel(opt)
- monthlyYield.(opt{iOpt}) = (1+annualYield.(opt{iOpt}))^(1/12)-1;% [pct]
- monthlyInflation.(opt{iOpt}) = (1+annualInflation.(opt{iOpt}))^(1/12)-1;% [pct];
- monthlyFundExpense.(opt{iOpt}) = (1+annualfundExpense.(opt{iOpt}))^(1/12)-1; % [pct]
- end
- actionType.il = 'pctg';
- actionType.us = 'fixed';
- actionType.lin = 'fixed';
- actionCost.il = 0.07 / 100; %[pct]
- actionCost.us = 28; % [nis]
- actionCost.lin = 0; % [nis]
- initialCapital = 1e5; % [nis]
- monthlyDeposit = 1e4; % [nis]
- currencyChangeCost.us = 0.5 / 100; % [nis]
- currencyChangeCost.il = 0; % [nis]
- currencyChangeCost.lin = 0; % [nis]
- years = 20;
- monthsPerDeposit = 1;
- line.il = 'b+';
- line.us = 'r+';
- line.lin = 'g+';
- %% Simulate investment
- optOn = 1:3;
- capital = zeros(years*12, numel(optOn));
- gain = zeros(years*12+1, numel(optOn));
- for iOpt = optOn
- % Initial buyout
- capital(1,iOpt) = initialCapital;
- capital(1,iOpt) = capital(1,iOpt) * ( 1-currencyChangeCost.(opt{iOpt}) ); % currency change
- switch actionType.(opt{iOpt}) % Initial action cost
- case 'pctg'
- capital(1,iOpt) = capital(1,iOpt) * ( 1-actionCost.(opt{iOpt}) );
- case 'fixed'
- capital(1,iOpt) = capital(1,iOpt) - actionCost.(opt{iOpt});
- end
- % Continuous progress
- for iMonth = 2:(years*12-1)
- % Gain yield - continuously
- gain(iMonth-1,iOpt) = capital(iMonth-1,iOpt) * ( monthlyYield.(opt{iOpt}) - ...
- monthlyFundExpense.(opt{iOpt}) - monthlyInflation.(opt{iOpt}) );
- capital(iMonth,iOpt) = capital(iMonth-1,iOpt) + gain(iMonth-1,iOpt);
- % Gain dividends every 12 months
- if mod(iMonth, 12) == 0 % Every end of year
- dividend = capital(iMonth,iOpt) * annualDividend.(opt{iOpt}); % get dividend
- capital(iMonth,iOpt) = capital(iMonth,iOpt) - dividend; % reinvest dividend
- taxedDividend = dividend * ( 1-dividendTax.(opt{iOpt}) ); % tax dividend
- capital(iMonth,iOpt) = capital(iMonth,iOpt) + taxedDividend; % reinvest dividend
- end
- % Timely deposit
- if mod( iMonth, monthsPerDeposit ) == 0 % deposit every monthsPerDeposit
- deposit = monthlyDeposit * monthsPerDeposit;
- deposit = deposit * ( 1-currencyChangeCost.(opt{iOpt}) ); % currency change
- switch actionType.(opt{iOpt}) % action cost
- case 'pctg'
- deposit = deposit * ( 1-actionCost.(opt{iOpt}) );
- case 'fixed'
- deposit = deposit - actionCost.(opt{iOpt});
- end
- capital(iMonth,iOpt) = capital(iMonth,iOpt) + deposit;
- end
- end
- % Final buyout (tax event)
- totalGain = sum(gain(:,iOpt));
- capital(iMonth+1,iOpt) = capital(iMonth,iOpt) - totalGain * tax.(opt{iOpt});
- end
- % Plot results
- fig = figure(); hold on;
- xlabel('Months'); ylabel('Capital');
- msg = sprintf('%d%% annual yield, %d%% annual dividend, commisions like in IBI.', ...
- 4, 2);
- title(msg);
- for iOpt = optOn
- plot(1:size(capital,1), capital(:,iOpt), line.(opt{iOpt}))
- end
- legend(opt, 'Location','northwest');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement