A Python Flask web application that processes FX trading data from the AM sheet of "FX October PnL updated.xlsx" and provides real-time profit calculations with the ability to adjust buy and sell rates.
✅ Real-time Calculations - Updates profit calculations instantly as you adjust rates ✅ Rate Adjustments - Modify buy and sell rates with 4 decimal precision ✅ Trade Type Detection - Automatically identifies SELL or BUY trades based on values ✅ Mark Up Display - Shows the spread between your rate and bank rate ✅ Total Profit Aggregation - Displays total profit across all 22 trading days ✅ Reset Functionality - Restore all rates to original values ✅ Visual Indicators - Color-coded profit display (green for positive, red for negative)
- Python 3.7 or higher
- Flask
- openpyxl
- numpy
- Navigate to the project directory:
cd C:\Users\Admin\Desktop\MYProject\FXSimulation- Install required packages (if not already installed):
python -m pip install flask openpyxl numpypython run.pyThis will start the Flask server and automatically open your browser to http://localhost:5000
python app.pyThen open your browser and navigate to http://localhost:5000
-
View Trading Data: The table displays all 22 trading days with their rates and profit calculations
-
Adjust Buy Rate:
- Click the "Buy Rate" input field for any trading day
- Enter a new rate (up to 4 decimal places)
- Press Enter or click away to apply the change
- The profit calculation updates in real-time
-
Adjust Sell Rate:
- Click the "Sell Rate" input field for any trading day
- Enter a new rate (up to 4 decimal places)
- Press Enter or click away to apply the change
- The profit calculation updates immediately
-
Reset All Rates:
- Click the "Reset All Rates" button
- Confirm the action in the dialog
- All rates return to their original values and profit recalculates
Profit = Buy Value - Sell Value - Bank Value
Where:
- Buy Value = Buy Rate × Buy Amount
- Sell Value = Sell Rate × Sell Amount
- Bank Value = Bank Rate × Bank Amount (Fixed - cannot be adjusted)
IF Sell Value > Buy Value
THEN Trade Type = "SELL"
ELSE
Trade Type = "BUY"
IF Trade Type = "SELL"
THEN Mark Up = Sell Rate - Bank Rate
ELSE (Trade Type = "BUY")
THEN Mark Up = Buy Rate - Bank Rate
The sum of all daily profits for the 22 trading days (Sep 30 - Oct 30, 2025)
- File: FX October PnL updated.xlsx
- Sheet: AM (AM session data only)
- Trading Days: 22 days
- Date Range: October 1-30, 2025
app.py- Main Flask application with calculation logicrun.py- Simple runner script to start the applicationtemplates/index.html- Web interface with styling and JavaScriptinspect_excel.py- Utility to inspect Excel file structuretest_calculator.py- Unit test for the calculatorfx_profit_calc_logic.md- Detailed documentation of calculation logic
If port 5000 is already in use, modify the port in app.py or run.py:
app.run(debug=True, port=5001) # Use port 5001 insteadEnsure the Excel file is in the same directory as the Python files:
C:/Users/Admin/Desktop/MYProject/FXSimulation/FX October PnL updated.xlsx
Install missing packages:
python -m pip install flask openpyxl numpy- Backend: Python Flask (RESTful API)
- Frontend: HTML5, CSS3, Vanilla JavaScript
- Data Processing: openpyxl for Excel file reading
- Calculation Engine: Native Python with numpy support
- Real-time Updates: AJAX/Fetch API for seamless data updates
GET /- Main application pageGET /api/get-data- Retrieve current data and calculationsPOST /api/update-rate- Update a buy or sell ratePOST /api/reset- Reset all rates to original values
- Chrome/Chromium (Latest)
- Firefox (Latest)
- Safari (Latest)
- Edge (Latest)
- Bank rates are fixed and cannot be adjusted
- All amounts (USD) are fixed per trading day
- Rates can be adjusted with up to 4 decimal places precision
- All calculations are done on the server side for accuracy