【问题标题】:Pyomo constraints and using pandasPyomo 约束和使用 pandas
【发布时间】:2020-09-07 02:39:31
【问题描述】:

我正在使用 Pyomo 来优化使用债券的现金流匹配问题。 我还希望有一个详细的约束条件,它可以查看我期望从我的投资组合中获得的现金流量与固定要求,并对差异进行一些计算:

  1. 计算差异(希望减去预期接收或图片中的“输入-输出”)
  2. 使用累积因子计算这些差异到最后一个终点的累积(将差异乘以累积因子 - 存储为模型。AccumFactors)
  3. 对这些同比累积因子求和 (cumsum(axis=1))
  4. 找到最小值

[Excel流程说明][1]

现在 Panda 命令在这种情况下不起作用。我能做些什么来解决这个问题吗?替代方法?

【问题讨论】:

  • 如果您有一些您尝试过但没有成功的示例,或者您确实需要帮助的内容,将会很有帮助。目前,我读到的只是 pandas 命令不能直接与 Pyomo 一起使用,这在某种程度上应该是可以预料的。您是否有 pandas/Pyomo/Python 问题或在数学上表达您提出的四个点的问题?

标签: python pandas constraints pyomo


【解决方案1】:

感谢 gmavrom。

尝试思考不同的表述。下面的代码将乘数作为模型变量,将其他所有内容作为参数。 不幸的是,以下内容不起作用,只会打印出以下字符串:

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)

【讨论】:

    猜你喜欢
    • 2021-06-28
    • 2017-04-13
    • 2021-09-12
    • 2017-08-24
    • 1970-01-01
    • 2018-05-29
    • 2018-07-22
    • 2017-12-31
    • 1970-01-01
    相关资源
    最近更新 更多