Python for Finance: Analyze Big Financial Data

(Elle) #1
In  [ 62 ]: output  =   True
opt2 = spo.fmin(fo, opt1, xtol=0.001, ftol=0.001, maxiter= 15 , maxfun= 20 )
opt2
Out[62]: -1.4000 -1.4000 -1.7749
-1.4700 -1.4000 -1.7743
-1.4000 -1.4700 -1.7743
-1.3300 -1.4700 -1.7696
-1.4350 -1.4175 -1.7756
-1.4350 -1.3475 -1.7722
-1.4088 -1.4394 -1.7755
-1.4438 -1.4569 -1.7751
-1.4328 -1.4427 -1.7756
-1.4591 -1.4208 -1.7752
-1.4213 -1.4347 -1.7757
-1.4235 -1.4096 -1.7755
-1.4305 -1.4344 -1.7757
-1.4168 -1.4516 -1.7753
-1.4305 -1.4260 -1.7757
-1.4396 -1.4257 -1.7756
-1.4259 -1.4325 -1.7757
-1.4259 -1.4241 -1.7757
-1.4304 -1.4177 -1.7757
-1.4270 -1.4288 -1.7757
Warning: Maximum number of function evaluations has been exceeded.

                                    array([-1.42702972, -1.42876755])

Again, we can observe a refinement of the solution and a somewhat lower function value:


In  [ 63 ]: fm(opt2)
Out[63]: -1.7757246992239009

For many convex optimization problems it is advisable to have a global minimization


before the local one. The major reason for this is that local convex optimization algorithms


can easily be trapped in a local minimum (or do “basin hopping”), ignoring completely


“better” local minima and/or a global minimum. The following shows that setting the


starting parameterization to x = y = 2 gives a “minimum” value of above zero:


In  [ 64 ]: output  =   False
spo.fmin(fo, (2.0, 2.0), maxiter= 250 )
Out[64]: Optimization terminated successfully.
Current function value: 0.015826
Iterations: 46
Function evaluations: 86

                                    array([ 4.2710728   ,       4.27106945])

Constrained Optimization


So far, we have only considered unconstrained optimization problems. However, large


classes of economic or financial optimization problems are constrained by one or multiple


constraints. Such constraints can formally take on the form of equations or inequalities.


As a simple example, consider the utility maximization problem of an (expected utility


maximizing) investor who can invest in two risky securities. Both securities cost qa = qb =


10 today. After one year, they have a payoff of 15 USD and 5 USD, respectively, in state


u, and of 5 USD and 12 USD, respectively, in state d. Both states are equally likely.


Denote the vector payoffs for the two securities by ra and rb, respectively.


The investor has a budget of w 0 = 100 USD to invest and derives utility from future wealth


according to the utility function , where w is the wealth (USD amount)


available. Equation 9-2 is a formulation of the maximization problem where a,b are the


numbers of securities bought by the investor.

Free download pdf