QuantPro Week10 Complete
QuantPro Week10 Complete
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
QUANT
PRO
Advanced Quant Finance Course
WEEK 10 — Days 71 to 78 — THE ELITE LAYER
Day 71: Time Series Core (Stationarity, ADF, ARIMA) · Day 72: Cointegration Deep Dive (Kalman Filter) · Day
73: Advanced Portfolio Optimisation (Risk Parity, Black-Litterman) · Day 74: Market Microstructure · Day 75:
Execution Algorithms (VWAP/TWAP) · Day 76: Code Architecture · Day 77: Final System Part 1 · Day 78: Final
System Part 2 + SQL Master Guide + Max Output Tips
What Weeks 1-9 gave you. Week 10 adds the elite mathematical
A complete production quant system: live layer.
pipeline, ML alpha, options strategies, Time series stationarity, Kalman Filter
professional risk management, cloud cointegration, robust portfolio optimisation,
deployment, interview readiness, and a market microstructure, VWAP/TWAP
career plan. execution, SQL mastery, and the final
complete modular system. Plus the full SQL
guide and maximum-output tips that close
the course.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 1
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
QUANT PRO
Advanced Quant Finance Course
WEEK 10 — Days 71 to 78 — THE ELITE LAYER
Time Series · Cointegration + Kalman · Robust Portfolio Optimisation · Market Microstructure · VWAP/TWAP Execution
· Code Architecture · SQL Mastery · Final System
Week 10 is the content that separates a strong junior from a genuine quant practitioner. Every topic here is
tested in senior interviews at global firms — Jane Street, Citadel, WorldQuant — and used daily on
professional quant desks. Stationarity and ARIMA underpin all time-series modelling. The Kalman Filter is
the correct way to track a changing hedge ratio in pairs trading. Risk parity and Black-Litterman fix the
critical failures of basic Markowitz. Market microstructure explains why your live trades fill worse than your
backtest. VWAP and TWAP execution are how institutional desks minimise market impact on large orders.
The final days complete the modular system, add the full SQL guide, and close with a comprehensive set of
tips, tricks, and resources to maximise what you get from this entire course.
WEEK 10 AT A GLANCE
Day Topic Key Skill Project Output
74 Market Microstructure Order book, adverse selection, Amihud illiquidity ratio for
Kyle Lambda, Amihud 5 NSE stocks
76 Code Architecture + SQL Package structure, type hints, Refactored strategy class +
Mastery pytest + full SQL guide SQL query suite
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 2
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
77 Final Project Part 1 Connect all 10-week components, Complete system running
integration test end-to-end live
78 Final Project Part 2 + Max GitHub polish, SQL deep dive, Professional portfolio +
Output Guide tips & tricks, resources complete reference guide
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 3
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
Time Series Core
71 Stationarity, ADF test, ACF/PACF plots, and ARIMA — the mathematical foundation under every
quant model
p-value > 0.05 -> Fail to reject null -> SERIES IS NON-STATIONARY
Cannot use in regression directly
Fix: take the first difference (returns)
RULE: always run ADF before any regression or correlation on financial data.
If p > 0.05: difference the series first. Then re-test.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 4
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
PACF = Partial ACF: correlation at lag k after removing all shorter lags
df = pd.read_csv("[Link]")
df = df[df["SYMBOL"]=="TCS"].sort_values("DATE1").reset_index(drop=True)
df["DATE1"] = pd.to_datetime(df["DATE1"])
prices = df["CLOSE"]
returns = prices.pct_change().dropna() * 100
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 5
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
ret_arr = [Link]
nlags = 25
acf_v = acf(ret_arr, nlags=nlags, fft=True)
pacf_v = pacf(ret_arr, nlags=nlags)
ci = 1.96 / [Link](len(ret_arr))
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 6
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 7
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
72 Engle-Granger test, half-life of mean reversion, and Kalman Filter dynamic hedge ratio
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 8
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
df = pd.read_csv("[Link]")
df["DATE1"] = pd.to_datetime(df["DATE1"])
df = df.sort_values(["SYMBOL","DATE1"])
tcs = df[df["SYMBOL"]=="TCS"].set_index("DATE1")["CLOSE"]
infy = df[df["SYMBOL"]=="INFY"].set_index("DATE1")["CLOSE"]
pair = [Link]({"TCS":tcs,"INFY":infy}).dropna()
for t in range(n):
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 9
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
y = pair["TCS"].iloc[t]
F = [Link]([1.0, pair["INFY"].iloc[t]])
# Predict
P = P + Vw
# Innovation
e = y - F @ theta
S = F @ P @ F + Ve
# Kalman gain
K = (P @ F) / S
# Update
theta = theta + K * e
P = P - [Link](K, F) @ P
beta_kf[t] = theta[1]
z_static = zscore(spread_static)
z_kf = zscore(spread_kf)
# ■■ Plot ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
fig, axes = [Link](3, 1, figsize=(13,11), sharex=True)
colors_sig = ["seagreen" if v>0 else "tomato" if v<0 else "lightgray" for v in signal_kf.values]
axes[2].bar(range(len(signal_kf)), signal_kf.values, color=colors_sig, alpha=0.7)
axes[2].set_title("Trading Signal: +1 = Long Spread | -1 = Short Spread", fontweight="bold")
axes[2].set_ylabel("Signal"); axes[2].grid(True, alpha=0.2)
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 10
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 11
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
73 Risk parity, Black-Litterman, and resampled efficient frontier — fix the failures of basic Markowitz
Risk Parity: find weights w such that all MRC_i are equal.
Solution 2 — Black-Litterman
BLACK-LITTERMAN: BLEND MARKET EQUILIBRIUM WITH YOUR VIEWS
Step 1: Start from market equilibrium weights (e.g. NIFTY50 index weights)
These are the "neutral" weights that require no skill to justify.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 12
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
RESULT: weights tilt AWAY from equilibrium only where you have conviction.
High confidence in a view -> larger tilt away from market weight.
No view -> stay at market weight (no uncompensated active risk).
symbols = ["TCS","INFY","RELIANCE","HDFCBANK","WIPRO"]
df = pd.read_csv("[Link]")
df["DATE1"] = pd.to_datetime(df["DATE1"])
df = df[df["SYMBOL"].isin(symbols)].sort_values(["SYMBOL","DATE1"])
df["Return"] = [Link]("SYMBOL")["CLOSE"].pct_change()
pivot = df.pivot_table(index="DATE1",columns="SYMBOL",values="Return").dropna()
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 13
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 14
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
• Always add min/max weight bounds (1% to 60%) in any optimisation — prevents degenerate
single-stock portfolios.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 15
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
Market Microstructure
74 Inside the order book — adverse selection, Kyle Lambda, and the true cost of trading
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 16
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
df = pd.read_csv("[Link]")
df["DATE1"] = pd.to_datetime(df["DATE1"])
symbols = ["TCS","INFY","RELIANCE","HDFCBANK","WIPRO"]
df = df[df["SYMBOL"].isin(symbols)].sort_values(["SYMBOL","DATE1"]).copy()
df["Return_abs"] = [Link]("SYMBOL")["CLOSE"].pct_change().abs()
df["Volume_Rs_Cr"] = df["CLOSE"] * df["TOTTRDQTY"] / 1e7 # in crore
# Annual summary
summary = ([Link]("SYMBOL")["Amihud_20d"]
.mean()
.sort_values(ascending=False)
.reset_index())
[Link] = ["Symbol","Avg_Amihud"]
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 17
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 18
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
Execution Algorithms — TWAP, VWAP, and Implementation
Shortfall
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 19
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
time_slots = [
"09:15","09:30","09:45","10:00","10:15","10:30","10:45","11:00",
"11:15","11:30","11:45","12:00","12:15","12:30","12:45","13:00",
"13:15","13:30","13:45","14:00","14:15","14:30","14:45","15:00",
"15:15"
]
n_slots = len(time_slots)
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 20
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
# Implementation Shortfall
decision_price = price_path[0] # price when you decided to trade
is_twap = (twap_exec - decision_price) * total_order
is_vwap = (vwap_exec - decision_price) * total_order
print(f"\nImplementation Shortfall (IS):")
print(f" TWAP IS: Rs {is_twap:+,.0f} ({(twap_exec/decision_price-1)*100:+.3f}%)")
print(f" VWAP IS: Rs {is_vwap:+,.0f} ({(vwap_exec/decision_price-1)*100:+.3f}%)")
# ■■ Plot ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
fig, axes = [Link](2, 1, figsize=(13,8), sharex=True)
x = range(n_slots)
axes[0].bar(x, twap_slices, alpha=0.7, label="TWAP (equal)", color="royalblue", width=0.4)
axes[0].bar([i+0.4 for i in x], vwap_slices, alpha=0.7, label="VWAP (vol-weighted)",
color="seagreen", width=0.4)
axes[0].plot(x, vol_profile*total_order, "o--", color="tomato", lw=2,
ms=4, label="Market vol profile")
axes[0].set_title("Execution Schedule: TWAP vs VWAP vs Market Volume", fontweight="bold")
axes[0].set_ylabel("Shares to Execute")
axes[0].legend(fontsize=8); axes[0].grid(True, alpha=0.2)
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 21
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
• VWAP execution beats TWAP when the volume forecast is accurate — it hides your order in natural
market volume.
• Implementation Shortfall captures the full cost from decision to execution — the most complete
execution quality metric.
• For orders below 0.1% of daily volume (most retail algo trading): simple market orders near close are
fine.
• Almgren-Chriss provides the mathematically optimal execution schedule — study it if you join an
institutional desk.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 22
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
Code Architecture + SQL Mastery
76 Refactor notebooks to production packages — then master the database language every quant desk
uses
Args:
prices: closing prices
trading_days: days per year
Returns:
DataFrame with ret, vol, sharpe
"""
ret = prices.pct_change().dropna()
vol = [Link]() * trading_days**0.5
sharpe = [Link]()/[Link]()*trading_days**0.5
return [Link]({
"daily_ret":ret,"ann_vol":vol,
"sharpe":sharpe})
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 23
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
# Create tables
[Link]("""
CREATE TABLE IF NOT EXISTS prices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
date TEXT NOT NULL,
open REAL, high REAL, low REAL, close REAL,
volume INTEGER,
UNIQUE(symbol, date)
);
CREATE TABLE IF NOT EXISTS signals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
symbol TEXT NOT NULL,
date TEXT NOT NULL,
signal TEXT,
rsi REAL,
adx REAL,
UNIQUE(symbol, date)
);
CREATE INDEX IF NOT EXISTS idx_prices_sym ON prices(symbol);
CREATE INDEX IF NOT EXISTS idx_prices_date ON prices(date);
""")
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 1: Basic SELECT with filters
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
q1 = """
SELECT symbol, date, close
FROM prices
WHERE symbol = 'TCS'
AND date >= '2023-01-01'
ORDER BY date DESC
LIMIT 10
"""
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 24
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 2: GROUP BY aggregation
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
q2 = """
SELECT
symbol,
COUNT(*) AS trading_days,
ROUND(AVG(close), 2) AS avg_close,
ROUND(MAX(close), 2) AS max_close,
ROUND(MIN(close), 2) AS min_close,
ROUND(AVG(volume) / 1000000, 2) AS avg_vol_M
FROM prices
GROUP BY symbol
ORDER BY avg_vol_M DESC
"""
print("\n=== Q2: Summary stats per stock ===")
print(pd.read_sql(q2, conn).to_string(index=False))
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 3: Window function — 20-day moving average
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
q3 = """
SELECT
symbol,
date,
close,
ROUND(AVG(close) OVER (
PARTITION BY symbol
ORDER BY date
ROWS BETWEEN 19 PRECEDING AND CURRENT ROW
), 2) AS sma_20
FROM prices
WHERE symbol = 'TCS'
ORDER BY date DESC
LIMIT 10
"""
print("\n=== Q3: 20-day SMA using SQL window function ===")
print(pd.read_sql(q3, conn).to_string(index=False))
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 4: Daily return using LAG window function
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
q4 = """
SELECT
symbol,
date,
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 25
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
close,
ROUND(
(close - LAG(close) OVER (PARTITION BY symbol ORDER BY date))
/ LAG(close) OVER (PARTITION BY symbol ORDER BY date) * 100
, 3) AS daily_ret_pct
FROM prices
WHERE symbol IN ('TCS', 'INFY')
ORDER BY symbol, date DESC
LIMIT 20
"""
print("\n=== Q4: Daily returns with LAG ===")
print(pd.read_sql(q4, conn).to_string(index=False))
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 5: Top gainers each month
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
q5 = """
WITH monthly AS (
SELECT
symbol,
SUBSTR(date, 1, 7) AS month,
MIN(close) AS close_start,
MAX(close) AS close_end,
ROUND((MAX(close)-MIN(close))/MIN(close)*100, 2) AS approx_return_pct
FROM prices
GROUP BY symbol, SUBSTR(date,1,7)
)
SELECT symbol, month, close_start, close_end, approx_return_pct
FROM monthly
ORDER BY month DESC, approx_return_pct DESC
"""
df_monthly = pd.read_sql(q5, conn)
print("\n=== Q5: Monthly return by stock (top rows) ===")
print(df_monthly.head(15).to_string(index=False))
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# SQL QUERY 6: JOIN prices with signals table
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# First insert some dummy signals
sig_rows = [('TCS','2023-06-01','BUY',28.5,32.1),
('INFY','2023-06-01','HOLD',55.2,18.4)]
[Link]("INSERT OR IGNORE INTO signals(symbol,date,signal,rsi,adx) VALUES(?,?,?,?,?)",
sig_rows)
[Link]()
q6 = """
SELECT
[Link],
[Link],
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 26
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
[Link],
[Link],
[Link],
[Link]
FROM prices p
JOIN signals s ON [Link] = [Link]
AND [Link] = [Link]
ORDER BY [Link] DESC
"""
print("\n=== Q6: Prices joined with signals ===")
print(pd.read_sql(q6, conn).to_string(index=False))
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
# PANDAS BRIDGE: read any SQL query directly into DataFrame
# ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
tcs_df = pd.read_sql(
"SELECT date, close FROM prices WHERE symbol='TCS' ORDER BY date",
con=conn,
parse_dates=["date"]
)
tcs_df["sma_20"] = tcs_df["close"].rolling(20).mean()
print(f"\nSQLAlchemy bridge: {len(tcs_df)} TCS rows loaded into DataFrame")
print("Continue using Pandas for all calculations after loading from SQL")
[Link]()
print("\nSQL Mastery complete. In production: replace sqlite:///[Link]")
print("with postgresql://user:password@host:5432/dbname")
SELECT col FROM tbl WHERE cond Filter and select columns df[condition][columns]
GROUP BY sym ORDER BY col DESC Aggregate per stock, sort [Link]("sym").agg(...).sort_
values(...)
JOIN ... ON key1=key2 Merge two tables on matching key [Link](df2, on="key")
LAG(col) OVER (PARTITION BY sym Previous row value per group [Link]("sym")["col"].shift(1
ORDER BY date) )
WITH monthly AS (SELECT ...) Common Table Expression (CTE) Assign result to variable then
reuse
pd.read_sql(query, con=engine) SQL query directly to DataFrame The SQLAlchemy bridge — use this
always
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 27
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 28
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
DAY
import pandas as pd
import numpy as np
import yfinance as yf
from arch import arch_model
from scipy import stats
from sqlalchemy import create_engine
[Link]("ignore")
# ■■ CONFIG ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
SYMBOLS = ["[Link]","[Link]","[Link]","[Link]","[Link]"]
NAMES = [[Link](".NS","") for s in SYMBOLS]
CAPITAL = 500_000
FAST_SMA = 20
SLOW_SMA = 50
ADX_THRESH = 25
KELLY_FRACTION = 0.25
VAR_CONF = 0.95
ROUND_TRIP_COST = 0.0023
TELEGRAM_TOKEN = [Link]("TELEGRAM_TOKEN","")
TELEGRAM_CHAT = [Link]("TELEGRAM_CHAT_ID","")
DB_PATH = [Link]("~/quant_system/[Link]")
LOG_PATH = [Link]("~/quant_system/logs/")
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 29
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
OUT_PATH = [Link]("~/quant_system/outputs/")
# ■■ LOGGING ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
[Link](
level=[Link],
format="%(asctime)s %(levelname)s %(message)s",
handlers=[
[Link](f"{LOG_PATH}{[Link]()}.log"),
[Link]([Link])
]
)
log = [Link]()
# ■■ HELPERS ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
def _rsi(s: [Link], p: int = 14) -> [Link]:
d=[Link](); g=[Link](lower=0).ewm(com=p-1,min_periods=p).mean()
return 100-100/(1+g/(-d).clip(lower=0).ewm(com=p-1,min_periods=p).mean())
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 30
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
except Exception as e:
[Link](f" Failed {name}: {e}")
return data
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 31
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 32
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
if __name__ == "__main__":
run()
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 33
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
78 Course completion, GitHub portfolio, and everything you need to get the most from this entire 10-week
journey
## Architecture Diagram
[paste ASCII or image diagram here]
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 34
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
## Folder Structure
[paste the Day 69 architecture tree here]
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 35
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Tip 1: Read the notes once, then BUILD everything from scratch.
Reading without building = 10% retention. Building = 80% retention.
If you cannot rebuild Day 33 (bootstrap Sharpe CI) from memory,
you have not learned it — you have only read it.
Tip 5: Re-read your own code one week after writing it.
If you cannot understand it without the notes, it needs better
variable names and comments. Code you cannot read is code you
cannot maintain or extend.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 36
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
But if the equity curve is flat for 2 years then spikes once,
the strategy is not tradeable — the Sharpe is from one event.
The equity curve shape tells the truth that numbers hide.
Tip 16: Post one LinkedIn update per week for 3 months.
Show a chart. Explain one concept. Ask one question.
Consistency matters far more than perfection.
Recruiters searching #quantfinance see consistent builders
as far more credible than silent profiles with impressive CVs.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 37
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 38
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
NSEPython library Python lib Live NSE option chains, pip install nsepython
Bhavcopy, FII data
directly in Python.
arch library (GARCH) Python lib The standard Python pip install arch
GARCH/EGARCH
implementation. Used in
production.
statsmodels Python lib ADF test, ARIMA, OLS pip install statsmodels
regression,
cointegration.
Essential quant
toolkit.
# GOLDEN RULE
You started Day 1 not knowing what a DataFrame was. You finish Day 78 with a live trading system on AWS,
a professional GitHub portfolio, 10 validated quant models, a SQL database, a Kalman Filter pairs strategy,
VWAP execution, interview readiness, and a career plan. That is a transformation, not just a course
completion.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 39
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Y
pro
ser
Python · Pandas · GARCH · ML · Options · Risk Parity · Kalman Filter · SQL · VWAP · AWS Cloud ·
Production System G
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 40
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
half_life = -ln(2)/lambda Mean reversion speed 5-30 days = tradeable. >60 days
= too slow.
Markowitz Max Sharpe max (w@mu - rf) / sqrt(w@cov@w) Research only. Unstable for live
trading.
Equal Weight w_i = 1/n for all i Strongest naive benchmark. Often
beats optimised.
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 41
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
WITH cte AS (SELECT ...) Common Table Expression — build Assign result to variable, reuse
and reuse later
pd.read_sql(query, engine) Load SQL result into DataFrame The production bridge: SQL
stores, Pandas analyses
Bid-ask spread Ask price - Bid price Always buy at ask, sell at bid —
never midprice
Adverse selection Largest spread component (~40%) Wider spreads in illiquid stocks
= more informed flow
1% daily volume rule Never trade >1% of avg daily Beyond this threshold, you start
volume moving the market
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 42
QUANT PRO WEEK 10 | Days 71-78 | ELITE LAYER
Advanced Quant Finance Course Time Series | Cointegration | Microstructure | Execution | Final System
Quant Pro | Advanced Quant Finance Course | Week 10 — Elite Layer Page 43