PART 5 DYNAMIC PROGRAMMING 13
Shortest paths in directed graphs Directed graph Tuple G= (V,A), where V is finite set of nodes and A V V is set of arcs (also called edges); arc from u to v is denoted by uv c : A R weights on arcs Path is sequence P= v,v 1,...,v k of nodes such that v i 1 v i A for i=1,...,k. Length of path c(p)= k i=1 c(v i 1v i ) Path v,v 1,...,v k with v = v k is called cycle Shortest path problem Let s V. Determine for each v V a shortest path from s to v. 131
Bellman s Equations Suppose G does not contain cycle of negative length Let l(v) be length of shortest path from s to v (possibly ) Clearly l(s) = (no neg. cycles!) For uv A one has l(v) l(u)+c(uv) If v s, there must be a node u on shortest path from s to v immediately preceding v. For this u one has l(v)=l(u)+c(uv) (principle of optimality) The shortest path distances l(v) satisfy Bellman s equations x s =, x v = min{x u + c(uv): uv A}, v V. 132
Sufficiency Theorem: If G does not contain cycles of length and if one has a path from s to each other node v, then there is unique solution to Bellman s equations, where x u = l(u) for each u V. 133
Proof Let x be solution to Bellman s equations Let v V, v s. There exists uv A with x v = x u + c(uv). Likewise, there exists w V with x u = x w + c(wu). If, repeating, this process, we come back to v again, we have found a cycle of length which is excluded Consequently, we arrive at s and we have constructed a path P= (s=v,v 1,...,v k = v) with x v = c(p)+x s = c(p). This shows x v l(v). Suppose x l. Then there exists node v with x v > l(v) such that the node u preceding v on shortest path from s to v has x u = l(u). Bellman s equations imply x v x u + c(uv)=l(u)+c(uv)=l(v) 134
Acyclic Graphs G = (V, A) is acyclic if G does not contain cycles In this case, G has an ordering < of nodes, such that uv A implies u<v (depth first search) Assume nodes are set {1,...,n}. Bellman s equations acyclic graphs x 1 = x j = min k<j (x k + c kj ) j=2,3,...,n. Easily solved by substitution x 2 is determined from x 1, x 3 determined from x 1 and x 2 etc. Running time: O( A + V ) 135
Bellman-Ford algorithm Bellman-Ford algorithm x j v length of shortest path from s to v using at most j arcs Initialization: x 1 s =, x1 v = { c(sv) for i=2,...,n for v V Running time x i v = min{xi 1 v Iterations outer loop: V if sv A otherwise.,min uv A {xu i 1+ c(uv)}} Each arc is considered exactly once in inner loop: O( A ) Complexity: O( V A ). 136
Negative cycles If network does not contain negative cycles and v is reachable from s, then a shortest path uses at most n 1 arcs. Bellman-Ford is correct if no negative cycles are present. Exercise Design a polynomial-time algorithm which detects whether G = (V, A) together with arc-weights c has a negative cycle. 137
Dynamic programming A capital budgeting problem 4 million to be invested in projects in three different regions At most one project can be run in each region Region 1 Region 2 Region 3 Project cost/profit cost/profit cost/profit 1 / / / 2 1/2 1/3 1/2 3 2/4 3/9 2/5 4 4/1 - - Enumeration 4 3 3 possibilities 138
Integer program x ij = 1 if project i is run in region j max ij p ij x ij i x ij 1, j= 1,...,3 ij c ij x ij 4 x ij {,1}. 139
Dynamic program States (i, j) represents optimal choice for first i {, 1, 2, 3} regions having still j {, 1, 2, 3, 4} mio. left to invest. Construct graph with nodes being states and arcs from stages (i,j) to (i+ 1,j ) having cost p if the investment of j j reflects an implementation of a project of cost j j and profit p in region i+ 1 Longest path in this directed acyclic graph is optimal strategy Number of states: 4 5 If we had x N regions with at least two possible projects per region and an amount of y N to invest, where each project would have integral costs, one would have (x + 1) (y + 1) states, whereas enumeration would require at least 2 x decisions to be compared. 14
Example cont. (,4) (1,4) (1,3) (1,2) (1,1) (1,) (2,4) (2,3) (2,2) (2,1) (2,) (3,4) (3,3) (3,2) (3,1) (3,) 2 4 1 3 9 3 9 3 2 5 2 5 2 5 2 2 4 1 3 5 9 11 3 5 9 11 141
Forward and backward recursion Forward recursion: Label each state which is reachable from starting state with the longest path distance from starting state using profits as edge costs. Process starts from starting node Backward recursion: Label each state with largest profit that can be collected from this state. 142
The Knapsack Problem Knapsack n items of weight w i N and profit p i N, i=1,...,n Knapsack of capacity K N Task: Compute subset of items which still fit into knapsack and maximizes the profit Integer Program max n i=1 p ix i n i=1 w ix i K x i {,1}. 143
Dynamic program for Knapsack W i (p) least possible weight that has to be accumulated in order to have total profit p using only items from {1,...,i} W i+1 (p)=min{w i (p),w i (p p i+1 )+w i+1 } States: {(i,p): i {1,...,n}, p {,...,n p max }}, where p max = max{p i : i=1,...,n}. There is an edge from (i,p) to (i+ 1,p) of weight and there is an edge from (i,p) to (i+ 1,p+p i+1 ) of weight w i+1. Compute shortest path distances from (,) to all nodes in directed graph Number of nodes: p max n 2 Number of arcs: 2 p max n 2 Theorem The knapsack problem can be solved in time O(n 2 p max ). 144
Alternative dynamic program P i (w): Maximum profit which can be accumulated choosing items out of {1,..., i} having total weight w. P i+1 (w)=max{p i (w),p i (w w i+1 )+p i+1 } States: {(i,w): i {1,...,n}, w {,...,K }} There is an edge from (i,w) to (i+ 1,w) of weight and an edge from (i,w) to (i+ 1,w+ w i+1 ) of weight p i+1. Number of states: n K Number of arcs: 2 n K Find longest paths from (,) to other states Running time: O(n K) 145
Approximation algorithm ε-approximation algorithm Let ε> be a number The algorithm A computes an ε-approximation to the knapsack problem, if it computes a feasible solution x ε with p T x ε (1 ε)p T x OPT, where x OPT is an optimal solution of the Knapsack problem A is fully polynomial time approximation scheme if the running time of A is polynomial in n and 1/ε. 146
Designing A Set last t bits of each p i to obtaining profits p i Let x {,1} n be feasible knapsack solution. Clearly p T x p T x p T x n 2 t Let x 1,x 2 be opt. sol w.r.t. p and p respectively One has p T x 1 p T x 2 p T x 2 p T x 1 p T x 1 n 2 t from which we conclude p T x 1 p T x 2 n 2 t We want (p T x 1 p T x 2 )/p T x 1 ε We have (p T x 1 p T x 2 )/p T x 1 n 2 t /p max If n/p max > ε solve problem with exact algorithm which takes time O(n 2 p max )=O(n 3 /ε). Else find t with ε/2< n 2 t /p max ε Apply algorithm to instance defined by p=p/2 t. p max 2 t p max < 2 n 2t ε 2 t = 2 n/ε. Running time: O(n 2 p max )=O(n 3 /ε) 147
Fully polynomial time approximation scheme for Knapsack Theorem There exists an algorithm which, given a knapsack instance and ε> computes a feasible solution x with OPT(1 ε) p T x Where OPT denotes the value of an optimal solution. The running time of the algorithm is O(n 3 /ε). 148
PART 5.1 OPTION PRICING 149
American call options Gives the holder right to purchase underlying security for prescribed amount strike price Valid until certain expiration date Pricing derivative security S current price of underlying security Two possible outcomes up and down at time 1: S u 1 = S u S d 1 = S d How to price the derivative security? 15
Replication Consider portfolio of shares of the underlying and B cash Up-state: S u+b R, (R is risk-less interest rate) Down-state: S d+ B R For what values of and B will portfolio have same payoff C1 u and C1 d of derivate? S u+b R = C1 u S d+ B R = C1 d One obtains = Cu 1 Cd 1 S (u d) B= ucd 1 dcu 1 R(u d) 151
Since portfolio is worth S +B today, this should also be price for derivate security C = Cu 1 Cd 1 u d + ucd 1 dcu 1 R(u d) = 1 [ R d R u d Cu 1 + u R ] u d Cd 1 Risk-neutral probabilities p u = R d u d, p d = u R u d Remark There is arbitrage opportunity if u>r>d is not satisfied. Consequently p u,p d > and since p u + p d = 1 one can interpret p u and p d as probabilities. 152
n time steps Basic period length (day or week... ) Price of asset in period being S there is the up event (price us) with probability p and down event (price ds) with probability 1 p Starting from price S in period, in period k it is u j d k j S if there are j up- and k j down moves. Probability is ( k j) p j (1 p) k j (binomial distribution). 153
n time steps Determining u, d and p S k : Price in periods k=,...,n Assume to know : Mean value µ and volatility σ of ln(s n /S ) Let =1/n be length between two consecutive periods Mean and volatility of ln(s 1 /S ) are µ and σ respectively Direct computation yields µ =p lnu+(1 p)ln d and σ 2 =p (1 p)(ln u lnd) 2. Set d= 1/u then equations simplify µ = (2p 1)ln u σ 2 = 4p(1 p)(ln u) 2 Squaring first and adding it to second equation yields (ln u) 2 = σ 2 +(µ ) 2. 154
Determining u, d and p cont. u = e σ 2 +(µ ) 2 d = e σ 2 +(µ ) 2 ( ) p = 1 1 1+ 2 1+(σ 2 /µ 2 ) For small this is approximately u = e σ d = e σ p = 1 ( 1+ µ ) 2 σ 155
Example 52 periods S known and random price S 52 with mean and standard deviation of ln(s 52 /S ) being 1% and 3% respectively. Since =1/52 is small one has u=e.3/ 52 = 1.425, d=.9592 and p=1/2+(1+.1.3 52 ) 156
Dynamic program to determine value of option Suppose strike price is c Work backwards from time N to time Nodes at time N are terminal nodes Option value v(j,n) of terminal nodes at height j is max{u j d N j S c,} Compute v(k,j) from v(k+ 1,j) and v(k+ 1,j+ 1) using formula with risk-neutral probabilities p u = R d u d, p d = u R u d : { } 1 v(k,j)= max R (p uv(k+ 1,j+ 1)+p d v(k+ 1,j)),u j d k j S c Output v(, ) 157
Example Stock with Volatility of logarithm σ=.2 Current price is 62 What is price of American call option with expiration date in 5 months from now? Strike price c is 6 Rate of interest is 1% compounded monthly Compute values =1/12, u=1.5943, d=.9439, R=1+.1/12= 1.833 p u =.5577 Fill table entries at the end of period. Example (upper right): S u 5 c= 22.75 158
Example cont. 62 5.85 65.68 8.21 58.52 2.97 69.59 11.19 62 4.61 55.24.96 73.72 14.71 65.68 6.96 58.52 1.74 52.14 78.11 18.6 69.59 1.8 62 3.14 55.24 49.21 82.75 22.75 73.72 13.72 65.68 5.68 58.52 52.14 46.45 159