I want to solve the optimization problem in R; The dummy data for them is given below.
# Input Data DTM <- sample(1:30,10,replace=T) DIM <- rep(30,10) Price <- 100 - seq(0.4,1,length.out=10) # Variables that shall be changed to find optimal solution Hike <- sample(0:1,10,replace=T) Position <- sample(-2:2,10,replace=T) # Objective function hikes_till_now <- cumsum(Hike) - Hike PostHike <- numeric(10) for (i in seq_along(Hike)){ PostHike[i] <- 99.60 - 0.25*(Hike[i]*(1-DTM[i]/DIM[i])) if(i>1) { PostHike[i] <- PostHike[i] - 0.25*hikes_till_now[i] } } Pnl <- Position*(PostHike-Price) # Snapshot of data all.data <- data.frame(DTM,DIM,Price,Hike,Position,Pnl) all.data # DTM DIM Price Hike Position Pnl # 1 3 30 99.60000 1 2 -0.4500000 # 2 11 30 99.53333 1 2 -0.6833333 # 3 29 30 99.46667 1 2 -0.7500000 # 4 16 30 99.40000 1 -2 1.3333333 # 5 25 30 99.33333 0 2 -1.4666667 # 6 5 30 99.26667 1 1 -0.8750000 # 7 3 30 99.20000 0 -1 0.8500000 # 8 8 30 99.13333 0 0 0.0000000 # 9 22 30 99.06667 0 -2 1.4333333 # 10 11 30 99.00000 0 -2 1.3000000
Description of Variables
So, the first section of code contains the inputs to my system - DTM , DIM and Price .
The second section consists of variables that I would like to change in order to find the optimal solution - Hike and Position . Values ββwere initiated as described above.
The last section consists of the calculations that I will need to do to achieve my objective function, which is to maximize Pnl .
Limitations
I also have a few limitations -
Hike must be less than 4- The sum of
Position must be 0, and each Position value must be from -2 to +2
I previously worked in GAMS and MATLAB, but I just canβt get to optimize the work here. I looked at the examples in the Rsymphony package and this answer , but I was not able to get them to work for several variable inputs.
Help evaluate.
source share