Baldros commited on
Commit
303f84b
·
verified ·
1 Parent(s): 0596b96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py CHANGED
@@ -150,6 +150,68 @@ def get_index_price(index: str) -> str:
150
  return f"The latest closing price for {index} is {price:.2f}."
151
  except Exception as e:
152
  return f"Error fetching index price: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  final_answer = FinalAnswerTool()
155
 
 
150
  return f"The latest closing price for {index} is {price:.2f}."
151
  except Exception as e:
152
  return f"Error fetching index price: {str(e)}"
153
+
154
+ @tool
155
+ def get_interest_rates() -> str:
156
+ """
157
+ Fetches the latest Selic, CDI, and IPCA rates.
158
+
159
+ Returns:
160
+ The latest values for Brazil's key interest rates.
161
+ """
162
+ import requests
163
+ try:
164
+ response = requests.get("https://api.bcb.gov.br/dados/serie/bcdata.sgs.11/dados/ultimos/1?formato=json") # SELIC
165
+ selic = response.json()[0]['valor']
166
+
167
+ response = requests.get("https://api.bcb.gov.br/dados/serie/bcdata.sgs.12/dados/ultimos/1?formato=json") # CDI
168
+ cdi = response.json()[0]['valor']
169
+
170
+ response = requests.get("https://api.bcb.gov.br/dados/serie/bcdata.sgs.433/dados/ultimos/1?formato=json") # IPCA
171
+ ipca = response.json()[0]['valor']
172
+
173
+ return (f"Selic atual: {selic}% ao ano\n"
174
+ f"CDI atual: {cdi}% ao ano\n"
175
+ f"IPCA acumulado: {ipca}%")
176
+ except Exception as e:
177
+ return f"Erro ao buscar taxas de juros: {str(e)}"
178
+
179
+
180
+ @tool
181
+ def compare_fixed_income(amount: float, period: int, cdi_percentage: float) -> str:
182
+ """
183
+ Compares the return of a CDB vs. savings over a given period.
184
+
185
+ Args:
186
+ amount: The initial investment amount.
187
+ period: The investment duration in months.
188
+ cdi_percentage: The CDB return as a percentage of the CDI.
189
+
190
+ Returns:
191
+ The final amount in CDB vs. savings.
192
+ """
193
+ import requests
194
+ try:
195
+ # Buscar CDI atual
196
+ response = requests.get("https://api.bcb.gov.br/dados/serie/bcdata.sgs.12/dados/ultimos/1?formato=json")
197
+ cdi = float(response.json()[0]['valor']) / 100
198
+
199
+ # Poupança rende 70% da Selic quando Selic > 8.5%
200
+ response = requests.get("https://api.bcb.gov.br/dados/serie/bcdata.sgs.11/dados/ultimos/1?formato=json")
201
+ selic = float(response.json()[0]['valor']) / 100
202
+ poupanca_rendimento = 0.7 * selic if selic > 0.085 else 0.005
203
+
204
+ # Calcular rendimentos
205
+ cdb_final = amount * ((1 + (cdi * cdi_percentage / 100)) ** (period / 12))
206
+ poupanca_final = amount * ((1 + poupanca_rendimento) ** (period / 12))
207
+
208
+ return (f"Após {period} meses:\n"
209
+ f"CDB ({cdi_percentage}% do CDI): R$ {cdb_final:.2f}\n"
210
+ f"Poupança: R$ {poupanca_final:.2f}")
211
+ except Exception as e:
212
+ return f"Erro ao calcular rendimentos: {str(e)}"
213
+
214
+
215
 
216
  final_answer = FinalAnswerTool()
217