stocksimpy lets you prototype trading ideas with minimal boilerplate. Everything is explicit — load data, define rules, run a backtest. No configuration sprawl, no hidden state, and no magic methods.. Perfect for beginners and anyone who wants results fast.
- Load stock prices from
yfinanceor your own database in seconds. - Run fixed or dynamic backtests in just a few lines of code.
- Built-in example strategies like SMA/EMA crossover, RSI, and price action.
- Clear and simple design — no hidden magic, everything is easy to read.
- Beginner-friendly: start experimenting immediately.
pip install stocksimpy yfinancefrom stocksimpy import StockData, Backtester, Visualize, Performance# If you want to load your own data from .csv, .sqlite or similar, use appropriate functions built into `StockData()`
data = StockData().from_yfinance([your_stock_symbol], your_starting_date, your_end_date)def sma_crossover(prices):
short = prices["Close"].rolling(20).mean()
long = prices["Close"].rolling(50).mean()
# Buy when short crosses above long, sell when it crosses below
signal = (short > long).astype(int)
return signal# You can use your own strategy or one of the built-in ones for testing (e.g. Strategy.rsi_momentum_fixed())
bt = Backtester('AAPL', data, sma_crossover)
# Depending on your strategy you may need to run bt.run_backtest_dynamic(), see more on the documentation
bt.run_backtest_fixed()# View performance metrics like max drawdown and sharpe ratio
perf = Performance(bt)
print(perf.generate_risk_report())# Visualize the graph
graph = Visualize(bt)
graph.visualize_backtest().show() # You can use .savefig(...) instead of .show() to record the graph in diskAnd thats it, you just ran your first backtest 🚀
Ideas, strategies, or improvements? We welcome all contributions! Check out CONTRIBUTING.md for a more detailed information about contributing