Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3406

Extract values from optimized solution

From SysInv <johan@systeminvestors.se>
Newsgroups comp.soft-sys.math.mathematica
Subject Extract values from optimized solution
Date 2011-06-30 20:55 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <iuinso$kur$1@smc.vnet.net> (permalink)

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Extract values from optimized solution SysInv <johan@systeminvestors.se> - 2011-06-30 20:55 +0000

csiph-web