Post #9 Companion — The CFO & AI Series

The Agent That Catches the Rate Move
Before Month-End Does

A small script that reads open FX positions and flags anything drifting past a set threshold — before month-end close finds it for you.

📄 Boris Dračka · ⏱ 4 min read · 📦 Code on GitHub

This is a personal, non-commercial side project I built to learn — not a product or service, and not connected to any company I work with.

6 Open positions in the sample data
2 Flagged past a ±2% threshold
0 API keys or live accounts required
The blind spot
Why the loss stays invisible until close

Post #9 walked through why an FX loss stays invisible until month-end close: an invoice gets booked at one rate, on one day, and nothing re-checks that rate again until the payment lands and someone reconciles it, weeks later.

This script is the small, personal experiment I put together to see what a daily check would actually need to compute. It doesn't trade anything and doesn't touch a real account — it just reads a list of open positions and does the one comparison nobody runs until close.

"None of this needs to be complicated. It just needs to run before the rate has finished moving, not after."


What the agent sees
Every open position, checked against today's rate
It reads a CSV of open positions — invoices billed in a foreign currency that haven't settled yet — and flags anything past a set variance since it was booked.
fx_positions.csv — Variance Check Sample run
−€4,622.49 Net unrealized variance
6 Positions checked
2 Flagged (±2.0% threshold)
ID Client Pair Amount Booked Current Variance Flag
FX-01 Iota Digital EUR/USD 95,000 1.0750 1.1100 −€2,786.51 ⚠ Flag
FX-05 Xi Manufacturing EUR/USD 61,000 1.0800 1.1150 −€1,772.96 ⚠ Flag
FX-04 Nu Consulting EUR/CHF 27,000 0.9550 0.9700 −€437.20 Clear
FX-02 Kappa Logistics EUR/GBP 42,000 0.8600 0.8550 +€285.60 Clear

Real output from running the script below against the sample CSV, threshold set to ±2.0% — see the full run further down.


How it works
5 steps. One CSV. No live connection.
Nothing here needs an API key or a real account — it's a calculation, run against sample data.
1
📥
Load open positions
Reads the CSV: position ID, client, currency pair, invoiced amount, and the rate it was booked at.
CSV input · no API required
2
🔁
Apply a current rate
For each position, compares the booked rate against a current rate you supply for that pair.
Manual or fed-in current rate
3
🧮
Calculate the variance
Works out the EUR value at both rates, and the difference — in euros and as a percentage.
EUR value = amount ÷ rate
4
🚩
Flag past the threshold
Anything beyond a configurable percentage (2% by default) gets flagged for a second look.
Default threshold: ±2.0%
5
🖨️
Print the report
Outputs a sorted table plus a plain-language summary of what's flagged and why.
Terminal output · no dashboard

Try it yourself
You need Python. That's it.
No API keys, no live trading connection — just a CSV of your own open positions.
1
Clone the repository
terminal
# Clone the repo
git clone https://github.com/LuliBobo/cfo-agents.git
cd cfo-agents
2
Add your open positions
data/fx_positions.csv
# position_id,client,currency_pair,amount_foreign,booked_rate,current_rate,invoice_date
FX-01,Iota Digital,EUR/USD,95000,1.0750,1.1100,2026-07-15
FX-02,Kappa Logistics,EUR/GBP,42000,0.8600,0.8550,2026-07-22
3
Run it
terminal
python fx_monitor_agent.py data/fx_positions.csv --threshold 2.0
4
What you get
output
================================================================
  FX Monitoring Agent — Open Position Check
================================================================

[Step 1] Loaded 6 open position(s) from CSV
[Step 2] Comparing booked rate vs current rate for each position
[Step 3] Flagging anything past ±2.0% variance

FX-01  Iota Digital      EUR/USD  1.0750  1.1100  −2,786.51  −3.15%  ⚠ FLAG
FX-05  Xi Manufacturing  EUR/USD  1.0800  1.1150  −1,772.96  −3.14%  ⚠ FLAG

[Step 4] 2 of 6 position(s) flagged
[Step 5] Net unrealized FX variance: €−4,622.49

Under the hood
No infrastructure. No API keys.

📄 Data source

A plain CSV of open positions. Export it from anywhere or type it by hand.

fx_positions.csv → Python

🐍 Calculation

Standard-library Python — no external packages, no API keys required to run it.

python3 fx_monitor_agent.py

🎚️ Threshold

A configurable percentage decides what gets flagged versus what's normal noise.

--threshold 2.0

🔒 No live connection

Nothing here touches a real account, a bank feed, or a trading platform — sample data only.

0 API keys

Get the full
source code

The FX Monitoring Agent lives in the same personal, non-commercial repository as the earlier demos in this series.

github.com/LuliBobo/cfo-agents

What's in the repository

  • fx_monitor_agent.py — the full script
  • data/fx_positions.csv — sample data to test immediately
  • Plus the CFO Report Agent (Post #2) and Invoice Agent (Post #3) in the same repo