Skip to main content

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 yfinance or 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):

    # Don't do any trades until long range
    if(len(prices) < 50):
        return "hold"
    
    short = prices["Close"].rolling(20).mean()
    long = prices["Close"].rolling(50).mean()

    # Buy when short crosses above long, sell when it crosses below
    if short > long:
        return "buy"
    else:
        return "sell"

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

📃 Docs

More in depth explanation on how to use this library can be found in ReadTheDocs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stocksimpy-0.1.1.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stocksimpy-0.1.1-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file stocksimpy-0.1.1.tar.gz.

File metadata

  • Download URL: stocksimpy-0.1.1.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for stocksimpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3b104dc46b3a497e7eb87fb7fb622ee7cb01d1e9663e5b252c248f59632770e9
MD5 5a4fbd3d49b7920ae9efdaddd9f4e5a8
BLAKE2b-256 0589dfaaef3de9b6b046e3310c00ce3e88edfd5c73bf768f27f220f69bbc6f75

See more details on using hashes here.

File details

Details for the file stocksimpy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: stocksimpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for stocksimpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa1cb38d0367c6e30278bcd7349335ba4fc6ef7ab83159a292bb1a427c3ae102
MD5 acc7bf22a9edbc08bd818cb1aa4f265d
BLAKE2b-256 05d73beca55c986cebfc7d155de7608502b729e40dc3616db404aa487c637aad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page