Ding 的个人资料EpicMorningBell照片日志列表更多 ![]() | 帮助 |
|
EpicMorningBellFuture is as certain as life will come to an end... 2009/6/21 A shrewd insight merely through observation.The fact that the thorny vine finally gave in to the inexorable hunter, as meant to be as it was, still revealed an exciting truth that sometimes the most profund impact could've come from an simple yet benign act, scrubbing away the layer of confusion and contradiction for those who enjoyed the comfort provided so long by various excuses.... 2009/3/19 Distilled truth.The most horrible force in this world is neither the complication of weaponry, nor the great might of deadly army, but the little greed resides in that man's heart. -- He who was not metionable long ago... 2009/2/27 Retirement Planning.To program a simulation in Matlab that is meant to assist in retirement planning. Make the following assumptions: a. You have 30 years until retirement. b. Your income is currently $100,000 per year. c. It will increase at the rate of inflation (r_inf) which is 3% per year (annualized) (so next year, you’ll earn $103,000). d. During each of the next 30 years, you contribute x% of this income to a retirement account. For simplicity, assume that your contribution is made in a lump sum at the beginning of each year. e. You begin with an asset allocation of 60% stocks and 40% (long-term) bonds. During each subsequent year, you reduce the asset allocation to stocks, so that after T years, you have 60-T % in stocks and 40+T % in bonds. (You’ll rebalance your portfolio at the beginning of each year by selling stocks or bonds to ensure that you have the appropriate allocation for that year.) f. During each of the 30 years after retirement (years 31-60), you withdraw 70% of your current income, adjusted for inflation. (For instance, in year 40, you withdraw .7*100,000*(1.03)^40.) g. Assume that on average, stocks return 10% per year, while bonds return 6.5%. Furthermore, the standard deviation of the log-return of stocks over one year is 20%, while the standard deviation of the log-return of bonds is 8%. The correlation between stock and bond log-returns is 0.2. (Through time, this correlation is actually very unstable, but more often than not, it is positive.) The simulation will entail 60 annual timesteps. What percentage of your income (x) must you contribute to your retirement account to ensure that there is less than a 5% chance that you’ll run out of money during your 30 years of retirement? What percentage must you contribute to ensure that the probability of exhausting your savings is less than 1%
ms=.1;
ss=.2;
mb=.065;
sb=.08;
rho=.2;
NumTimeSteps=60;
NumPaths=50000;
Initws=.6;
InitAssetValue=100000;
InflaRate=.03;
TimetoRetirement=30;
x=.5;
function[rs,rb]=AssetReturnsSimulation(ms,ss,mb,sb,rho,NumTimeSteps,NumPaths)
dt=1;
y1=randn(NumTimeSteps,NumPaths);
x2=randn(NumTimeSteps,NumPaths);
y2=rho*y1+sqrt(1-rho^2)*x2;
MuStock=log(1+ms)-ss^2/2;
MuBond=log(1+mb)-sb^2/2;
MS=repmat(MuStock,NumTimeSteps,NumPaths);
MB=repmat(MuBond,NumTimeSteps,NumPaths);
rs=exp(MS+ss*sqrt(dt)*y1);
rb=exp(MB+sb*sqrt(dt)*y2);
end
function [PortfolioReturns]=PortfolioReturnsCalculation(Initws,rs,rb,NumTimeSteps,NumPaths)
ws=zeros(NumTimeSteps,1);
wb=zeros(NumTimeSteps,1);
for t=1:NumTimeSteps
ws(t)=Initws-t/100;
wb(t)=1-ws(t);
end
Ws=repmat(ws,1,NumPaths);
Wb=repmat(wb,1,NumPaths);
PortfolioReturns=Ws.*rs+Wb.*rb;
end
function [RetPlan]=CashInflowPattern(InitAssetValue,InflaRate,x,PortfolioReturns,TimetoRetirement,NumPaths)
income=zeros(TimetoRetirement,1);
for t=1:30
income(t)=InitAssetValue*(1+InflaRate)^t;
end
PR1=PortfolioReturns(1:TimetoRetirement,:);
Income=repmat(income,TimetoRetirement,NumPaths);
CashIn=zeros(TimetoRetirement,NumPaths);
CashIn(1,:)=Income(1,:).*PR1(1,:);
for k=2:30
CashIn(k,:)=(CashIn(k-1,:)+Income(k,:)).*PR1(k,:);
end
X=repmat(x,TimetoRetirement,NumPaths);
RetPlan=X.*CashIn;
end
function [RetAcct]=CashOuflowPattern(NumTimeSteps,NumPaths,InitAssetValue,InflaRate,PortfolioReturns,TimetoRetirement,RetPlan)
NumWithdraw=NumTimeSteps-TimetoRetirement;
PR2=PortfolioReturns(TimetoRetirement+1:NumTimeSteps,:);
withdrawal=zeros(NumTimeSteps,1);
for t=TimetoRetirement+1:NumTimeSteps
withdrawal(t)=0.7*InitAssetValue*(1+InflaRate)^(t);
end
Withdrawal=repmat(withdrawal(TimetoRetirement+1:NumTimeSteps,:),1,NumPaths);
RetAcct(1,:)=(RetPlan(TimetoRetirement,:)-Withdrawal(1,:)).*PR2(1,:);
for t=2:TimetoRetirement;
RetAcct(t,:)=(RetAcct(t-1,:)-Withdrawal(t,:)).*PR2(t,:);
end
function [RunOutofMoneyPercentage]=Evolve(ms,ss,mb,sb,rho,Initws,InitAssetValue,InflaRate,x,TimetoRetirement,NumTimeSteps,NumPaths)
[rs,rb]=AssetReturnsSimulation(ms,ss,mb,sb,rho,NumTimeSteps,NumPaths);
[PortfolioReturns]=PortfolioReturnsCalculation(Initws,rs,rb,NumTimeSteps,NumPaths);
[RetPlan]=CashInflowPattern(InitAssetValue,InflaRate,x,PortfolioReturns,TimetoRetirement,NumPaths);
[RetAcct]=CashOuflowPattern(NumTimeSteps,NumPaths,InitAssetValue,InflaRate,PortfolioReturns,TimetoRetirement,RetPlan);
Count=zeros(30,1);
for T=1:30;
Count(T,1)=length(find(RetAcct(T,:)<0));
end
RunOutofMoneyPercentage=max(Count)/length(RetAcct(T,:));
end
function[x]=BisectionAlgorithm(ms,ss,mb,sb,rho,Initws,InitAssetValue,InflaRate,TimetoRetirement,NumTimeSteps,NumPaths,Percentage,Precision)
high=1;
low=0;
x=(high+low)/2;
RunOutofMoneyPercentage=Evolve(ms,ss,mb,sb,rho,Initws,InitAssetValue,InflaRate,x,TimetoRetirement,NumTimeSteps,NumPaths);
while abs(RunOutofMoneyPercentage-Percentage)>Precision
if RunOutofMoneyPercentage>Percentage
low=x;
else high=x;
end
x=(high+low)/2;
RunOutofMoneyPercentage=Evolve(ms,ss,mb,sb,rho,Initws,InitAssetValue,InflaRate,x,TimetoRetirement,NumTimeSteps,NumPaths);
end
end
Command Window:
Percentage=.05;
Precision=.00002;
[x]=BisectionAlgorithm(ms,ss,mb,sb,rho,Initws,Initwb,InitAssetValue,InflaRate,TimetoRetirement,NumTimeSteps,NumPaths,Percentage,Precision)
x =0.4293
Percentage=.01;
[x]=BisectionAlgorithm(ms,ss,mb,sb,rho,Initws,Initwb,InitAssetValue,InflaRate,TimetoRetirement,NumTimeSteps,NumPaths,Percentage,Precision)
x =0.5677 2009/2/20 One period Jump Diffusion Simulationfunction [S,MeanS]=JumpDiffusionStockEvolution(S0,m,s,lda,pup,pdown,NumPaths) S=zeros(1,NumPaths); x=rand(1,NumPaths); y=randn(1,NumPaths); z=rand(1,NumPaths); for t=1:NumPaths if x(t)<=pup S(t)=S0*exp(m+s*y(t))*exp(-log(z(t))/lda); elseif x(t)>=1-pdown S(t)=S0*exp(m+s*y(t))*exp(log(z(t))/lda); else S(t)=S0*exp(m+s*y(t)); end end MeanS=mean(S); end
2009/2/10 A probability density parameters estimation function.function [m,s]=estimateMultModelParams(stockTimeSeries,indexTimeSeries,LookbackPeriod,indexReturn,riskFreeRate) swr=stockTimeSeries(1:LookbackPeriod)./stockTimeSeries(2:LookbackPeriod+1)-1; iwr=indexTimeSeries(1:LookbackPeriod)./indexTimeSeries(2:LookbackPeriod+1)-1; covmatx=cov(swr,iwr); beta=covmatx(1,2)/covmatx(2,2); fcastR=riskFreeRate/LookbackPeriod+beta*(indexReturn/LookbackPeriod-riskFreeRate/LookbackPeriod); s=std(log(stockTimeSeries(1:LookbackPeriod)./stockTimeSeries(2:LookbackPeriod+1))); m=log(1+fcastR)-s^2/2; end
If you define and input data into those variables, you can use it to estimate the probability density of a function of a variable subjected to normal distribution, with a mean of m, and a standard deviation of s. Here is an example: >>x=-4:.1:4; >>m=.06; >>s=.02; >>T=5; >>By=1./(1+(m+s*x)/2).^(2*T);
>>Plot(By, (1/(s*T))*normpdf(x)./(By.^(1+1/(2*T)))), title(‘bond price distribution with a yield subject to normal distribution.’)
2009/2/8 A bewildered soul.On this blade,on my name,both true and given,an on all the good and evil i have done in life,i commit all the days that remain to me,for better or for worse,to Tyr and to his justice.Let it be so!----Aribeth de Tylmarande. the tale of Neverwinter Night is end. 2009/1/14 重返MSN曾几何时,这个Space见证了我生活中的一点一滴,每一个变化,每一个进步。 但在过去的大半年里,我却一点提不起兴趣在这里留下自己的痕迹,其中固然有学习生活的繁忙,但自己心里知道,惰性和不知从何而起的失落感才是自我封闭的罪魁祸首。
突然想起半年前对自己的一句话,人生的目标没有终点。充实的人生是从克服难关,达成自己一个又一个夙愿的土壤中吸取养分的。
人生总有失落和迷茫,这是必然的。但我希望我总能在片刻的滞留之后找到新的曙光。
有时候,一个新的态度和生活方式能给人带来意想不到的收获。
It's time to scrumb away the layer of confusion and contradiction.
J |
|
||
|
|