function pi1=regime_Sentiment(Xt,t)

P120=0.01; P210=0.1; psi10=1; psi20=-1; sigma_X0=0.5;
A0=[P120  P210  psi10 psi20 sigma_X0]; %give the initial values of parameters for search

L_bound=[  0;  0;-2;-2;0];
U_bound=[0.5;0.5; 2; 2;3];
options = optimset('Display','iter','TolX',1e-8,'TolFun',1e-6,'MaxIter',10000, 'MaxFunEvals', 10000,'Algorithm','interior-point');
ff = @(u) Log_likelihood_fun_Sentiment(u,Xt,t); 
[A_text]=fmincon(ff,A0,[],[],[],[],L_bound,U_bound,[],options);

    P12=A_text(1);
    P21=A_text(2);
    psi1=A_text(3);
    psi2=A_text(4);
    sigma_X=A_text(5);
    P11=1-P12;
    P22=1-P21;
    
 %% pi(t)
 
    f1=zeros(t,1);
    f2=zeros(t,1);
    pi1=zeros(t+1,1); % pi1(t) stands for \pi(t-\Delta t|t-\Delta t), so pi1(1) stands for \pi(0|0)
    pi2=zeros(t,1); % pi2(t) stands for \pi(t|t-\Delta t)
    pi1(1)=P21/(P12+P21);
    
    for j=1:t
        f1(j)=1/sqrt(2*pi)/sigma_X*exp(-(Xt(j)-psi1)^2/2/sigma_X^2);
        f2(j)=1/sqrt(2*pi)/sigma_X*exp(-(Xt(j)-psi2)^2/2/sigma_X^2);
        pi2(j)=pi1(j)*P11+(1-pi1(j))*P21;
        pi1(j+1)=f1(j)*pi2(j)/(f1(j)*pi2(j)+f2(j)*(1-pi2(j)));
    end
    

end