# OSR/New Keynesian Model with bounded rationality

Hello Dynare community,

I want to find the optimal simple rule of a new keynesian model with bounded rationality and switching. It is a baseline model with backwardlooking expectations now.
As I understand this kind of system is only feasible in matlab. If I’m wrong please correct me. I couldn´t find anything about bounded rationality in Dynare.

So, I have programed the system in Matlab and used the discrete choice theory to state the fraction of economic agents using a certain heuristic.

My question is now: How to find the optimal simple rule for this system in Matlab.
In case of Rational Expectations I used the OSR command but now its not possible anymore.

My first thought was to find an algorithm which finds the optimal value of the gamma’s…

This is a simple optimization problem. You can find various pieces of code useful for this in the forum.

Thank you.
I have checked some codes and found fminsearch:
https://de.mathworks.com/help/matlab/ref/fminsearch.html

fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2,1];
x = fminsearch(fun,x0)

For my loss functon I changed it to:

% model
pi= bet* pi(+1) + gam* x;
x= x(+1) - (1/sig)* (i- pi(+1));
i= gamma_1* x + gamma_2* pi; %OSR of taylor type

fun=@(gamma) bet^k*(alp_1*(pi)^2 + alp_2*(x)^2 + alp_3*(i)^2);
gamma0 = [0.5, 1.5];
L= fminsearch(fun,gamma0);

but I do have expectations. So I need to define pi(+1) and x(+1)

pi(+1)=frac_pi_ext*(1+alp_pi)pi + (frac_pi_sta - alp_pi frac_pi_ext)pi(-1);
x(+1)= frac_pi_ext
(1+alp_x)x + (frac_pi_sta - alp_x frac_w_ext)*x(-1);

and by doing this I need to define every term again e.g frac_pi_ext, frac_pi_sta
Is there any easier way to skip this?

I am not sure I understand the last question. Why are there expectations appearing in your model solution?

I have the following model:

pi= beta* pi(+1) + gam* x;
x= x(+1) - (1/sig)* (i- pi(+1));
i= i* + delta_pi* (pi-pi*) + delta_x* x + k;

Expectations are no longer formed rationally but are based on simple heuristics.
Agents can chosse from various heuristics: Targeters, Static exp, Extrapolators - for output and Inflation. Based on past expectation error an attractivity vaule is assigned to each heuristic. And with the discret choice theory the fraction of agents who use one of the heuristcs is defined.
That’s why I have this expectations in my model.

And when I use “fminsearch” I need to care about the expectations in the PC and IS. Or do I make an error in reasoning?

You are making a mistake here. What is relevant in the end is the model solution, not the system defining the solution. Even with RE, the solution later is a VARMA process and therefore purely backward looking.