BeginnerPython FundamentalsPython
Python Basics – Pandas¶
Overview¶
Covers the Pandas patterns that power real quant research pipelines — from building a synthetic OHLCV DataFrame through rolling indicators, resampling, groupby analysis, and a simple SMA-crossover backtest. Every example is grounded in price data so the link from Pandas API to practical quant work stays concrete.
Concepts Covered¶
- Building a date-indexed OHLCV DataFrame with
pd.bdate_range pct_change,shift, and log returns on a Series- Rolling windows: SMA-20, Bollinger Bands, rolling Sharpe ratio
- Resampling daily OHLCV to weekly bars with
resample().agg() groupbyby day-of-week to surface return seasonality patterns- Signal generation: SMA crossover with
np.where, vectorised P&L, strategy vs buy-and-hold comparison
Files¶
pandas_tutorial.py: Annotated walkthrough script; each section prints labelled DataFrame output alongside the corresponding Pandas call
How to Run¶
Sections¶
| Section | What it demonstrates |
|---|---|
| DataFrame basics | Shape, head, dtypes, describe on a synthetic 60-day OHLCV frame |
| Returns and rolling windows | pct_change, rolling().mean/std, Bollinger Bands, rolling Sharpe |
| Resampling | Daily → weekly OHLC aggregation with named agg columns |
| Groupby by weekday | Day-of-week return stats as a bias check |
| Signal generation | SMA-5/20 crossover, shifted signal, strategy vs buy-and-hold |
Practice Ideas¶
- Load real price data via
pandas_datareaderor a CSV and replace the synthetic DataFrame - Add a drawdown column using
cummax()andcummin() - Extend the groupby section to group by calendar month
Next Steps¶
- Apply these patterns to real data in
Market Data/ - Move into more advanced modelling in
Quantitative Methods - Time Series/ - See
Strategies - Momentum Trading/for production-grade signal generation
Continue in Python Fundamentals¶
-
Python Basics - Comprehensions
Comprehensions are Python's most elegant way to transform data—replacing loops with readable, performant one-liners. This module teaches list, dict, set comprehensions, generator expressions, and functional tools (
map,filter,reduce,accumulate) used constantly in quantitative finance for data cleaning, signal generation, and portfolio calculations. -
Control flow structures (
if/elif/else,for,while, comprehensions,break,continue) are the foundation of all algorithms. This module teaches how to make decisions, iterate through data, and build the logic patterns used in trading systems, backtests, and risk management tools. -
Python Basics - Dates and Times
Markets run on a calendar, not a clock. Interest accrues over days, options
-
Python Basics - Essential Libraries
A working quant leans on a small set of libraries for almost everything. A few of
-
This utility teaches Python functions - the building blocks of modular, reusable code. Learn to write efficient trading algorithms and financial tools using proper function design.
-
Python Basics - Imports and Modules
Almost every Python program begins with a few import lines. An import is how you