title: Matlab: Calculating Correlation of time series
body: <p>The time series model is expressed as </p>
  
  <pre><code>y(t) = 0.5 + 0.3y(t-1) + n(t)
  </code></pre>
  
  <p>where </p>
  
  <pre><code>n(t) = 0.1*randn(500,1) for t=1,2,...,500
  </code></pre>
  
  <p><a href="http://www.uio.no/studier/emner/matnat/ifi/INF4480/v10/undervisningsmateriale/spII_stocastic_processesIII_handout.pdf" rel="nofollow">Slides</a> contain the Correlation and covariance matrix. The formula for correlation is: <code>E[y(t)*y(t)^T]</code> which can be invoked by using <code>xcorr</code>. I would like to know how one can calculate the individual Correlation matrix for its lagged version <code>E[y(t-1)*y(t-1)^T]</code> without using the inbuilt commands so that I can finally implement the following expression</p>
  
  <pre><code> trace([E[y(t-1)*y(t-1)']]^-1) 
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>For example, Let </p>
  
  <pre><code>y = randn(10,1);
  
  for t = 1:10
  disp(y(t));
  end
  
  Expectation_y =  sum(y(1:end))/10
  </code></pre>
  
  <p>Likewise, how do I perform expectation for lagged variables and then implement the formula =</p>
  
  <pre><code> trace([E[y(t-1)*y(t-1)']]^-1)
  </code></pre>