A Computer Program about Markowitz Portfolio Selection, Second Edition

Jsun Yui Wong

The computer program listed below seeks to solve the small example about Markowitz portfolio selection [3] on pp. 888-890 of Li and Tsai [2].

Minimize .0108 * X(1) ^ 2 + .0584 * X(2) ^ 2 + .0942 * X(3) ^ 2 + .0248 * X(1) * X(2) + .0262 * X(1) * X(3) + .1108 * X(2) * X(3)

subject to 1.089 * X(1) + 1.214 * X(2) + 1.235 * X(3) >= 115

X(1) + X(2) + X(3) = 100

where X(1), X(2), and X(3) are integers.

Below X(1) through X(3) are integer variables, and X(4) is a slack variable.

Whereas line 128 of the earlier edition is 128 FOR I = 1 TO 10000, here line 128 is 128 FOR I = 1 TO 8000.

0 REM DEFDBL A-Z

2 DEFINT I, J, K

3 DIM B(99), N(99), A(99), H(99), L(99), U(99), X(1111), D(111), P(111), PS(33)

12 FOR JJJJ = -32000 TO 32000

14 RANDOMIZE JJJJ

16 M = -1D+37

64 FOR J44 = 1 TO 3

65 A(J44) = RND * 10

66 NEXT J44

126 REM IMAR=10+FIX(RND*32000)

128 FOR I = 1 TO 8000

129 FOR KKQQ = 1 TO 3

130 X(KKQQ) = A(KKQQ)

131 NEXT KKQQ

133 FOR IPP = 1 TO (1 + FIX(RND * 2))

181 J = 1 + FIX(RND * 3)

183 R = (1 - RND * 2) * A(J)

187 X(J) = A(J) + (RND ^ (RND * 10)) * R

222 NEXT IPP

223 X(1) = 100 - X(2) - X(3)

224 FOR J33 = 1 TO 3

226 X(J33) = INT(X(J33))

227 NEXT J33

229 REM X(5) = 1

233 X(4) = -115 + 1.089 * X(1) + 1.214 * X(2) + 1.235 * X(3)

281 FOR J44 = 1 TO 3

283 IF X(J44) < 0 THEN 1670

284 IF X(J44) > 100 THEN 1670

285 NEXT J44

331 FOR J44 = 4 TO 4

332 IF X(J44) < 0 THEN PS(J44) = ABS(X(J44)) ELSE PS(J44) = 0

333 NEXT J44

403 POBA2 = -(.0108 * X(1) ^ 2 + .0584 * X(2) ^ 2 + .0942 * X(3) ^ 2 + .0248 * X(1) * X(2) + .0262 * X(1) * X(3) + .1108 * X(2) * X(3))

411 POBA = POBA2 - 1000000 * (PS(4))

459 POB1 = POBA

463 P1NEWMAY = POB1

466 P = P1NEWMAY

1111 IF P <= M THEN 1670

1452 M = P

1453 PPOBA2 = POBA2

1454 FOR KLX = 1 TO 11

1455 A(KLX) = X(KLX)

1456 NEXT KLX

1557 GOTO 128

1670 NEXT I

1889 IF M < -224.647 THEN 1999

1900 PRINT A(1), A(2), A(3), A(4)

1904 PRINT M, JJJJ, PPOBA2

1999 NEXT JJJJ

This BASIC computer program was run with qb64v1000-win [5]. The complete output through JJJJ=-16563 is shown below:

53 35 12 .027

-224.6452 -29251 -224.6452

53 36 11 .006

-223.8916 -19156 -223.8916

53 35 12 .027

-224.6452 -18228 -224.6452

53 36 11 .006

-223.8916 -16563 -223.8916

Above there is no rounding by hand; it is just straight copying by hand from the monitor screen.

On a personal computer with a Pentium Dual-Core CPU E5200 @2.50GHz, 2.50 GHz, 960 MB of RAM and qb64v1000-win [5], the wall-clock time for obtaining the output through JJJJ=-16563 was 3 minutes and 20 seconds.

**Acknowledgment**

I would like to acknowledge the encouragement of Roberta Clark and Tom Clark.

References

[1] Yuichiro Anzai (1974). On Integer Fractional Programming. *Journal Operations Research Society of Japan*, Volume 17, No. 1, March 1974, pp. 49-66.

www..orsj.or.jp/~archiv/pdf/e_mag/Vol.17_01_049.pdf.

[2] Han-Lin Li, Jung-Fa Tsai (2008). A distributed computational algorithm for solving portfolio problems with integer variables.* European Journal of Operational Research* 186 (2008) pp.882-891.

[3] Harry Markowitz (1952). Portfolio Selection*. The Journal of Finance* 7 (2008) pp. 77-91.

[4] Microsoft Corp., *BASIC*, Second Edition (May 1982), Version 1.10. Boca Raton, Florida: IBM Corp., Personal Computer, P. O. Box 1328-C, Boca Raton, Florida 33432, 1981.

[5] Wikipedia, QB64, https://en.wikipedia.org/wiki/QB64.

[6] Jsun Yui Wong (2012, April 12). The Domino Method of General Integer Nonlinear Programming Applied to a Nonlinear Fractional Programming Problem from the Literature. http://myblogsubstance.typepad.com/substance/2012/04/12/