# Quant Trading Foundation: The Four Pillars

*A distillation of Mark's quant curriculum: the mechanical edge and philosophy.*

## 1. Thinking like a Trader
- **Primary Goal:** To consistently compound wealth with an edge while protecting the portfolio. It's not about making 200% a month (which leads to ruin); it's about beating the S&P 500 CAGR or beating its drawdowns (aiming for 10-30% max drawdown so you can comfortably sleep at night).
- **Market Regimes:** Markets cycle between *Trending* and *Range-bound (Choppy)*.
  - *Trending strategies* (Moving Averages, Breakouts) work in trends but suffer in chop. They have lower win rates (20-40%) but high risk/reward ratios (wins are big).
  - *Mean-reversion strategies* (RSI, Bollinger Bands, oversold conditions) work in range-bound markets or during extreme market anomalies (e.g. panic-selling). They have higher win rates (60-80%) but smaller risk/reward ratios.
- **Edge through Diversification:** Running *both* a trend-following system and a mean-reversion system simultaneously smooths the equity curve.
- **Emotional Discipline:** Have a "poker face." Losses are an expected, mechanical cost of doing business. As long as the backtest works, temporary drawdowns shouldn't shake you. Stick to high-liquidity assets (large caps, S&P 500) to avoid slippage and micro-cap ruin.

## 2. Thinking like a Mathematician
- **Position Sizing is Everything:** Risking 50% of your account size guarantees ruin (8 consecutive losses wipe you out). Risking **1% to 5%** per trade means a 20-trade losing streak only dents your portfolio slightly. Survival mathematically guarantees long-term compounding.
- **The Law of Large Numbers:** The 50/50 probability doesn't mean you win every other trade; it means you win 50% over an *infinite* sample. In a small sample, you can and will have losing streaks. Your position sizing must be small enough to survive these normal statistical streaks.
- **Exits > Entries:** We obsess over finding the perfect entry, but tweaking the exit (e.g., exiting at the end of the day or when closing above an MA) drastically shifts backtest outcomes.
- **Systematic Portfolio Testing:** By limiting position size to 1%, you can simultaneously test a basket of 10-100 stocks. The few massive winners in a diversified basket (e.g., a stock that goes 10x) easily cover the small 1% stop-outs of the losers.

## 3. Thinking like a Coder
- **The Right Tool:** TradingView is free and simple for single assets. Python is highly customizable but complex. **AmiBroker** is ideal for quant traders because it allows portfolio-level backtesting across hundreds of stocks at once (e.g. testing the S&P 500 basket), Walk-Forward analysis, and Monte Carlo simulations with a click.
- **The Coding Process:**
  1. Brainstorm ideas daily.
  2. Write them down in **plain English** (e.g. "Buy if close is above 200 MA AND RSI is below 30").
  3. Translate them into code. Start very simple (e.g., MA crossover) and incrementally add logic (e.g., trailing stops).
- **Coding Efficiency:** Don't hardcode variables. Instead of `RSI(2)`, assign `N=2` and use `RSI(N)`. This lets you easily optimize the `N` variable later during backtesting.
- **Perseverance:** Syntax errors are common (missing semicolons, misspelled variables). Google is your best friend. Coding is simply a vehicle to apply the trader's edge mathematically.

## 4. Thinking like a Quant
- **The Synthesis:** A Quant combines the Trader (strategy), the Mathematician (risk management), and the Coder (execution and backtesting) into one holistic pipeline.
- **Regime Filters:** Use structural rules to protect capital. For example, a "Long Only" strategy might require the broader index (e.g., S&P 500) to be above its 200-day moving average. If it drops below, you close positions to avoid choppy recessionary environments.
- **Optimization:** In a platform like AmiBroker, you can run thousands of combinations to find the optimal parameters (e.g., discovering that a 62-day MA crossing a 90-day MA produces better risk-adjusted returns than standard defaults).
- **Walk-Forward Analysis (Avoiding Curve Fitting):**
  - **In-Sample Data:** Optimize parameters on a historical chunk (e.g., 2000–2010). If it survives the Dot-Com Bubble and 2008 Financial Crisis, note the returns and drawdowns.
  - **Out-of-Sample Data:** Test those exact parameters on unseen data (e.g., 2010–2020). 
  - **The Golden Rule:** If the out-of-sample performance significantly degrades or looks completely different, the strategy was "curve-fitted" (over-optimized) and should be discarded. A true edge persists across unknown data.
- **Implementation Reality:** Factor in slippage (entering at the open vs. close) and execution limits. Decide if the system will be manually traded (e.g., limiting to 10-20 large cap ETFs) or automated (e.g., interactive brokers API trading a 500-stock universe). Automation scales but introduces infrastructure risk.