Download LINDO API USER MANUAL
Transcript
SOLVING QUADRATIC PROGRAMS
Q(i,j): covariance between the returns of i^th and
j^th assets.
K
: a scalar denoting the level of risk of loss.
w(i) : proportion of total budget invested on asset i
Covariance Matrix:
w1
w2
w1 [ 1.00 0.64
w2 [ 0.64 1.00
w3 [ 0.27 0.13
w4 [ 0.
0.
w3
0.27
0.13
1.00
0.
w4
0.
0.
0.
1.00
]
]
]
]
Returns Vector:
w1
w2
w3
r =
[ 0.30 0.20 -0.40
w4
0.20
]
Risk of Loss Factor:
K = 0.4
*/
#include
#include
#include
#include
<stdlib.h>
<stdio.h>
<string.h>
"lindo.h"
/* Define a macro to declare variables for
error checking */
#define APIERRORSETUP
int nErrorCode;
char cErrorMessage[LS_MAX_ERROR_MESSAGE_LENGTH]
/* Define a macro to do our error checking */
#define APIERRORCHECK
if (nErrorCode)
{
if ( pEnv)
{
LSgetErrorMessage( pEnv, nErrorCode,
cErrorMessage);
printf("Errorcode=%d: %s\n", nErrorCode,
cErrorMessage);
} else {
printf( "Fatal Error\n");
}
exit(1);
}
/* main entry point */
int main(int argc, char **argv)
{
APIERRORSETUP;
int nM = 2;
/* Number of constraints */
int nN = 4;
/* Number of assets */
double K = 0.20; /* 1/2 of the risk level*/
393