A collection of computational-finance scripts: MATLAB scripts for portfolio optimization, yield-curve bootstrapping, and optimal trade execution, plus R scripts for Monte Carlo simulation and sampling methods.
| Script | Description |
|---|---|
Markowitz.m |
Mean-variance portfolio optimization on a 10-stock universe: plots the efficient frontier, the global minimum-variance portfolio, the tangency portfolio (capital market line), and constrained frontiers (no short selling; sector-weight bounds) solved via quadprog. |
yieldCurve.m |
Bootstraps a zero-coupon yield curve from five semi-annual coupon bonds (maturities 1, 2, 3, 5, 10 years), then computes yield-to-maturity, Macaulay duration, and duration for each bond, and plots the curve. |
f.m |
Helper for yieldCurve.m: prices a coupon bond with previously bootstrapped yields, leaving the last segment's yield as the unknown (root-found with fzero). |
g.m |
Helper for yieldCurve.m: bond price minus market price as a function of a single flat yield, used to solve for yield-to-maturity. |
almgren_chriss.m |
Monte Carlo simulation of optimal liquidation under the Almgren-Chriss model, comparing terminal-wealth mean/std frontiers for constant vs. stochastic (mean-reverting) temporary price impact across risk-aversion levels. |
getMarketData.m |
Downloads historical market data from Yahoo Finance (fork of Artem Lenskiy's downloader). Used by Markowitz.m to fetch prices. Note: the Yahoo endpoint it targets has changed over the years and may require updating. |
Open MATLAB in the repository root and run any script, e.g.:
yieldCurve
almgren_chriss
Markowitz % needs price data; see get_prices() inside the scriptRequirements: yieldCurve.m uses the Symbolic Math Toolbox (syms,
symsum); Markowitz.m uses the Optimization Toolbox (optimvar,
quadprog). Scripts relying on those toolboxes will not run in stock GNU
Octave; the others (almgren_chriss.m) are Octave-compatible.
| Script | Description |
|---|---|
Monte Carlo/european_call.R |
Prices a European call under Black-Scholes dynamics by Monte Carlo with antithetic variates; reports the price estimate with a 95% confidence interval. |
Monte Carlo/areas.R |
Monte Carlo integration of 1, x, x², sin(x), exp(x) on [0, 1], showing estimator convergence as the sample count grows. |
Monte Carlo/multivariate_area.R |
Monte Carlo integration of exp((x + y)²) over the unit square. |
Monte Carlo/order_statistics.R |
Samples order statistics (min/max of uniforms, min of exponentials) via inverse-CDF formulas and validates against empirical simulation. |
Monte Carlo/poisson_sampling.R |
Generates Poisson samples from exponential inter-arrival times and compares mean/variance against R's rpois. |
Monte Carlo/rejection_sampling.R |
Rejection sampling from f(x) = 2(1 − x) on [0, 1] using a uniform proposal. |
Monte Carlo/stickToTriangle.R |
Estimates the probability that a stick broken at two uniform points forms a triangle (analytic answer: 1/4). |
Rscript "Monte Carlo/european_call.R"No external R packages required (base R only).