Portfolio
OptiMax Sample of Stock Portfolio Application
TITLE
Portfolio;
OPTIONS
ModelType=Quadratic
NAMED INDEX
month := DATAFILE("StockPrice.dat", start=1, end=2) : 5
period[month] := month - (First(month));
INDEX
stock := DATAFILE("StockPrice.dat", column=1, start=2); ! First column contains stock symbol
stock2 := stock;
DATA
MinInvest := 0;
MaxInvest := 1;
MinStocks := 5;
MaxStocks := 10;
TargetReturn := 5.0;
Price[stock,month] := DATAFILE("StockPrice.dat", start=2); ! Price data per stock and month
DATA
Return[period, stock] := FORMULA(100*((Price[month:=period] / Price[month:=period-1]) - 1));
MeanReturn[stock] := 1/Count(period) * SUM(period: Return);
Deviation[period,stock] := Return - MeanReturn;
Covariance[stock,stock2] := 1/(Count(period)-1) * SUM(period: Deviation * Deviation[stock:=stock2]);
VARIABLES
Invest[stock];
MACROS
Variance := SUM(stock,stock2: Invest * Covariance * Invest[stock:=stock2]);
Target := TargetReturn;
MODEL
MIN Risk = Variance;
SUBJECT TO
TotalInvestment:
SUM(stock: Invest) = 100%;
MeetTarget:
SUM(stock: MeanReturn * Invest) >= TargetReturn;
BOUNDS
MinInvest <= Invest[stock] <= MaxInvest;
END