Feedback on Week 9 Homework: Numerical Approximation & Simulation
Feedback on Week 9 Homework: Numerical Approximation & Simulation
Student: Lorenzo Ilari Assignment: Week 9 - Monte Carlo OLS & Numerical Integration
Overall Assessment
Grade: ✅ (Pass)
Your submission is good and covers most of the requirements. The Monte Carlo simulation part is well-executed. In the numerical integration part, there is a technical issue with the implementation of Simpson’s rule regarding the number of grid points, and the convergence plot is missing.
Task-by-Task Check
Part 1: Monte Carlo OLS
- Function Definition: ✅
montecarlo_olsis correctly defined. - DGP Logic: ✅ Correct generation of random variables inside the replication loop.
- OLS Logic: ✅
regressis used correctly. - Execution: ✅ Loops over sample sizes correctly.
- Visuals: ✅ Histograms with normal fits are generated correctly.
- Statistics: ✅ Empirical mean and variance are calculated and printed.
- Interpretation: ✅ (Implicit in the printed results).
Part 2: Numerical Integration
- Utility Function: ✅ CRRA utility correctly defined.
- Trapezoidal Rule: ✅ Correctly implemented using
trapz. - Simpson’s Rule: ⚠️ Parity Issue. Simpson’s 1/3 rule requires an odd number of grid points (which corresponds to an even number of intervals). You used $N \in {50, 200, 1000}$, which are even. Your formula
(h/3) * (uc(1) + 4*sum(...) + 2*sum(...) + uc(end))implicitly skips the second-to-last point (index $N-1$) when $N$ is even, leading to an incorrect calculation. - Grid Loop: ✅ Integration performed over grid sizes.
- Visuals: ⚠️ Missing Convergence Plot. You plotted the utility function $u(c)$ itself, but the assignment asked for a plot of the integral value (or error) vs. $N$ to visualize convergence.
- Interpretation: ✅ (Implicit in results table).
Technical Implementation
- Code Organization: Clean and logical.
- Simpson’s Rule: To fix the parity issue, you should either choose odd $N$ (e.g., 51, 201) or add a check to remove the last point if $N$ is even (e.g.,
if mod(N,2)==0, N=N-1; end).
Style & Clarity
- Output: Results are displayed clearly in the command window.
- Comments: Code is readable.
Suggestions for Improvement
- Check Assumptions: When using numerical formulas like Simpson’s rule, always verify the requirements (like odd/even points) against your input parameters.
- Visualizing Results: Plotting the final results (the integrals) against the parameter ($N$) provides more insight into the method’s performance than plotting the function itself.
Summary
You have a solid handle on the simulation and basic integration logic. Paying closer attention to the specific constraints of numerical algorithms (like Simpson’s rule parity) will improve the accuracy of your work.
Tasks Correct: 11/13