gw2 flipping optimizer

🔗View on GitHub

🚀 Launch Notebook

📄 README

GW2 Flipping Optimizer

A data-driven trading tool for Guild Wars 2's Trading Post that uses survival analysis and linear programming to optimize portfolio allocation.

What This Does

Problem: Managing a large trading portfolio (10,000+ gold across hundreds of items) becomes overwhelming. Which items should you buy? How much of each? The market has thousands of opportunities but limited capital and time.

Solution: This tool analyzes your historical transaction data to model item sell rates, then uses optimization to recommend the best allocation of your budget for maximum expected profit within your time horizon.

Features

1. Trading Dashboard

2. Transaction Data Collection

3. Fill Probability Models

Uses Weibull survival analysis to model "time until item sells":

Why Weibull? - Flexible shape parameter captures different sell dynamics (fast movers vs slow movers) - Standard approach in survival analysis / reliability engineering - Works well with sparse data

Current limitation: Model doesn't yet properly account for quantity effects (1 unit vs 100 units). Solutions being explored: - Weibull regression with quantity as covariate - Rate-based modeling (units sold per day) - Stratification by batch size

4. Portfolio Optimizer

Linear programming formulation to maximize expected profit:

Decision Variables: Maximum margin in a time frame

Objective Function: Maximize: Σ (sell_price - buy_price) × quantity × P(fill within T days)

Constraints: - Budget constraint: Σ (buy_price × quantity) ≤ available_gold - Transaction limit: number of distinct items ≤ max_transactions (to limit clicking) - Per-item caps: quantity_i ≤ max_quantity_i (based on market depth) - Minimum margin: only consider items with (sell_price - buy_price) / buy_price ≥ min_margin - Minimum fill probability: only consider items with P(fill) ≥ min_fill_prob

Output: "Buy 33 Zhed's Coats, 40 Impalers, 1 Crustacea, 400 Sigils of Force" with expected profit and capital required.

Technical Stack

Project Structure

gw2-flipping-optimizer/ ├── tp.py # Flask app (dashboard) ├── fetch_transaction_history.py # Daily data collection script ├── fill_model_v0_1.ipynb # Jupyter notebook for model development ├── data/ │ ├── buy_orders/ # Historical buy transaction data │ ├── sell_orders/ # Historical sell transaction data │ └── item_fill_models.json # Fitted Weibull parameters per item ├── templates/ # HTML templates for dashboard ├── static/ # CSS/JS for frontend └── .github/workflows/ # GitHub Actions for automation

Current Status

Completed: - Transaction data collection pipeline - Weibull model fitting per item - Fill probability calculator - Trading dashboard (current positions)

In Progress: - Quantity modeling (how batch size affects fill time) - LP optimizer implementation

TODO: - Fetch live market prices from GW2 API - Integrate optimizer into Flask dashboard - Add visualization of historical performance - Buy fill probability models (time until buy order fills)

Data Requirements

To build accurate models, the tool needs: - Minimum 3 completed transactions per item to fit a Weibull distribution - Varied quantity sizes (1 unit, 10 units, 100 units) to model batch effects - 30+ days of data for stable parameter estimates

With only 50 transactions per day from the API, it takes time to accumulate sufficient data. This is a long-term tool that improves as you trade.

Why This Approach?

Alternatives considered: - Intuition-based trading: Works at small scale, doesn't scale to 200+ items - Simple ranking by margin: Ignores liquidity and capital efficiency - Monte Carlo simulation: Overkill for this problem, slower to compute - Bayesian models: Better for uncertainty quantification, but Weibull is simpler and works well with limited data - Deep learning (VAEs, etc.): Unnecessary complexity for 1D time-series data

Survival analysis + LP optimization balances simplicity, interpretability, and effectiveness for this specific use case.

Trading Performance

Current portfolio: ~14,000 gold actively trading across 200+ items, placing me in the top 400 traders globally by volume. The goal is to systematically scale these returns by removing manual bottlenecks.

Setup

  1. Create .env file with your GW2 API key: GW2_KEY=your-api-key-here

  2. Install dependencies: bash pip install flask requests python-dotenv lifelines pandas numpy

  3. Run the dashboard: bash python tp.py

  4. Collect daily transaction data: bash python fetch_transaction_history.py

Future Enhancements

License

GPL-3.0


This tool is for educational and personal use. Trading involves risk. Past performance does not guarantee future results.