Skip to content

Commit

Permalink
Merge pull request #372 from jdebacker/inflation_effects
Browse files Browse the repository at this point in the history
Updates to output, remove exception
  • Loading branch information
jdebacker committed Jul 25, 2022
2 parents a5ee743 + d06a045 commit 39be545
Show file tree
Hide file tree
Showing 15 changed files with 1,179 additions and 1,180 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -55,4 +55,4 @@ Results will change as the underlying models improve. A fundamental reason for a


## Citing the Cost-of-Capital-Calculator Model
Cost-of-Capital-Calculator (Version 1.2.10)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator
Cost-of-Capital-Calculator (Version 1.2.11)[Source code], https://github.com/PSLmodels/Cost-of-Capital-Calculator
9 changes: 1 addition & 8 deletions ccc/calcfunctions.py
Expand Up @@ -46,7 +46,6 @@ def update_depr_methods(df, p, dp):
'ADS_life']
df.loc[df['system'] == 'GDS', 'Y'] = df.loc[df['system'] == 'GDS',
'GDS_life']
df.to_csv('check_of_merge.csv')
return df


Expand Down Expand Up @@ -159,6 +158,7 @@ def npv_tax_depr(df, r, pi, land_expensing):
idx = df['asset_name'] == 'Inventories'
df.loc[idx, 'z'] = 0.0 # not sure why I have to do this with changes
z = df['z']

return z


Expand Down Expand Up @@ -187,13 +187,6 @@ def eq_coc(delta, z, w, u, inv_tax_credit, pi, r):
rho = (((r - pi + delta) / (1 - u)) *
(1 - inv_tax_credit - u * z) + w - delta)

if ENFORCE_CHECKS and np.any(rho <= 0):
print('Error raised')
err = ('The cost of capital is less than or equal to zero in ' +
'at least one case. Please try alternative parameter ' +
'values to ensure a cost of capital that is positive.')
raise RuntimeError(err)

return rho


Expand Down
15 changes: 11 additions & 4 deletions ccc/calculator.py
Expand Up @@ -206,8 +206,14 @@ def calc_by_asset(self, include_inventories=True,
major_asset_df['major_asset_group']
major_asset_df['asset_name'] = major_asset_df['major_asset_group']
major_asset_df = self.calc_other(major_asset_df)
# Can put some if statements here if want to exclude land/inventory/etc
overall_df = pd.DataFrame(self.__assets.df.groupby(
# Drop land and inventories if conditions met
df1 = self.__assets.df
if not include_land:
df1.drop(df1[df1.asset_name == 'Land'].index, inplace=True)
if not include_inventories:
df1.drop(df1[df1.asset_name == 'Inventories'].index,
inplace=True)
overall_df = pd.DataFrame(df1.groupby(
['tax_treat']).apply(self.__f)).reset_index()
overall_df['major_asset_group'] = 'Overall'
overall_df['minor_asset_group'] = 'Overall'
Expand Down Expand Up @@ -1761,7 +1767,7 @@ def data_year(self):

def __f(self, x):
'''
Private method. A fuction to compute sums and weighted averages
Private method. A function to compute sums and weighted averages
from a groubpy object.
Args:
Expand All @@ -1780,6 +1786,7 @@ def __f(self, x):
d['z_mix'] = wavg(x, 'z_mix', 'assets')
d['z_d'] = wavg(x, 'z_d', 'assets')
d['z_e'] = wavg(x, 'z_e', 'assets')
d['Y'] = wavg(x, 'Y', 'assets')

return pd.Series(d, index=['assets', 'delta', 'rho_mix', 'rho_d',
'rho_e', 'z_mix', 'z_d', 'z_e'])
'rho_e', 'z_mix', 'z_d', 'z_e', 'Y'])
5 changes: 3 additions & 2 deletions ccc/paramfunctions.py
Expand Up @@ -295,7 +295,8 @@ def calc_r(u, nominal_int_rate, inflation_rate, ace_int_rate, f,
Compute firm nominal discount rates
..math::
r_{m,j} = f_{m,j}\[i(1-u_{j}) - \pi\] + (1-f_{m,j})E_{j} + \pi
r_{m,j} = f_{m,j}\[i(1-(1-i_{hc})u_{j})] + (1-f_{m,j})
(E_{j} + \pi - ACE_{j})
Args:
u (array_like): tax rate on business entity income
Expand All @@ -313,7 +314,7 @@ def calc_r(u, nominal_int_rate, inflation_rate, ace_int_rate, f,
'''
r = (
f * (nominal_int_rate * (1 - (1 - int_haircut) * u)) + (1 - f) *
(E + inflation_rate - E * ace_int_rate * ace)
(E + inflation_rate - ace_int_rate * ace)
)

return r
Expand Down
2 changes: 1 addition & 1 deletion ccc/tests/run_ccc_asset_output.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ccc/tests/run_ccc_industry_output.json

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions ccc/tests/test_calcfunctions.py
Expand Up @@ -272,14 +272,6 @@ def test_eq_coc(delta, z, w, u, inv_tax_credit, pi, r, expected_val):
assert(np.allclose(test_val, expected_val))


def test_eq_coc_exception1():
'''
Raise exception for non-positive cost of capital
'''
with pytest.raises(RuntimeError):
assert cf.eq_coc(0.05, 1.0, 0.0, 0.28, 1.0, 0.02, 0.04)


u = np.array([0.3, 0, 0.3, 0, 0.3, 0])
phi = np.array([0.33, 0.33, 0.33, 0.33, 0.33, 0.33])
Y_v = np.array([8, 8, 8, 8, 8, 8])
Expand Down
10 changes: 8 additions & 2 deletions ccc/tests/test_calculator.py
Expand Up @@ -90,15 +90,21 @@ def test_calc_all():
assert ('eatr_mix' in calc_all_df.keys())


def test_calc_by_asset():
@pytest.mark.parametrize('include_land,include_inventories',
[(False, False), (True, True)],
ids=['No land or inv', 'Both land and inv'])
def test_calc_by_asset(include_land, include_inventories):
'''
Test calc_by_asset method
'''
assets = Assets()
p = Specification()
dp = DepreciationParams()
calc = Calculator(p, dp, assets)
asset_df = calc.calc_by_asset()
asset_df = calc.calc_by_asset(
include_land=include_land,
include_inventories=include_inventories
)
assert ('major_asset_group' in asset_df.keys())


Expand Down

0 comments on commit 39be545

Please sign in to comment.