I created a Linear Programming model as follows:
require(lpSolveAPI)
% defining data
liab<--c(100,500,200,400,210,-600,100,900,500,400,600,810,100)
num_times<-length(liab)
% details the rates of interest
money <- 0.5/100;
shorttermrate <- 0.9/100;
creditgrate <- 1/100;
transactionrate <- 0.2/100;
bondvalue <- 200;
num_constraints = num_times;
% defining the no of variables
num_vars <- num_times-6;
num_vars <- num_vars + num_times-6;
num_vars <- num_vars + num_times-1;
num_vars <- num_vars + num_times-1;
num_vars <- num_vars + num_times-6;
num_vars <- num_vars + num_times-1;
vec1 <- c(2,3,4,5,6)
% create an LP model with num_constraints constraints and % num_vars variables
lpmodel<-make.lp(num_constraints,num_vars)
% This is where I find an issue:
% I am struggling to understand how to access elements within lpmodel
. I get the error `Error in
% lpmodel[t, column - (ntimes - 1) + t - 1] : object of type 'externalptr' is not subsettable
for (t in c(1:(num_times-6))){
if (t==1)
set.column(lpmodel,column+t,c(bondvalue), indices=c(t))
else
set.column(lpmodel,column+t,c((shorttermrate)*lpmodel[t-1,column]), indices=c(t)) % Issue associated with trying to access lpmodel
if (t==num_times-6)
set.column(lpmodel,column+t+1,c(-bondvalue), indices=c(t))
for (i in vec1){
set.column(lpmodel,column+t+i,c(lpmodel[t-1,column]-lpmodel[t,column]), indices=c(t)) % Issue associated with trying to access lpmodel
}
}
Thanks