Code: Select all
m = GEKKO()
m.time = np.arange(0, 200, 1)
#define the variables
consumption = m.Var()
tax = m.Var()
disposable_income = m.Var()
(...)
#define the parameters
government_spending = m.Param(value=20)
interest_rate = m.Param(value=0.05)
tax_rate = m.Param(value=0.2)
(...)
#define lagged values of bond_price and bond_holding
m.delay (bond_price, bond_price_previous, steps=1)
m.delay (bond_holding, bond_holding_previous, steps=1)
#define the equations of the model
m.Equation(money_holding == wealth - bill_holding_household - bond_value)
m.Equation(money_demand == expected_wealth - bill_holding_household - bond_value)
m.Equation(bill_holding_central_bank == bill_supply - bill_holding_household)
m.Equation(bill_supply.dt() == (government_spending + coupon_rate * bill_supply + bond_holding) - (tax + coupon_rate * bill_holding_central_bank) - bond_price * bond_holding.dt())
m.Equation(money_supply.dt() == bill_holding_central_bank.dt())
(...)
m.Equation(coupon_rate == interest_rate)
m.Equation(bond_return == 1 / bond_price)
m.options.IMODE=4
m.solve(disp=True, DIAGLEVEL=2)
< /code>
Das obige Modell wird von Gekko erfolgreich gelöst. Freiheitsgrade (DOF) = 0, und die Lösungen sind wie erwartet.m.Equation(bond_price.dt() == bond_price_increase_step * decision_increase_bond_price)
m.Equation(decision_increase_bond_price == m.if2(target_proportion - ceiling_target_proportion, 0, 1))
m.Equation(target_proportion == bond_value / (bond_value + bill_holding_household))
< /code>
Bond_price ist zuvor ein Parameter, aber jetzt ist es eine Variable. Es wird sich ändern, abhängig davon, ob darget_proportion höher ist Wenn dies der Fall ist, wird Decision_increase_bond_price 1 und erhöht Bond_price durch Bond_price_increase_Step. Dies bedeutet möglicherweise, dass es im System zwei weitere Variablen gibt als die Anzahl der Gleichungen. Außerdem bin ich besonders zuversichtlich, dass der DOF durch IF2 verursacht wird, da das Entfernen und Hinzufügen eines IF2 aus meinem Experiment meine DOFs um 2. Gilt der Grund für andere logische Funktionen in Gekko (max, min, if3 usw.). ihre zugehörigen Variablen und Parameter) < /p>
from gekko import GEKKO
m = GEKKO()
m.time = np.arange(0, 200, 1)
consumption = m.Var()
tax = m.Var()
disposable_income = m.Var()
money_holding = m.Var()
money_demand = m.Var()
money_supply = m.Var()
income = m.Var()
bill_holding_household = m.Var()
wealth = m.Var()
coupon_rate = m.Var()
bill_supply = m.Var()
bill_holding_central_bank = m.Var()
expected_disposable_income = m.Var()
expected_wealth = m.Var()
bond_holding = m.Var()
bond_return = m.Var()
bond_value = m.Var()
bond_price_previous = m.Var()
bond_holding_previous = m.Var()
capital_gain = m.Var()
bond_price = m.Var(value=10)
decision_increase_bond_price = m.Var()
target_proportion = m.Var()
government_spending = m.Param(value=20)
interest_rate = m.Param(value=0.05)
tax_rate = m.Param(value=0.2)
marginal_propensity_to_consume_income = m.Param(value=0.6)
marginal_propensity_to_consume_wealth = m.Param(value=0.4)
expected_disposable_income_adjustment_speed = m.Param(value=0.5)
expected_wealth_adjustment_speed = m.Param(value=0.5)
portion_household_expect_increased_return = m.Param(value=0.1)
bond_price_increase_step = m.Param(value=0.01)
ceiling_target_proportion = m.Param(value=0.505)
floor_target_proportion = m.Param(value=0.495)
lambda20 = m.Param(value=0.35)
lambda22 = m.Param(value=1)
lambda23 = m.Param(value=1)
lambda24 = m.Param(value=0.03)
lambda30 = m.Param(value=0.3)
lambda32 = m.Param(value=1)
lambda33 = m.Param(value=1)
lambda34 = m.Param(value=0.03)
m.delay (bond_price, bond_price_previous, steps=1)
m.delay (bond_holding, bond_holding_previous, steps=1)
m.Equation(money_holding == wealth - bill_holding_household - bond_value)
m.Equation(money_demand == expected_wealth - bill_holding_household - bond_value)
m.Equation(bill_holding_central_bank == bill_supply - bill_holding_household)
m.Equation(bill_supply.dt() == (government_spending + coupon_rate * bill_supply + bond_holding) - (tax + coupon_rate * bill_holding_central_bank) - bond_price * bond_holding.dt())
m.Equation(money_supply.dt() == bill_holding_central_bank.dt())
m.Equation(wealth.dt() == disposable_income - consumption + capital_gain)
m.Equation(expected_disposable_income.dt() == expected_disposable_income_adjustment_speed * (disposable_income - expected_disposable_income))
m.Equation(expected_wealth.dt() == expected_wealth_adjustment_speed * (wealth - expected_wealth) + expected_disposable_income - consumption)
m.Equation(capital_gain == bond_holding_previous * (bond_price - bond_price_previous))
m.Equation(consumption == marginal_propensity_to_consume_income * expected_disposable_income + marginal_propensity_to_consume_wealth * wealth)
m.Equation(disposable_income == income + coupon_rate * bill_holding_household + bond_holding - tax)
m.Equation(income == consumption + government_spending)
m.Equation(tax == tax_rate * (income + coupon_rate * bill_holding_household + bond_holding))
m.Equation(bill_holding_household == expected_wealth * (lambda20 + lambda22 * coupon_rate + lambda23 * bond_return + lambda24 * (expected_disposable_income/expected_wealth)))
m.Equation(bond_value == expected_wealth * (lambda30 + lambda32 * coupon_rate + lambda33 * bond_return + lambda34 * (expected_disposable_income/expected_wealth)))
m.Equation(bond_holding == bond_value / bond_price)
m.Equation(coupon_rate == interest_rate)
m.Equation(bond_return == 1 / bond_price)
m.Equation(bond_price.dt() == bond_price_increase_step * (decision_increase_bond_price))
m.Equation(decision_increase_bond_price == m.if2(target_proportion - ceiling_target_proportion, 0, 1))
m.Equation(target_proportion == bond_value / (bond_value + bill_holding_household))
m.options.IMODE=4
m.solve(disp=True)
< /code>
Ich habe eine unvollkommene Lösung ausprobiert, die den IF2 durch eine Ungleichheit ersetzt:decision_increase_bond_price * (ceiling_target_proportion - target_proportion)