Many engineers want to trade stocks with data, not gut feelings. This guide shows how to build simple, working systems with Python, free tools, and clear rules.
We will cover data, coding, backtesting, and keeping your money safe. No finance degree needed.
Start With Free Data and Simple Tools
Before writing code, pick tools that cost nothing and work today. Engineers love free APIs (Application Programming Interfaces) and open-source libraries.
| Tool / Source | What It Gives You | Best For |
|---|---|---|
| Yahoo Finance API (yfinance) | Free stock prices, splits, dividends | Daily price data, quick tests |
| Alpha Vantage (free tier) | 500 API calls per day | Fundamental data, technical indicators |
| Quandl / Nasdaq Data Link | Free datasets for academics | Macro data, sector trends |
| Pandas library | Data frames, easy math | Cleaning and shaping data |
| Backtrader (open source) | Full backtesting engine | Strategy testing, no live trading |
| Zipline (Quantopian fork) | Event-driven backtesting | Complex multi-asset systems |
A developer in Bangalore used only yfinance and pandas. He tested a simple moving average crossover on 50 stocks. It took two weekends. His system broke even in backtests, but he learned where the holes were.
Pick one data source and one backtester. Do not build your own tools yet. Use what works.
You do not need Bloomberg Terminal. Free Python libraries handle data fetching, cleaning, and testing.
Spending money on tools before you have a working strategy is a common trap.
Pick One Simple Strategy First
Engineers often over-engineer. Start with strategies that have only 2-3 rules. Complexity adds bugs and false hope.
| Strategy Name | Rules | Expected Behavior |
|---|---|---|
| Moving Average Crossover | Buy when 50-day price average crosses above 200-day; sell when opposite happens | Catches medium-term trends, misses sharp reversals |
| Mean Reversion (RSI) | Buy when RSI below 30 (oversold); sell when RSI above 70 (overbought) | Works in sideways markets, fails in strong trends |
| Momentum (12-month) | 余,我来看看Buy top 10% performers last 12 months, hold for 1 month | Rides trends, suffers sharp drawdowns |
Each strategy wins in some markets and loses in others. That is normal. Your job is to know when it wins and when it breaks.
A software engineer in Texas tried a 20-rule neural network strategy. It looked perfect in backtests. In live trading, it lost 15% in three weeks. She switched to a 3-rule momentum system and cut losses fast. Simple beat smart.
Backtest Like an Engineer, Not a Dreamer
Backtesting means running your strategy on old data to see how it would have done. Most beginners cheat by mistake. They look at future data or ignore trading costs.
| Rule | What Bad Backtests Do | What You Should Do Instead |
|---|---|---|
| Look-ahead bias | Use data not available at decision time | Shift signals forward by one day minimum |
| Survivorship bias | Only test stocks that still exist today | Include delisted companies in your dataset |
| Ignore costs | Assume zero commissions and slippage (price difference between expected and actual trade price) | Add $0.01 per share plus 0.1% slippage at minimum |
| Overfitting | Keep tuning rules until past data looks perfect | Split data into train/test sets, never touch test set until final validation |
| Short time window | Test only bull markets | Include 2008, 2020, and 2022 in your data |
A clean backtest takes longer. It also tells you the truth. Garbage in, garbage out.
Your strategy only matters if it passes a strict backtest with real costs and no cheating.
If you cannot explain why it works in simple words, it probably does not work.
Build With Python: A Minimal Example
Here is a working skeleton. It fetches data, computes a signal, and prints trades. You can run this today.
The code below uses yfinance and pandas. It buys when price crosses above the 50-day average and sells when it crosses below.
import yfinance as yf
import pandas as pd
def simple_ma_strategy(ticker='AAPL', period='3y'):
df = yf.download(ticker, period=period)
df['MA50'] = df['Close'].rolling(50).mean()
df['Signal'] = 0
df.loc[df['Close'] > df['MA50'], 'Signal'] = 1
df['Position'] = df['Signal'].shift(1) # Avoid look-ahead
return df
# Run it
data = simple_ma_strategy()
print(data[['Close', 'MA50', 'Position']].tail())This is not a complete system. It has no risk rules, no position sizing, and no live trading. But it runs. You can see signals. You can test changes.
Risk Management: The Part That Keeps You Alive
Engineers often focus on entry signals. Retail traders die from poor risk control. Professional quants spend more time on risk than on finding new signals.
| Rule Type | Specific Limit | Purpose |
|---|---|---|
| Max position size | No single stock over 5% of portfolio | One bad stock cannot ruin you |
| Stop loss | Sell if any position drops 8% below entry | Cut losses before they grow |
| Portfolio stop | Pause all trading if total portfolio drops 10% in a month | Protect against regime change |
| Correlation check | Do not hold two assets with >0.8 correlation | Avoid doubling same bet |
| Cash reserve | Keep 20% in cash or bonds | Survive dry spells, buy dips |
An engineer in Berlin traded with 100% of his cash deployed. His momentum strategy hit a three-week losing streak. He had no cash to add to winning positions. He also had no buffer to stop panic. A 15% drawdown became a 30% drawdown because he could not sit still. Cash is not dead money. It is optionality.
Go Live Slowly: Paper Then Real
Never start with real money. Use paper trading (simulated trades with fake money) for at least 3 months. Track every signal, every slippage, every delayed fill.
When you do go live, start small. Use 10% of your intended capital. Scale up only after 6 months of consistent execution.
Emotions change everything. A strategy that looked easy on screen becomes hard when real money moves.
Paper trade first. Then trade tiny. Only then trade full size.
Key Takeaways
| Key Point | What It Means | Action Item |
|---|---|---|
| Start free | Expensive tools do not make better traders | Pick林荫,我来看看Use yfinance, pandas, and Backtrader for first 6 months |
| Simple wins | 2-3 rule strategies beat complex black boxes | Pick one: MA crossover, RSI mean reversion, or momentum |
| Backtest honestly | Most self-reported returns are fake | Add costs, avoid look-ahead, include delisted stocks |
| Risk first | Preservation beats growth in long run | Set 5% max position, 8% stop loss, 20% cash reserve |
| Scale slowly | Live trading exposes gaps backtests hide | Paper trade 3 months, then 10% capital for 6 months |
Building quant strategies is a craft. It takes time, mistakes, and patience. Start small, measure everything, and protect your downside.