Sunday, January 28, 2018

Understanding Basic structure of SAM (Social Accounting Matrix)

Understanding the interaction and transfers between different factors of production, production activities and institutions (households, governments and corporate sector) is imperative in order to completely grasp the concept of  macro economic dynamics. The interaction  can be illustrated with the help of Social Accounting Matrix (SAM).

In this post we create SAM  and then attempt to create SAM multiplier. SAM is a matrix representation of national account for a single year and it sketches transactions that take place within an economy/ country. SAM is a squared matrix in which each 'row' and 'column' is called account, and each cell in the matrix represents circular flow from column to  row accounts. For example: While accounting an expenditure of households on commodities, we record the household expenditure in household 'Column' and value of consumed commodities in commodities 'Row'

(Note that total expenditure on commodities is equal to value of total commodities, which  complements the double entry accounting requirement, that the total expenditure is equal to total revenue). 

In SAM we distinguish entities between 'Activities' and 'Commodities'. Activities are those entities which produce commodities sold in an economy. This distinction is important because there are different commodities, and sometimes a commodity can be produced by more than one kind of activity. Similarly one activity can produce more than one kind of commodity. In our illustration we denote activity with '_a' and commodity with '_c'


 Activities makes use of intermediate commodities and factors of production to produce final commodities and services (C1). The factors are paid, wages (for labor), rent (for capital) and profits (to firm), so the value added 'cell' (R1C3) appears in SAM.  It is important to note that the sum of activities (C1 R8) is Gross Output, and is equal to activity income in R1.

Commodities (R2) are either imported or domestically supplied. (R1 C2)  Further there are sales taxes and import tariffs in products (R5 C2). As total supply is accounted on market value, inclusion of sales taxes and import tariff is important. Sum of commodities produced is total supply (R8 C2) in an economy which is equals to Total demand (R2) . The total demand (R2 C8)  is sum of demand for intermediate commodities (by each activities), consumption spending on commodities (by households), recurrent spending by government, investment demand and export earnings.

Factor payments (R4 C3) made to households for supply of labor and capital is the total factor spending (R8 C3) in the economy. The payment made to factor is equal to the total factor income (R3 C8)

Similarly household spends on consumption (R2 C4) and direct taxes (R5 C4), the remaining income is then saved (or dissaved if expenditure exceeds income) (R6 C4).

Government spends on normal recurrent activities (R2 C5) and social transfers (R4 C5), and if Government revenue earned from sales taxes, direct taxes)  is greater/less than expenditure then  fiscal/deficit (R6 C5) surplus occurs.

Rest of the world shows foreign exchange inflow/outflows, that is why export earnings, foreign remittances, foreign grants and loans and current account balance are included in C7. The summation of rest of the world gives Foreign exchange inflow (R8 C7).

Wednesday, January 10, 2018

Statistical Properties of OLS

Our statistical model is restricted to linearity  (in parameters ).

The model we have is $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$

As stated in the earlier post, we can stack everything together, and write the equation (no matter how many explanatory variables we have), in the matrix form: \(y=x\beta +\varepsilon\).  The matrix representation shows that the regression analysis is conditional upon value of 'x'

'Y' and 'X' are observed, 'beta' is fixed unknown parameter and '$\varepsilon $' is observed random term . 


The reason we use OLS is that, under assumptions A1- A7 of the classical linear regression model, the OLS have several desirable statistical properties. This post examines these desirable statistical properties of OLS under seven assumptions:

Seven assumptions of the model:

A1: Fixed Regressor: It means that all the elements of matrix 'x' with dimension N times K are fixed (or we can say it is non-stochastic/non random/deterministic). Further, assumption also requires that N must be greater than K  (N is number of observations and K is number of co-efficient), and matrix N*K is a full rank (Invertible).

Violations of these two conditions can have errors in variables in following forms:
a) Auto Regression
b) Simultaneous Equation  
c) Perfect Multicollinearity 


A2: Random Disturbance zero Mean: It means that expectation of random term is equal to zero or
$E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$. 




A3: Homoscedasticity: (Homo= Same and Scedas= Spread):  It means that variance of the error terms is equal to sigma square. $Var({{\varepsilon }_{i}})=\text{ E(}\varepsilon {{\varepsilon }^{T}})={{\sigma }^{2}}$.

The variance  is similar across range of values of independent variable.

Violation of A3 leads to Heteroscedasticity : It means that the variability of variable is unequal across the range of values.

