// exact DP - infinite - VI clc clear ////// Variables ////// // n - number of states // Niter - number of iterations // J - n x Niter matrix, J(i,t) is the cost function starting from i after t steps of VI // Q - vector of dimension n, Q(i) is short for Q(HOLD, i) // price_list - 1 x n vector, price_list(i) is the stock price associated with state i ////// Parameters ////// K = 1; // Strike Price S = 1; // Initial Price p = 0.4; // Probability of Moving Up u = 1+1e-3; // Growth Rate d = 2-u; // Diminish Rate Niter = 1000; // Number of iterations n = 10; // Number of States alpha = 0.95; // Discount Factor //// Initialization //// // Initialize All Possible States price_list = S*[d.^((n/2-1):-1:0), u.^(1:(n/2))]; // Initialize J and Q J = zeros(n,Niter); Q = zeros(n,1); //// VI //// for t = 2 : Niter for i = 1 : n //////// Find Q-values by using J(:,t-1) //////// Write here: ////////// Update J(i,t) by using new Q values //////// Write here: end end figure(1); plot(price_list, J); plot(price_list, J(:,Niter),'*'); title('Convergence of Value Functions (Dotted line: J^*)'); xlabel('Stock Price'); ylabel('Option Price (Value Fucntion)'); figure(2); plot(price_list,Q,'-*'); plot(price_list,price_list-K); title('Q Values and Optimal Strategy)'); xlabel('Stock Price'); ylabel('Q Value'); legend('Q Values of the control HOLD','Q Values of the control EXERCISE')