A beginner-friendly library for stock market data, backtesting, and strategies.
Project description
stocksimpy
Easy Python backtesting for stocks — fast and simple
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.
(Disclaimer: This is an early alpha, API might change in the future updates)
🎯 Quick Features
- 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.
⚡ Quick Start
1. Install stocksimpy (and yfinance for convenient data input)
pip install stocksimpy yfinance
2. Imports
from stocksimpy import StockData, Backtester, Visualize, Performance
3. Load Data
# 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)
4. Define Your Strategy
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
5. Run Backtest
# 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()
6. Evaluate the Results
# View performance metrics like max drawdown and sharpe ratio
perf = Performance(bt)
print(perf.generate_risk_report())
7. Visualize
# Visualize the graph
graph = Visualize(bt)
graph.visualize_backtest().show() # You can use .savefig(...) instead of .show() to record the graph in disk
And thats it, you just ran your first backtest 🚀
🤝 Contributions
Ideas, strategies, or improvements? We welcome all contributions! Check out CONTRIBUTING.md for a more detailed information about contributing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stocksimpy-0.1.0.tar.gz.
File metadata
- Download URL: stocksimpy-0.1.0.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b70eda713aceaffc67db73d7f95628d2bb99ebca41a41c08ce598b918e2626
|
|
| MD5 |
115f41c7ae47931ef3ee77f893e971ef
|
|
| BLAKE2b-256 |
9427d1aa7fa20a4109c1c8c49108c2c7274b1ba774372c8730265717f50af7ce
|
File details
Details for the file stocksimpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stocksimpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1118af9d53a127ccaff5b2f71db185fb6e64bf226bb3bb33a557b4fb3a976249
|
|
| MD5 |
3889c9119c85e3cd13e7309ecdd8ac94
|
|
| BLAKE2b-256 |
c78d1c50fe8121060db70f46f241ba729b5a3303ebd6cecc69f179a0b7a6ff63
|