gw2 flipping optimizer
🚀 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
- Real-time view of current buy orders, sell orders, and delivery box
- Calculates total capital deployed across all positions
- Fetches data directly from GW2 API
2. Transaction Data Collection
- Automated daily scraping of completed transactions via GW2 API
- Tracks: item, quantity, price, time placed, time filled
- Accumulates historical data for model training
- Can be automated via GitHub Actions for hands-free data collection
3. Fill Probability Models
Uses Weibull survival analysis to model "time until item sells":
- Fits Weibull distribution per item based on historical sell times
- Accounts for item-specific characteristics (liquidity, price point, market depth)
- Calculates P(item sells within T days) for any time horizon
- Handles censored data (items not yet sold)
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
- Backend: Flask
- Data: SQLite (optional, for historical tracking), CSV files
- Stats/ML: lifelines (Weibull models), scipy/pulp (LP optimization)
- API: GW2 official API (transactions, prices, items)
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
-
Create
.envfile with your GW2 API key:GW2_KEY=your-api-key-here -
Install dependencies:
bash pip install flask requests python-dotenv lifelines pandas numpy -
Run the dashboard:
bash python tp.py -
Collect daily transaction data:
bash python fetch_transaction_history.py
Future Enhancements
- Multi-user support (aggregate data across multiple traders)
- item discovery from public sources (GW2BLTC etc.)
- Risk modeling (volatility, undercut probability)
- closer integration with gw2efficiency for additional insights, such as tracking inventory across all characters
- Native app
License
GPL-3.0
This tool is for educational and personal use. Trading involves risk. Past performance does not guarantee future results.