Instructions
Objective
Calculate the total expenses for a group of individuals from multiple files, convert all amounts to a target currency (e.g., CNY) using historical exchange rates from a specific date, and output a structured JSON report.
Core Workflow
- •Identify Inputs: Determine the target currency, the historical date for exchange rates, the list of individuals, and the location of their expense files (CSV/JSON). The user may provide this explicitly or it may need to be inferred from the workspace.
- •Read Data: List and read all relevant expense files from the workspace. Files are typically CSVs with columns for
Date,Activity/Description,Cost/Amount, andCurrency, or similar variations. - •Fetch Exchange Rates: Use the Yahoo Finance tool (
yahoo-finance-get_stock_price_by_date) to get the closing exchange rates for the required currency pairs (e.g.,USDCNY=X,EURCNY=X) on the specified historical date. For indirect pairs (e.g., TRY/CNY), you may need to fetch a cross-rate (e.g.,TRYUSD=X) and calculate the target rate. - •Parse & Aggregate: For each individual's file:
- •Parse the data, summing amounts by currency (USD, EUR, TRY, CNY, etc.).
- •Convert each currency sum to the target currency using the fetched rates.
- •Calculate the individual's total in the target currency.
- •Calculate Grand Total: Sum all individual totals.
- •Generate Output: Create or update a specified JSON file (e.g.,
calculation.json) with the exchange rates used and each individual's total in the target currency, along with the grand total. Format numbers appropriately (e.g., rounded to 2 decimal places).
Key Considerations & Edge Cases
- •File Format Variability: Expense files may have different column names, structures, or delimiters. Be prepared to handle variations like
CostvsAmount, or files where costs are spread across multiple currency columns. - •Missing Direct Rates: If a direct exchange rate pair (e.g.,
TRYCNY=X) is not available, you must calculate it using a common intermediary (e.g.,TRYUSD=XandUSDCNY=X). - •Date Handling: The exchange rate date is critical. Ensure the correct date is used for the
yahoo-finance-get_stock_price_by_datecall. Use thecloseprice for conversion. - •Error Handling: If a file cannot be read or a rate cannot be fetched, note the issue and proceed if possible, or ask for clarification.
- •Calculation Verification: For complex sums, consider writing a temporary Python script to perform the arithmetic and verify totals, then clean it up.
Typical Tool Sequence
- •
filesystem-list_directory- Explore the workspace. - •
filesystem-read_multiple_files/filesystem-read_file- Load expense data. - •
yahoo-finance-get_stock_price_by_date- Fetch historical FX rates. - •
terminal-run_command- Optionally run a Python script for accurate bulk calculations. - •
filesystem-write_file- Write the final JSON report.
Output
The primary output is a JSON file (e.g., calculation.json) populated with keys for exchange rates and individual/group totals in the target currency. Provide a concise summary to the user.