Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanramoscfa committed Jun 9, 2024
1 parent 3c9d9c6 commit f7e908a
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 240 deletions.
68 changes: 25 additions & 43 deletions examples/monetary_policy_rules/balanced_approach_rule.ipynb

Large diffs are not rendered by default.

104 changes: 44 additions & 60 deletions examples/monetary_policy_rules/monetary_policy_rules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
" rho=0.0,\n",
" apply_elb=False,\n",
" verbose=True,\n",
" include_ai_analysis=True\n",
" include_ai_analysis=False\n",
")"
]
},
Expand All @@ -146,33 +146,25 @@
"output_type": "stream",
"text": [
"\n",
"┌──────────────────────────────────────────────────────────────────────────────┐\n",
"│ Interest Rate Policy Estimates │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) 5.82% │\n",
"│ Balanced Approach Rule (BAR) 6.23% │\n",
"│ Balanced Approach Shortfalls Rule (BASR) 5.41% │\n",
"│ First Difference Rule (FDR) 5.76% │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Federal Funds Rate (FFR) 5.50% │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ As of Date June 08, 2024 │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ AI-Generated Policy Prescription │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Given the current estimates from the Taylor Rule (5.82%), Balanced │\n",
"│ Approach Rule (6.23%), Balanced Approach Shortfalls Rule (5.41%), and │\n",
"│ First Difference Rule (5.76%), it is evident that the appropriate │\n",
"│ Federal Funds Rate lies in a range slightly above the current rate of │\n",
"│ 5.5%. To align more closely with these indicators while supporting │\n",
"│ stable economic conditions, we recommend a cautious increase in the │\n",
"│ Federal Funds Rate to 5.75%. This adjustment will help address │\n",
"│ inflationary pressures while considering potential output shortfalls │\n",
"│ and maintaining a balanced approach to monetary policy. │\n",
"| |\n",
"│ *Generated with gpt-4o. Use with caution. ChatGPT can make mistakes. │\n",
"│ Check important info. │\n",
"└──────────────────────────────────────────────────────────────────────────────┘\n",
"┌───────────────────────────────────────────────────────────────────────────────────────┐\n",
"│ Interest Rate Policy Estimates │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) 5.82% │\n",
"│ Balanced Approach Rule (BAR) 6.23% │\n",
"│ Balanced Approach Shortfalls Rule (BASR) 5.41% │\n",
"│ First Difference Rule (FDR) 5.76% │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Federal Funds Rate (FFR) 5.50% │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ As of Date June 09, 2024 │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Policy Prescription │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) suggests raising the rate by 0.25%. │\n",
"│ Balanced Approach Rule (BAR) suggests raising the rate by 0.75%. │\n",
"│ Balanced Approach Shortfalls Rule (BASR) suggests maintaining the current rate. │\n",
"│ First Difference Rule (FDR) suggests raising the rate by 0.25%. │\n",
"└───────────────────────────────────────────────────────────────────────────────────────┘\n",
"\n"
]
}
Expand Down Expand Up @@ -424,38 +416,30 @@
"output_type": "stream",
"text": [
"\n",
"┌──────────────────────────────────────────────────────────────────────────────┐\n",
"│ Adjusted Interest Rate Policy Estimates │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) 5.53% │\n",
"│ Balanced Approach Rule (BAR) 5.57% │\n",
"│ Balanced Approach Shortfalls Rule (BASR) 5.49% │\n",
"│ First Difference Rule (FDR) 5.53% │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Federal Funds Rate (FFR) 5.50% │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Adjustment Parameters │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Effective Lower Bound (ELB) 0.12% │\n",
"│ Policy Inertia (Rho) 0.90 │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ As of Date June 08, 2024 │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ AI-Generated Adjusted Policy Prescription │\n",
"├──────────────────────────────────────────────────────────────────────────────┤\n",
"│ Based on the analysis of the adjusted monetary policy rules, which │\n",
"│ yield a range of suggested interest rates between 5.49% and 5.57%, it │\n",
"│ is evident that the current Federal Reserve rate of 5.5% aligns closely │\n",
"│ with these estimates. Considering our policy inertia parameter (rho = │\n",
"│ 0.9), the optimal approach is to maintain the Federal Reserve rate at │\n",
"│ its current level of 5.5%. This decision reflects the synthesis of │\n",
"│ balanced approaches and shortfall considerations, ensuring a measured │\n",
"│ and data-driven response to prevailing economic conditions while │\n",
"│ adhering to a stable monetary policy stance. │\n",
"| |\n",
"│ *Generated with gpt-4o. Use with caution. ChatGPT can make mistakes. │\n",
"│ Check important info. │\n",
"└──────────────────────────────────────────────────────────────────────────────┘\n",
"┌───────────────────────────────────────────────────────────────────────────────────────┐\n",
"│ Adjusted Interest Rate Policy Estimates │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) 5.53% │\n",
"│ Balanced Approach Rule (BAR) 5.57% │\n",
"│ Balanced Approach Shortfalls Rule (BASR) 5.49% │\n",
"│ First Difference Rule (FDR) 5.53% │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Federal Funds Rate (FFR) 5.50% │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Adjustment Parameters │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Effective Lower Bound (ELB) 0.12% │\n",
"│ Policy Inertia (Rho) 0.90 │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ As of Date June 09, 2024 │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Adjusted Policy Prescription │\n",
"├───────────────────────────────────────────────────────────────────────────────────────┤\n",
"│ Taylor Rule (TR) suggests maintaining the current rate. │\n",
"│ Balanced Approach Rule (BAR) suggests maintaining the current rate. │\n",
"│ Balanced Approach Shortfalls Rule (BASR) suggests maintaining the current rate. │\n",
"│ First Difference Rule (FDR) suggests maintaining the current rate. │\n",
"└───────────────────────────────────────────────────────────────────────────────────────┘\n",
"\n"
]
}
Expand Down
20 changes: 12 additions & 8 deletions pyeconomics/ai/monetary_policy_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import openai