We can use assumptions A2 $E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$  with A3 to get more insight regarding the property  $Var({{\varepsilon }_{i}})=\text{ E(}\varepsilon {{\varepsilon }^{T}})={{\sigma }^{2}}$  :



Step1 is formula of variance (actual subtract to mean)
Step2 is rule of decomposition 
Step 3 we replace the value of expectation of $E(\varepsilon )$from A2: which states that $E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$

A4:  No Auto-correlation: The Covariance between epsilon(i) and epsilon (j) is zero or $Cov({{\varepsilon }_{i}}{{\varepsilon }_{j}})=0$

In other words, error of 'i'th variable and 'j' variable doesn't change together.

A5: Constant Parameters : This means ${{\beta }_{k*1}}\text{ and }\varepsilon $ are fixed and unknown

A6: Linear Model : As stated earlier, it is linear in parameter. Basically it is saying that 'y' is generated through a process $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$ (DGP= Data generating process)

A7: Normality: The distributions of the error term '$\varepsilon $' is normal

Now if we combine assumptions A2 (Random Distribution) +A3 (Homoscedasticity) +A4 (No Auto-Correlation)+A7 (Normality) we get '$\varepsilon \sim N(0\text{ , }{{\sigma }^{2}}{{I}_{N*N}})$'


In Econometrics; the assumptions are just like a catalogue , one has to refer the catalogue and if there is any violation (of the assumptions) then we must treat the violation with specific technique.

Friday, January 5, 2018

Orthogonality and Geometric representation of OLS solution

You will have to go through part  Deriving OLS with Matrices  as prerequisite to understand this post:

From first order condition we have:

\[\begin{align} & \frac{\partial S}{\partial b}=2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}=0 \\ & or\text{ }2{{x}^{T}}(y-xb)=0 \\ & or\text{ }{{x}^{T}}(y-xb)=0 \\ \end{align}\]
Here: \((y-xb)=e\text{ }\left( Residual \right)\)
So, \(\text{ }{{x}^{T}}e=0\)

Note that \({{x}^{T}}e=0\) is the condition of orthogonality 

What is Orthogonality ?

When conducting econometric or statistical analysis, independent variables that affect particular dependent variable are said to be orthogonal if they are uncorrelated. Orthogonality is a condition when two vectors intersect each other in a right angle. 
 In above illustration 'x' independent variable is orthogonal on 'e' residual

Geometric representation of 'OLS' solution 

We have residual 'e' represented as difference between actual and predicted value. So y (actual) -xb (predicted y) which is equal to 'e' can be written as:

\(\begin{align} & e=y-xb=y-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}}y \\ & =(I-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}})y \\ \end{align}\)

Remember we derived value of 'b' from OLS solution in previous post

Let M = \(\begin{align} &(I-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}}) \\ \end{align}\) 

So the expression becomes 'My',  known as operator

