Pandas Dataframe as Paramaters within Pyomo optimisation model

533 views Asked by At

I'm new to Pyomo and trying to utilise data in my pandas dataframe as parameters within the optimisation model, the dataframe looks like this;

          Ticker    Margin  Avg. Volume   M_ratio   V_ratio
Index
0            ES1   6600.00      1250970  0.126036  0.212996
1            TY1   1150.00      1232311  0.021961  0.209819
2            FV1    700.00       488906  0.013367  0.083244
3            TU1    570.00       293885  0.010885  0.050038
4            ED3    500.00       137802  0.009548  0.023463
5            NQ1   7500.00       427061  0.143223  0.072713
6          FDAX1  24074.12        98838  0.459728  0.016829
7          FESX1   2641.28       832836  0.050439  0.141803
8          FGBL1   2502.75       546878  0.047793  0.093114
9          FGBM1   1042.10       330517  0.019900  0.056275
10         FGBS1    262.97       232801  0.005022  0.039638
11         F2MX1   4822.81          398  0.092098  0.000068

The model I'm constructing aims to find the maximum contracts one may have in all assets based on balance and a number of constraints.

I need to iterate through the rows in order to add all the relevant data to model.utilisation

model.Vw = Param() #<- V_ratio from df
model.M = Param() #<- Margin from df
model.L = Var(domain=NonNegativeReals)

model.utilisation = Objective(expr = model.M * model.L, sense=maximize)

Effectively it needs to take in Margin for each ticker and determine how many of that you can get relevant to balance - i.e.

*(ES1 Margin * model.L) + (TY1 Margin * model.L)* etc etc throughout the dataframe.

I've tested the logic by plugging in dummy data and seems to work but it's not efficient to be writing in each piece of data and then adding it to the utilisation model as I have hundreds of lines in my dataframe.

Apologies if there are some blinding errors, very new to Pyomo

0

There are 0 answers