from pyeconomics.api.openai_api import load_prompt
from pyeconomics.data.economic_indicators import EconomicIndicators
from pyeconomics.data.model_parameters import MonetaryPolicyRulesParameters


def monetary_policy_rules(
estimates: dict,
current_fed_rate: float,
ai_dict: dict = None,
indicators: EconomicIndicators,
params: MonetaryPolicyRulesParameters,
) -> str:
"""
Generate an AI-based analysis of the monetary policy rules calculation
Expand All @@ -19,13 +21,15 @@ def monetary_policy_rules(
Args:
estimates (dict): Dictionary containing the monetary policy rules
estimates.
current_fed_rate (float): The current Federal Funds Rate.
ai_dict (dict): Dictionary containing the AI-parameters.
indicators (EconomicIndicators): Instance containing economic
indicators.
params (MonetaryPolicyRulesParameters): Instance containing the policy
rule parameters.
Returns:
str: AI-generated analysis paragraph.
"""
if ai_dict['adjusted']:
if params.rho > 0.0 or params.apply_elb:
prompt_filepath = 'adjusted_monetary_policy_rules.txt'
else:
prompt_filepath = 'monetary_policy_rules.txt'
Expand All @@ -49,11 +53,11 @@ def monetary_policy_rules(
estimates['Balanced Approach Shortfalls Rule (BASR)'], 2),
first_difference_rule=round(
estimates['First Difference Rule (FDR)'], 2),
current_fed_rate=round(current_fed_rate, 2)
current_fed_rate=round(indicators.current_fed_rate, 2)
)

response = openai.chat.completions.create(
model=ai_dict['model'],
model=params.model,
messages=[
{"role": "system",
"content": "Act as the Federal Open Market Committee (FOMC) of "
Expand All @@ -62,7 +66,7 @@ def monetary_policy_rules(
"the growth of the United States money supply."},
{"role": "user", "content": prompt}
],
max_tokens=ai_dict['max_tokens']
max_tokens=params.max_tokens
)

analysis = response.choices[0].message.content.strip()
Expand Down
1 change: 1 addition & 0 deletions pyeconomics/data/model_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ class MonetaryPolicyRulesParameters:
include_ai_analysis: bool = False
max_tokens: int = 500
model: str = 'gpt-4o'
as_of_date: str = None
Loading

0 comments on commit f7e908a

Please sign in to comment.