Skip to content

Commit

Permalink
Add description in the IRF section
Browse files Browse the repository at this point in the history
  • Loading branch information
tuduun committed Mar 22, 2024
1 parent 4997871 commit 501384e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/app/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@



def plot_irfs(irf, independent_var: str) -> None:
def plot_irfs(irf, independent_var: str, description: str) -> None:
"""
Plots impulse response functions (IRFs) showing the response of LAYOFFS to a shock in the specified independent variable.
Expand All @@ -17,6 +17,9 @@ def plot_irfs(irf, independent_var: str) -> None:
Returns:
None. The function directly renders the plot in a Streamlit application.
"""
st.write(" ")
st.write(f"**Graph for {independent_var}**")
st.write(description)
fig = irf.plot(impulse=independent_var, response='LAYOFFS', orth=True, subplot_params={'title': f'Response of LAYOFFS to a shock in {independent_var}'})
st.pyplot(fig)

Expand Down
11 changes: 9 additions & 2 deletions src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def main():

# Load the dataset for VAR

description = ["Inflation on Layoffs graph illustrates how a positive shock in inflation affects the number of layoffs. We can see that a positive shock in inflation decreases the number of layoffs until it hits 0 in the 6th month. This does not seem to match the hypothesis that I initially came up with.",
"Industrial production on Layoffs graph shows a positive shock in the industrial production decreases layoffs until it reached 0 in the 8th month. This result lines up with Hypothesis 2: An increase in Industrial Production decreases Layoffs. This makes economic sense because if there is more production, there is more workforce behind the produced goods.",
"Federal Funds Rate (aka Interest Rates) on Layoffs graph tells how the federal funds rate affects the number of layoffs. According to the graph, we can see a positive shock in federal funds, layoffs decrease until the 3rd month. My hypothesis disagrees with this result because in economic theory, at times when interest rates are high, people save more and consume as little as possible. Moreover, jobs will not be created due to the businesses not borrowing any money with high-interest rates to do more projects. Thus, it is intuitive to think that higher interest rates will lead to more layoffs due to the slowing down of the economy and the increase in borrowing of money for businesses makes it expensive to hire employees. Thus, the VAR IRF does not support the economic theory.",
"Economic Uncertainty Index on Layoffs graph illustrates how the U.S economic uncertainty index affects layoffs. The graph starts with a positive spike and is on the positive side until it hits 0 at around the 2nd period. This is in line with the economic theory that supports that businesses are cutting back on the workforce during economic challenging times. Moreover, after the 2nd period in the IRF graph, the response(layoffs) fluctuates above and below the zero line, which suggests the impact of layoffs changes over time. Thus, the VAR IRF result was consistent with the H4: Increase in Economic Uncertainty index increases Layoffs."
"Layoffs on Layoffs does not mean that much."
]

var_data = prepare_raw_data(load_data('src/data/macro_seasonal_variables_data.csv'))
data_df = difference_variables(var_data)
fitted_model, results_df = fit_var_model_and_select_lags(data_df,12)
Expand Down Expand Up @@ -56,8 +63,8 @@ def main():
st.title('Impulse response functions')
st.write('This section shows the response of layoffs to shocks in various economic indicators.')
independent_variables = ['INFLATION', 'D_INDPRO', 'FEDFUNDS', 'UNCERTAINTY', 'LAYOFFS']
for independent_vars in independent_variables:
plot_irfs(irf, independent_vars)
for i in range(len(independent_variables)-1):
plot_irfs(irf, independent_variables[i], description[i])

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def test_plot_irfs():
mock_irf.plot.return_value = mock_fig

independent_var = 'GDP'

description = "This is a test description."
# Patch the streamlit.pyplot function
with patch('app.display.st.pyplot') as mock_pyplot:
# Call the function with the mock IRF object and an independent variable
display.plot_irfs(mock_irf, independent_var)
display.plot_irfs(mock_irf, independent_var, description)

# Assert the IRF plot method was called correctly
mock_irf.plot.assert_called_once_with(impulse=independent_var, response='LAYOFFS', orth=True,
Expand Down

0 comments on commit 501384e

Please sign in to comment.