Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Extracting values from optimized result' topicStudent Support Forum > General > Archives > "Extracting values from optimized result"

Help | Reply To Topic
Author Comment/Response
Johan
06/29/11 8:13pm

I'm running a simple mean variance optimization, but I'm ripping my hair out from small "easy" things that I can't get to work properly. I've gone through references and similar posts online, but it must be simpler solutions than what I've found.

(1) We import data from a text file, and store this in matrices. (This works fine)
(2) We run an min optimization. (Have done something wrong here, since the returned values are integers? And should be doubles..)
(3) Take the output, and store it in a matrix. Right now the total output is stored. I've tried different solution, but they require a lot of manual work. I'm sure it must be some way to simply store the output values for each the x-variables in an 6*1 matrix?
(4) We export the result to a file. My problem here is that it's only the last output that is exported - how can I have it continue on an existing file rather than replacing the data?

My code is the following:

f = Import[
"C:\\Users\\System Investors\\Desktop\\PortfolioModel \
Mathematica\\Inputs.txt", "Table"]

For[i = 1, i <= 170,
i++, {return[i] = f[[i, 1 ;; 6]],
omega[i] = Partition[f[[i, 6 ;; 42]], 6]}]

weights = {x1, x2, x3, x4, x5, x6}

For[i = 1, i <= 170,
i++, {output[i] =
NMinimize[{(weights.omega[i].weights)[[1, 1]], Total@weights == 1,
Thread[weights >= 0]}, weights],
Export["C:\\Users\\System Investors\\Desktop\\PortfolioModel \
Mathematica\\out.txt", output[i], "String"]}]

I hope someone can give me some hints!

Thank,
Johan

URL: ,
Help | Reply To Topic