MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Extract values from optimized solution

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[{([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!


  • Prev by Date: Re: Improt vs Get
  • Next by Date: Re: Oblique coordinates from cartesian coordinates
  • Previous by thread: Re: can't Solve[1 - x == x^r, x]?
  • Next by thread: Why does Solve give me no solutions for this in Version 8.0.1?