# Inaugural Project

Imports and set magics:


```python
import numpy as np
import math
from scipy import optimize

# autoreload modules when code is run
%load_ext autoreload
%autoreload 2

# local modules
import inauguralproject
```

## Question 1

We start out by setting up the consumer mazimization problem. This is done by setting up a function returning the utility function and the objective function. These functions are set up in the inauguralproject.py file, to give a better overview of this file.

We then call upon a solver that can solve the maximization problem given the parameters. 


```python
# call solver
def sol_case1(w, epsilon, m, nu, tau0, tau1, kappa): 
    sol_case1_opt = optimize.minimize_scalar(inauguralproject.value_of_choice,method='bounded',
        bounds=(0,1),args=(w, epsilon, m, nu, tau0, tau1, kappa))
    l_opt = sol_case1_opt.x
    return l_opt
    l=l_opt
    u = inauguralproject.u_func(l, w, epsilon, m, nu, tau0, tau1, kappa)

    
```

## Question 2

Plot $l^{*}$and $c^{*}$ as a function of w in the range 0.5 to 1.5.


We create vectors for wage, labour and consumption, where the labour and consumptions vectors are empty. The labour and concumption is calculated for every value of w in a for loop. 
From this we are able to plot the optimal values of labour and consumption


```python
N = 100
# vector of wages
w_vec = np.linspace(0.5,1.5,N)
l_vec = np.empty(N)
c_vec = np.empty(N)


# calculates l and c for every value of w
for i,w in enumerate(w_vec):
    w = w_vec[i]
    find_l=sol_case1(w, epsilon=0.3, m=1, nu=10, tau0=0.4, tau1=0.1, kappa=0.4)
    l_vec[i] = find_l
    l=l_vec[i]
    c_vec[i] = inauguralproject.c_func(l, w)

# creates the figures
import matplotlib.pyplot as plt
plt.style.use("seaborn")

fig = plt.figure(figsize=(10,4))

fig_w_l = fig.add_subplot(1,2,1)
fig_w_l.plot(w_vec,l_vec)

fig_w_l.set_title('Optimal $l$ as a funtion of $w$')
fig_w_l.set_xlabel('$w$')
fig_w_l.set_ylabel('$l*$')
fig_w_l.grid(True)

fig_w_c = fig.add_subplot(1,2,2)
fig_w_c.plot(w_vec,c_vec)

fig_w_c.set_title('Optimal $c$ as a funtion of $w$')
fig_w_c.set_xlabel('$w$')
fig_w_c.set_ylabel('$c*$')
fig_w_c.grid(True)
```

## Question 3

Condsider a population with $N=10.000$ individuals indexed by i.
Assume the distribution of wages is uniform such that: 


\begin{equation}
w_{i}=\bigcup(0.5,1.5)
\end{equation}

Denote the optimal choices of individual i by $l_{i}^{*}$and $c_{i}^{*}.$

Calculate the total tax revenue given by:

\begin{equation}
T=\sum_{i=1}^{N}\left[\tau_{0}w_{i}l_{i}^{*}+\tau_{1}max\{wl-\kappa,0\}]\right]
\end{equation}

We set seed to be able to draw the same uniform numbers everytime we run the code. This time we compute the vector of wages by uniformly drawn numbers in the range 0.5 to 1.5 for N2 entries. 

Then we compute two functions, which are loacted in the py.file. The first function is a function calculating the taxes paid by each individual while the second function returns the total tax revenue. Thus, the total taxrevenue is given by:


```python
np.random.seed(42)
N2 = 100 #OBS! Was supposed to be 10K, but code took forever to run in Q5
w_vec2 = np.random.uniform(0.5,1.5,N2)
l_vec2 = np.empty(N2)
t_vec = np.empty(N2)

print(f'The total tax revenue is given by {inauguralproject.tax_rev(epsilon=0.3, m=1, nu=10, tau0=0.4, tau1=0.1, kappa=0.4):.2f} ')

```

    The total tax revenue is given by 12.25 


## Question 4

What would the tax revenue be instead of $\varepsilon=0.1$
We specify a new level of epsilon and call the total tax revnue function again:


```python
print(f'Given the new value of epsilon the tax revenue becomes {inauguralproject.tax_rev(epsilon=0.1, m=1, nu=10, tau0=0.4, tau1=0.1, kappa=0.4):.2f} ')
```

    Given the new value of epsilon the tax revenue becomes 28.18 


## Question 5

Consider a politician who wishes to maximize the tax revenue.


Which $\tau_{0},\,\tau_{1}$ and $\kappa$ would you suggest her to
implement? Report the tax revenue you expect to obtain. 

To solve this we define a new function that returns the objective function, that we want to maximize. To be able to solve this optimization problem we set some bounds and initial guesses. 

From this we can optimize the objective function and use the optimal values of $\tau_{0},\,\tau_{1}$ and $\kappa$ to calculate the taxrevenue that we expect the politician to obtain


```python
# Setting bounds and initial guess
# Tax rates cannot be higher than 100 pct., kappa cannot be higher than max(l)*max(w)
bounds_tax = ((0,1),(0,1),(0,1.5)) 
initval = [0.4,0.1,0.4]

# Solving by calling the objective function
sol_opt_tax = optimize.minimize(inauguralproject.obj_func, initval, method='SLSQP',bounds=bounds_tax)

# Unpack solution
tau0_opt = sol_opt_tax.x[0]
tau1_opt = sol_opt_tax.x[1]
kappa_opt = sol_opt_tax.x[2]

print(f'Optimal tau0 is {tau0_opt:.3f}, optimal tau1 is {tau1_opt:.3f} and optimal kappa is {kappa_opt:.3f}')
print(f'Total tax revenue in this case will be {inauguralproject.tax_rev(0.1,1,10,tau0_opt,tau1_opt,kappa_opt):.3f}')
```

    Optimal tau0 is 0.914, optimal tau1 is 0.000 and optimal kappa is 0.000
    Total tax revenue in this case will be 50.551


# Conclusion

We have constructed a function that maximizes the consumer problem. We have further computed a function that can return the total tax revenue and which futrher allows ud to adjust the level of $\epsilon$.

Finally we have helped the politician by suggesting the values of $\tau_{0},\,\tau_{1}$ and $\kappa$, which yields the expected taxrevenue of 50.551.