Further we know that $\hat{y}=xb={{({{x}^{'}}x)}^{-1}}{{x}^{'}}y$
Let H= ${{({{x}^{'}}x)}^{-1}}{{x}^{'}}$

So the expression becomes 'Hy', known as 'Hat' matrix or Projection matrix



Note that e ='My' is perpendicular on y(hat)= 'Hy' line which has the projection matrix made of x

Tuesday, January 2, 2018

Deriving OLS with Matrices

In Econometric and statistics, ordinary least squares (OLS) or linear least squares is a method for estimating the unknown parameters($\beta$)  in a linear regression model. The goal is to minimize the differences ($\varepsilon \text{ or e}$) between the observed values and predicted values with the use of linear approximation. In this post i make an effort to derive the OLS solution ($\beta$) with Matrices

We know that Simple OLS regression looks like $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$. Suppose we have ‘n’ numbers of observations and ‘k’ numbers of explanatory variables. If we convert the equation into matrix form, it looks like:



From above representation we can infer that the size of Y (Dependent variable) is N by 1, size of X (Independent variable) is N by K and size of e  (errors of prediction) is N by 1. This gives us a clue that size of Beta (B) is K by 1 i.e  Beta has K row and 1 column.

The whole purpose of this post is to derive the beta from the structure by minimizing the square of residuals  in matrix notation 

(Step: 1) Because we can stack everything together, we can write the equation (no matter how many explanatory variables we have) in the form: \[y=x\beta +\varepsilon\].

The equation in-turn can be written as: \[\text{y=xb+e}\] Where, e=Residual and XB is OLS estimator.

(Step 2) We know that the error term 'e' is  \[\begin{align} & e=y-{{y}^{\wedge }}=y-xb \\ & \\ \end{align}\] (y is the fitted value and y^ is the predicted, and we minimize sum of residual squares).

Note: ‘e’ is a scalar and it has N by 1 dimension matrix, and 'e' transpose has 1 by N dimension.

So the square of residuals is ${{e}^{2}}={{e}^{T}}*e$, and it has 1 by 1 dimension.

(Step 3) We represent minimized sum of square residuals as  $Minimize\text{ S(b)= }\sum{{{e}_{i}}^{2}}={{e}^{T}}*e$ , and after we include the value of e and e(Transpose) it looks like: $={{[y-xb]}^{T}}*[y-xb]$

Note: ($e^{T}={{[y-xb]}^{T}}and $ e= [y-xb])

We need to solve this further with the help of matrix rule which states that: ${{(A+B)}^{T}}={{A}^{T}}+{{B}^{T}}$ and ${{(A*B)}^{T}}={{B}^{T}}*{{A}^{T}}$

(Step 4) Working out with the rule, we progress further and expand ((Step 3) as follows: $\begin{align} & =[{{y}^{T}}-{{x}^{T}}{{b}^{T}}][y-xb] \\ & ={{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb \\ \end{align}$

This means that sum of square residuals $S={{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb$

(Step 5) Now, inorder to minimize the sum of square residuals we take first order derivative with respect to 'b'

\[\frac{\partial S(b)}{\partial b}=\frac{\partial ({{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb)}{\partial b}\]

There is a rule for derivatives of matrix which states that:

\[(i)\frac{\partial Ax}{\partial x}={{A}^{'}}\text{ ; (ii)}\frac{\partial {{x}^{'}}Ax}{\partial x}=2Ax\text{ (If  }\!\!'\!\!\text{ A }\!\!'\!\!\text{  is symetric) and = (}{{\text{A}}^{'}}+A)x\text{ (If  }\!\!'\!\!\text{ A }\!\!'\!\!\text{  is not symetric)}\] 
Symmetric: If A is equal to A (Transpose) then A is symmetric.

(Step 6) First order condition leaves us with:
 \[\begin{align} & \frac{\partial S(b)}{\partial b}=\frac{\partial ({{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb)}{\partial b} \\ & \frac{\partial S(b)}{\partial b}=0-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}+2{{x}^{T}}xb \\ & \frac{\partial S(b)}{\partial b}=2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}} \\ \end{align}\]

Now, we make the term equal to zero as per first order condition of minimization to get expression for 'b'.
\[\begin{align} & 2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}=0 \\ & or\text{ }2{{x}^{T}}xb-{{x}^{T}}y-{{x}^{T}}y=0 \\ & or\text{ }2{{x}^{T}}xb={{x}^{T}}y+{{x}^{T}}y \\ & or\text{ }2{{x}^{T}}xb=2{{x}^{T}}y \\ & or\text{ }{{({{x}^{T}}x)}^{-1}}{{x}^{T}}xb={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ & or\text{ }Ib={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ & \therefore b={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ \end{align}\]

(Step 7) Now we check the second order condition of minimization, where the result must be greater than zero:


\[\frac{{{\partial }^{2}}S(b)}{\partial b\partial {{b}^{'}}}=2{{x}^{T}}x\text{ (The expression is a Positive definite)}\]

Since $2{{x}^{T}}x$ is greater than zero, we confirm that the expression derived for beta i.e $b={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y$ shall give value of coefficient that minimizes the sum of the squared errors of prediction when y is regressed on x.

Next post will focus on OLS solution properties (With Matrices)

Sunday, July 9, 2017

Financial Market Interdependence (Australia, HongKong, Europe and United States)

This post illustrates Vector Auto Regression (VAR) technique that can be used to  analyses impulse response of indices in different regions (Australia, Hong Kong, Europe and United States) when there is a shock in anyone of the market. It makes use of VAR model with simple recursive structure to analyse the impulse response.Vector auto regression (VAR) is an ordinary least square regression where each variable is regressed on lag value of itself and other variables in the set.

$Au{{s}_{t}}={{A}_{0}}+HK{{G}_{t-1}}+E{{U}_{t-1}}+US{{A}_{t-1}}+{{\mu }_{t}}$

In above equation u(t) is the VAR disturbance vector and is serially uncorrelated. VAR disturbance vector have variance covariance matrix, distrubance vector is assumed to be related to the underlying economic shocks, ${{\varepsilon }_{t}}$, by 

${{\mu }_{t}}=D{{\varepsilon }_{t}}$ 
 D is lower triangular and ${{\varepsilon }_{t}}$ has covariance matrix analogous to the identity matrix. 

$\left( \begin{matrix} {{u}_{Australia}} \\ {{u}_{HongKong}} \\ {{u}_{Europe}} \\ {{u}_{usa}} \\ \end{matrix} \right)=\left( \begin{matrix} {{t}_{11}} & 0 & 0 & 0 \\ {{t}_{21}} & {{t}_{22}} & 0 & 0 \\ {{t}_{31}} & {{t}_{32}} & {{t}_{33}} & 0 \\ {{t}_{41}} & {{t}_{42}} & {{t}_{43}} & {{t}_{44}} \\ \end{matrix} \right)\left( \begin{matrix} {{\varepsilon }_{Australia}} \\ {{\varepsilon }_{HongKong}} \\ {{\varepsilon }_{Europe}} \\ {{\varepsilon }_{usa}} \\ \end{matrix} \right)$

We construct Financial market interdependence matrix to derive the impulse response of prices in different regions. We arrange the matrix based on financial market opening time, which states that Australian Market opens first, which is followed by HongKong Market, European market and then at at last by United States ( for the shake of  illustration we ignore China and India market).

The data are extracted from world stock price indices (Yahoo Finance) and dates are arranged in ascending order. We extract the date from January 1st 2013 to December 31st 2014, and run the regression in Eviews software.

Data sources:
For  (US and World Indices)
USA (us): S&P 500,
Australia (au):S&P ASX 200
Hong-Kong (hk):  HANG SENG INDEX 
EU(eu): FTSE 100

The model is estimated as a structural recursive VAR using Cholesky decomposition. The derived short run restriction matrix is structure in such a way that, in equation one Australian market does not react to change in other markets. In second equation, HongKong market reacts to Australian market, in third equation European market reacts to Hongkong market and Australian market; in equation four United States market reacts to HongKong, Euroepan Market and Australian market, contemporaneously. We take lag 5 which denotes working week days (we  test the lag length and co-integration, you can refer the process in this link).

Stability test-AR root table shows that no root lies outside the unit circle, and VAR satisfies the stability condition. If you want to follow the process in E-views please click here.

Stability check


Impulse response (2013-2014)


First row shows how Australian market reacts to shock in rest of the region, second row shows Hong Kong market, third row shows European market and fourth row shows US market. We find that Australian market is less sensitive to HongKong market, however it is more responsive to US and European market in second day of trading (14 units and 15units positive response to one standard deviation shock in the residuals) . If we analyse Hongkong market we find that  it responds instantaneously to Australian market as it climbs up 85 units as a response to one standard deviation shock in residuals (of Australian market share indices). In next row when we analyze European market we find that it responds significantly to US market, and shows 18 units positive increment. Further it quickly dies out when it responds to US and Australian market, and the absorption of the shock is more rapid when it responds to HongKong market.

We can extend this study and compare how the transition has been changing throughout the years. It will be interesting to see how response of Australian, US and HongKong market has changed overtime when there is shock in European market and compare the scenario before 2010 (first) Greece Bailout.

Impulse Response (2005-2006)


We analyze the impulse response of rest of region (third column) when there is shock in European market in the period 2005 to 2006. The results shows that impulse response to the shock on European market doesn't die out quickly when compared to 2013-2014, for example S&P 500 (US) market is back to normalcy within 12 days in the year 2013-14, while it continued above '6'  even after 20th day in the period 2005-2006. The reason behind this could be that after late 2009 GREECE (first) bailout most of the vulnerable GREECE/EU stocks were sold out by the  investors/companies, making respective markets relatively insulated and enabling them recover (back to normalcy '0' ) from shocks in European market within very short time.  

Tuesday, June 6, 2017

Financial Planning- Home Mortgage management (ii)

In this section you will need excel. Also you will have to go through part (i) as prerequisite to understand the formulation of system equations. 

In part (i) we assumed that annual income of client is constant, i.e Y(bar) = $80,000. However in reality income of an individual is not constant in nature (because it might decrease or increase due unforeseeable circumstances). In this regard let us assume that the client's income is growing at rate 'g'= 2% and so we incorporate this dynamics as continuous compounding growth of Y:







Further, we take the differential equation describing debt (D(dot))(we have already discussed about this equation in part i) and include the value of Y(t). Then we transform the equation by transferring Exponential value on right hand side.


Now we multiply both the sides by integrating factor e^(rt) and integrate both the sides to obtain 'D' :


By simplifying above equation ( transfer e^(-tr) on the right hand side) we derive the expression for D(t) which is known as general solution of the system of equation. 
As we have a general solution for the system of equation, we embed initial condition and determine value of 'C' in terms of Initial Debt, Initial Income, growth rate of income, interest rate on debt; and then formulate analytical solution for D(t). This will enable us to calculate the maximum loan, that we can approve with the help of given information.




 We know: Value of e^(0) =1



Make 't' =0 , as we are considering initial debt condition.



Transfer 'C' on the left hand side and express the relationship.


Include C in  D(t) as
Now you have readymade decision making equation that can be used for mortgage/auto loan financing.  When you embed D(t) equation in excel along with decision making parameters/factors you will get the visual dynamics of debt.


# Techniques  covered in blog posts labelled AED are taught in courses Mathematics for Applied Economics, and Applied Economics Dynamics offered at Crawford School of Public Policy @ The Australian National University. 

Monday, June 5, 2017

Financial Planning- Home Mortgage management (i)

#If you are new to compounding interest formula and continuous time series please refer my post on Financial Planning (basics) before reading this post

Consider that you a lending officer of a bank (e.g Standard Chartered or HSBC) are calculating a home loan contract with a client. The client wishes to borrow some debt amount (D), which can be denoted as Do > 0  (Here o means at time zero or at the time of burrowing). The annual interest rate is quote to be 'r', and since it is daily compounded, we will treat it as continuously compounding rate. The annual income of the client is Y(t)>0, which is a yearly income in some positive numbers. A fixed proportion (S) of the income (Y) is saved to pay the outstanding debt.

The relationship can be exhibited with the help of differential equation:


D(dot) is the change in debt, which is the function of saving (S) from Income (Y) deducted from incurred interest rate from debt  D(t)
In this first section we considered that Y (income) remains constant over time, so we change Y(t) as Y(bar). The solution method we use in solving the equation relies on the nature of the equation. So with the assumption of Y(t) as constant, the equation becomes autonomous, non-homogeneous and first order equation. It is of the first-order because it the higher-order derivative in the equation and it is autonomous because the coefficients doesn't vary with time. So first step to solve fist order, non-homogeneous and autonomous equation is to identify the steady state. If a system is in steady state, then the recently observed behavior of the system will continue into the future, which  means system remains unchanged for ever. So in-order to determine steady state we will have to solve by making change in Debt as zero or D(dot)=0 . We get steady state D(bar) and then incorporate it in solution for non-homogeneous equation.

I will include the process of deriving a particular solution for given nature of equation in next post or update in this post by 7th June 2015. 

For now just understand that the particular solution looks like:
A) Now first  question client asks you is "If i get home loan (D)o  in how many years i will pay up the debt  (remember here we assumed that whatever client save (S) from constant income (Y) is used to service the debt) 

So for particular solution we make D(t) = 0  (Client pays the debt in time  't' )



 





We solve the equation by keeping e^rt on left side and rest on the right. Further taking log on the both sides simplifies the equation,and we will have expression without exponential form. Now client reveals us that his/her income is Y= $80,000, and saves (s) 30% out of the yearly income, and wants to take $500,000  (given that valuation of property is sufficient enough provide the required sum). By feeding the value in the formula we can easily calculate the number of years it will take client to pay the loan, by servicing debt from his/her savings. 
                                                                        
 B) Now if the client could choose the length of the contract (e.g. 40 years or 60 years), what would be the maximum loan you should approve? If client wants to pay up the debt in 30 years


We took particular solution and embedded 30 in-place of 't', since we want to calculate the maximum loan we can approve for the given income and savings we calculate D(o) such that D(30)=0 i.e debt at 30th year is zero. 




Knowing this process enables us to understand the dynamics that goes inside system of equation. Further it also enables us to calculate specific value without use of complex excel formulas and software.



# Techniques  covered in blog posts labelled AED are taught in courses Mathematics for Applied Economics, and Applied Economics Dynamics offered at Crawford School of Public Policy @ The Australian National University.