简体   繁体   English

Pyomo 约束和使用 pandas

[英]Pyomo constraints and using pandas

I am using Pyomo to optimize a cashflow matching problem using bonds.我正在使用 Pyomo 使用债券优化现金流匹配问题。 I also want to have a detailed constraint that does looks at the cashflows I am expecting to get from my portfolio versus fixed requirements and conduct a number of calculations on the differences:我还希望有一个详细的约束来查看我期望从我的投资组合中获得的现金流与固定要求,并对差异进行一些计算:

  1. Calculate difference (wanted minus expected to receive or "in - out" in the picture)计算差异(想要减去预期接收或图片中的“输入-输出”)
  2. Calculate the accumulation of these differences to the last end point using accumulation factors (multiply difference with accumulation factors - which are stored as a model.AccumFactors)使用累积因子计算这些差异到最后一个端点的累积(将差异乘以累积因子 - 存储为 model.AccumFactors)
  3. Sum these year-on-year accumulation factors (cumsum(axis=1))将这些同比累积因子相加(cumsum(axis=1))
  4. Find the minimum找到最小值

[Excel description of process][1] [过程Excel说明][1]

Now Panda commands don't work in this situation.现在 Panda 命令在这种情况下不起作用。 Is there anything I can do to fix this?我能做些什么来解决这个问题吗? Alternative approaches?替代方法?

Thanks gmavrom.谢谢gmavrom。

Trying to think a different formulation.试图想一个不同的表述。 The code below has Multipliers as the model variable and everything else as parameters.下面的代码将乘数作为 model 变量,并将其他所有内容作为参数。 Unfortunately the below doesn't work and just prints out strings of:不幸的是,以下内容不起作用,只会打印出以下字符串:

54993.219033692505*Multipliers[Bond1] + 63662.18895851663*Multipliers[Bond2] + 64451.10079031628*Multipliers[Bond3] + … etc 54993.219033692505*Multipliers[Bond1] + 63662.18895851663*Multipliers[Bond2] + 64451.10079031628*Multipliers[Bond3] + ... 等

def Test1_Constraint(model, TimeIndex):
   SumAccumulatedShortfall=0
   for TimeCount in range(0,TimeIndex+1):
         AccumulatedShortfall = (model.Liabilities[TimeCount] - \
                    sum(model.BondPayment[BondIndex, TimeCount] *model.Multipliers[BondIndex] for BondIndex in model.Bonds))* \
                                  model.AccumulationFactor[TimeCount]

         SumAccumulatedShortfall = SumAccumulatedShortfall + AccumulatedShortfall
         print('SumAccum',SumAccumulatedShortfall)
    return (SumAccumulatedShortfall/model.TotalLiabilityValue <= 0.03)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM