2025-11-07 01:24:43 +08:00
..
2025-11-01 20:54:13 +08:00
2025-05-27 21:57:37 +09:00
2025-07-09 10:35:28 +08:00
2025-05-15 13:08:38 +00:00
2025-10-14 09:49:11 +00:00
2025-08-14 21:35:22 +08:00
2025-05-27 14:22:26 +00:00
2025-05-27 14:22:26 +00:00
2025-05-27 14:22:26 +00:00
2025-05-13 16:36:58 +00:00
2025-05-14 04:58:31 +00:00
2025-11-07 01:24:43 +08:00
up
2025-05-19 07:13:26 +00:00
2025-05-19 06:56:42 +00:00
2025-10-02 04:58:57 +00:00
2025-10-14 09:49:11 +00:00
2025-10-14 09:49:11 +00:00
2025-10-14 09:49:11 +00:00
2025-10-17 21:36:27 +08:00
2025-11-01 19:07:18 +08:00
2025-07-09 17:30:49 +08:00

Trade Analysis Tools

This directory contains tools for analyzing backtest results from Freqtrade.

tradestocsv.py

Converts Freqtrade backtest JSON results to CSV and enhanced JSON formats with position adjustment information.

Features:

  • Converts backtest results to CSV format for easy analysis
  • Enhances JSON output with detailed position entry information
  • Calculates average entry prices, initial entry costs, and adjustment costs
  • Handles both real order data and fallback scenarios

Fields Added:

  1. entry_orders_count: Number of entry orders for the trade
  2. adjustments_count: Number of position adjustments (entry_orders_count - 1)
  3. avg_entry_price: Average price across all entry orders
  4. initial_entry_cost: Cost of the initial entry order
  5. total_adjustment_cost: Total cost of all adjustment orders
  6. entries: Detailed array of all entry orders with:
    • order_index: Order sequence number (0 for initial)
    • timestamp: Order execution time (millisecond timestamp)
    • price: Order execution price
    • amount: Order quantity
    • cost: Order total cost
    • order_type: 'initial' or 'adjustment'

Usage:

cd tools
python tradestocsv.py

# Run analysis script (including timing analysis)
python analyze_entry_timing.py

The script will automatically:

  1. Find the largest backtest result JSON file in the ../result directory
  2. Convert it to both CSV and enhanced JSON formats
  3. Save the outputs to ../result/backtest_trades.csv and ../result/backtest_trades.json

Environment Variables:

  • STRATEGY_NAME: Strategy name to analyze (default: 'FreqaiPrimer')

Output Format:

The CSV and JSON files will contain all original trade information plus the additional fields listed above for comprehensive trade analysis.

Explanation of Position Adjustment Timing Issues

Analysis reveals the following characteristics in current backtest data:

  1. Only two orders per trade: One entry order and one exit order
  2. Identical open and close times: All trades have exactly the same open_date and close_date
  3. No actual position adjustments: The adjustments_count field is always 0, indicating no position adjustment behavior

This means there are no actual position adjustment time intervals to analyze in the current data. If position adjustment timing strategy analysis is needed, the corresponding position adjustment functionality should be enabled in backtesting to generate data containing multiple entry operations.

Timestamp handling notes:

  • The script prioritizes using the order_filled_timestamp field from orders
  • If not available, it falls back to the timestamp field
  • Finally falls back to the trade's open_date field
  • All timestamps are stored in millisecond format for precise time calculations