Computational Pressure can be Reduced by Applying Math for Simulating Stock Price
Computers now are much faster than 10 years before. But, with a little bit of some math problems, new computers still have to work very hard.
I recently built a tool that models stock price movement, SPY ETF to be precise with the following steps:
- I first obtained the stock daily closing price adjusted for dividend payout from Yahoo Finance scv file, then converted to daily returns.
- With an array of SPY daily returns, I calculated the mean and standard deviation.
- Finally I could model SPY price movement based on the geometric Brownaian motion that stock price may follow.
- The model app is here, feel free to try.
Here is the problem
After building the above mentinoed modeling tool, I went ahead and built another tool that can model if we would spend all our retirement money if we sell 4%, each year, of our SPY-only portfolio.
I thought, instead of grabing yearly closing prices of SPY from Yahoo Finance again, I could just use the daily returns for modeling.
Now, the problem is, the assumnption is we sell at the end of each year, so my model has to run 252 times before we sell once, assuming there are 252 trading days every year.
If we model for 10 years, our computer has to run 2,520 calculations, instead of just 10 times if we just used yearly return data.
Problem Solved with Math
Since the we assume SPY price movement follow the geometric Brownian motion, then SPY returns follow arithmetic Brownian motion.
And, 2 normal random variables from a same distribution with mean x and standard deviation y, would make up a nomal distribution with mean 2x and standard deviation square root of 252 times y.
Therefore, SPY mean yearly return can be otained by multiplying mean daily return by 252 and yearly return standard deviation can be otained by multiplying daily return standard deviation by square root of 252.
Now, with SPY mean yearly return and yearly return standard deviation, I could improve my model which is 252 times faster. The tool is here.
Before improving my model, I could here my computer fan spinning. Now I don't.
Comments
Post a Comment