Documentation 
Monte Carlo simulation of correlated asset returns
RetSeries = portsim(ExpReturn, ExpCovariance, NumObs, RetIntervals,
NumSim, Method)
ExpReturn  1 by number of assets (NASSETS) vector specifying the expected (mean) return of each asset. 
ExpCovariance  NASSETSbyNASSETS matrix of asset return covariances. ExpCovariance must be symmetric and positive semidefinite (no negative eigenvalues). The standard deviations of the returns are ExpSigma = sqrt(diag(ExpCovariance)). 
NumObs  Positive scalar integer indicating the number of consecutive observations in the return time series. If NumObs is entered as the empty matrix [], the length of RetIntervals is used. 
RetIntervals  (Optional) Positive scalar or number of observations (NUMOBS)by1 vector of interval times between observations. If RetIntervals is not specified, all intervals are assumed to have length 1. 
NumSim  (Optional) Positive scalar integer indicating the number of simulated sample paths (realizations) of NUMOBS observations. Default = 1 (single realization of NUMOBS correlated asset returns). 
Method  (Optional) String indicating the type of Monte Carlo simulation: 'Exact' (default) generates correlated asset returns in which the sample mean and covariance match the input mean (ExpReturn) and covariance (ExpCovariance) specifications. 'Expected' generates correlated asset returns in which the sample mean and covariance are statistically equal to the input mean and covariance specifications. (The expected value of the sample mean and covariance are equal to the input mean (ExpReturn) and covariance (ExpCovariance) specifications.) For either method the sample mean and covariance returned are appropriately scaled by RetIntervals. 
portsim simulates correlated returns of NASSETS assets over NUMOBS consecutive observation intervals. Asset returns are simulated as the proportional increments of constant drift, constant volatility stochastic processes, thereby approximating continuoustime geometric Brownian motion.
RetSeries is a NUMOBSbyNASSETSbyNUMSIM threedimensional array of correlated, normally distributed, proportional asset returns. Asset returns over an interval of length dt are given by
$$\frac{dS}{S}=\mu dt+\sigma dz=\mu dt+\sigma \epsilon \sqrt{dt},$$
where S is the asset price, μ is the expected rate of return, σ is the volatility of the asset price, and ε represents a random drawing from a standardized normal distribution.
Notes
