A powerful command-line tool for calculating common technical indicators for stock analysis. Fetches historical stock data from Yahoo Finance API and computes a comprehensive set of technical indicators, saving the enriched dataset to various file formats.
- Features
- What's New
- Prerequisites
- Installation
- Quick Start
- Usage
- Configuration
- Templates
- Indicators
- Output Formats
- Advanced Usage
- Interpretation
- Performance
- Troubleshooting
- Build and Publish
- Contributing
- License
- 9 Technical Indicators: Calculate SMA, EMA, MACD, RSI, Bollinger Bands, ATR, OBV, ROC, and Stochastic Oscillator
- Multiple Data Sources: Fetch data from Yahoo Finance for any listed security
- Flexible Time Periods: Support for YTD, 1Y, 2Y, 5Y, 10Y, and MAX periods
- Multiple Timeframes: Daily (1d), Weekly (1wk), Monthly (1mo), and Quarterly (3mo) data
- Batch Processing: Process multiple tickers simultaneously
- Custom Configuration: Override default indicator parameters with JSON config files
- Multiple Output Formats: Export to CSV, Parquet, JSON, XLSX, or AVRO
- High Performance: Powered by Polars library for fast, concurrent data processing
- GPU Support: Optional GPU acceleration for compute-intensive operations
- Async Operations: Asynchronous I/O for efficient data fetching and file operations
- Lazy Evaluation: Memory-efficient data processing with lazy computation
- v1.2.9: Current stable release
- v1.2.0: Added support for configuration files and downsampling.
- v1.1.0: Added support for asynchronous handling of I/O bound tasks and downloading
(done by yfinance backend).
- v1.0.0: Upgrade to polars library to support concurrent data processing,
lazy computations and support for both CPU and GPU engines.
- Python: Version 3.6 or higher
- pip: Python package installer
- Internet Connection: Required to fetch data from Yahoo Finance API
Install the package from PyPI using pip:
pip install indicators-cliTo verify installation:
indicators --versionAfter installation, you can start analyzing stocks immediately:
# Analyze Apple stock with default settings (5-year period, daily data)
indicators AAPL
# Analyze with custom period and timeframe
indicators AAPL -p 2y -t 1wk
# Analyze multiple stocks at once
indicators AAPL MSFT NVDA GOOGL
# Save to a specific file and directory
indicators AAPL -o my_analysis.csv -d ./outputindicators TICKER [OPTIONS]- TICKER: Stock ticker symbol as listed on Yahoo Finance (e.g., AAPL, MSFT, TSLA)
- Can specify multiple tickers:
indicators AAPL MSFT NVDA - Can use a text file with one ticker per line:
indicators tickers.txt
- Can specify multiple tickers:
| Parameter | Short | Long | Default | Description |
|---|---|---|---|---|
| Period | -p |
--period |
5y |
Time period for data. Options: ytd, 1y, 2y, 5y, 10y, max |
| Timeframe | -t |
--timeframe |
1d |
Data granularity. Options: 1d, 1wk, 1mo, 3mo or JSON file path |
| Output | -o |
--output |
Auto-generated | Output file name. Can be TXT file with multiple names |
| Format | -f |
--format |
csv |
Output format. Options: csv, parquet, json, xlsx, avro |
| Directory | -d |
--dir |
Current dir | Directory to save output files |
| Config | -c |
--config_json |
None | Path to JSON config file for indicator parameters |
| Engine | -e |
--engine |
cpu |
Computation engine. Options: cpu, gpu |
Example 1: Basic usage with default settings
indicators AAPLExample 2: Custom period and timeframe
indicators AAPL -p 5y -t 1d -f csv -e cpu -o indicators.csvExample 3: Multiple stocks with GPU acceleration
indicators AAPL MSFT NVDA -t 1wk -f parquet -e gpuExample 4: Batch processing with configuration files
indicators tickers.txt -t timeframe.json -c config.json -f json -e gpu -o outputs.txtExample 5: Export to Excel format
indicators TSLA -p 2y -t 1wk -f xlsx -o tesla_analysis.xlsxExample 6: High-frequency data analysis
indicators AAPL -p 1y -t 1d -f parquet -e cpu -d ./analysis/2024indicators --helpYou can customize indicator parameters using JSON configuration files. This allows you to fine-tune the calculation windows for different periods and timeframes.
Create a JSON file (e.g., my_config.json) with your custom parameters. Any omitted values will use defaults.
Example configuration structure:
{
"sma_window": {
"5y": { "1d": 50, "1wk": 25 }
},
"rsi_window": {
"5y": { "1d": 21 }
}
}Using the configuration:
indicators AAPL -c my_config.jsonFor advanced users, you can specify different timeframes for different periods using a JSON file:
Example timeframe.json:
{
"ytd": "1d",
"1y": "1d",
"2y": "1wk",
"5y": "1mo",
"10y": "3mo",
"max": "3mo"
}Usage:
indicators AAPL -t timeframe.jsonEnter the values you want to override for whichever period you are scraping. Each integer value is a certain number of timeframe periods so if your timeframe is "1wk" for the "ytd" period then entering 20 would mean a 20 weeks window. Entering all values is not necessary. The values omitted will be replaced by default values in this template:
{
"sma_window": {
"ytd": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"1y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"2y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"5y": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 },
"10y": { "1d": 200, "1wk": 100, "1mo": 50, "3mo": 25 },
"max": { "1d": 200, "1wk": 100, "1mo": 50, "3mo": 25 }
},
"ema_window": {
"ytd": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"1y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"2y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"5y": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 },
"10y": { "1d": 200, "1wk": 100, "1mo": 50, "3mo": 25 },
"max": { "1d": 200, "1wk": 100, "1mo": 50, "3mo": 25 }
},
"macd_short": {
"ytd": { "1d": 12, "1wk": 6, "1mo": 4, "3mo": 3 },
"1y": { "1d": 12, "1wk": 6, "1mo": 4, "3mo": 3 },
"2y": { "1d": 12, "1wk": 6, "1mo": 4, "3mo": 3 },
"5y": { "1d": 12, "1wk": 6, "1mo": 4, "3mo": 3 },
"10y": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 },
"max": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 }
},
"macd_long": {
"ytd": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 },
"1y": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 },
"2y": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 },
"5y": { "1d": 26, "1wk": 13, "1mo": 8, "3mo": 5 },
"10y": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 },
"max": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 }
},
"macd_signal": {
"ytd": { "1d": 9, "1wk": 5, "1mo": 3, "3mo": 2 },
"1y": { "1d": 9, "1wk": 5, "1mo": 3, "3mo": 2 },
"2y": { "1d": 9, "1wk": 5, "1mo": 3, "3mo": 2 },
"5y": { "1d": 9, "1wk": 5, "1mo": 3, "3mo": 2 },
"10y": { "1d": 18, "1wk": 9, "1mo": 5, "3mo": 3 },
"max": { "1d": 18, "1wk": 9, "1mo": 5, "3mo": 3 }
},
"rsi_window": {
"ytd": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"1y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"2y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"5y": { "1d": 21, "1wk": 10, "1mo": 7, "3mo": 5 },
"10y": { "1d": 30, "1wk": 15, "1mo": 10, "3mo": 7 },
"max": { "1d": 30, "1wk": 15, "1mo": 10, "3mo": 7 }
},
"bb_window": {
"ytd": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"1y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"2y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"5y": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 },
"10y": { "1d": 100, "1wk": 50, "1mo": 25, "3mo": 12 },
"max": { "1d": 100, "1wk": 50, "1mo": 25, "3mo": 12 }
},
"roc_window": {
"ytd": { "1d": 10, "1wk": 5, "1mo": 3, "3mo": 2 },
"1y": { "1d": 10, "1wk": 5, "1mo": 3, "3mo": 2 },
"2y": { "1d": 10, "1wk": 5, "1mo": 3, "3mo": 2 },
"5y": { "1d": 20, "1wk": 10, "1mo": 5, "3mo": 3 },
"10y": { "1d": 90, "1wk": 45, "1mo": 20, "3mo": 10 },
"max": { "1d": 90, "1wk": 45, "1mo": 20, "3mo": 10 }
},
"atr_window": {
"ytd": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"1y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"2y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"5y": { "1d": 20, "1wk": 10, "1mo": 7, "3mo": 5 },
"10y": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 },
"max": { "1d": 50, "1wk": 25, "1mo": 15, "3mo": 8 }
},
"stochastic_window": {
"ytd": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"1y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"2y": { "1d": 14, "1wk": 7, "1mo": 5, "3mo": 3 },
"5y": { "1d": 21, "1wk": 10, "1mo": 7, "3mo": 5 },
"10y": { "1d": 30, "1wk": 15, "1mo": 10, "3mo": 7 },
"max": { "1d": 30, "1wk": 15, "1mo": 10, "3mo": 7 }
}
}
Enter the timeframe you would like to choose for each period. Entering a timeframe for each period you mention is necessary if you pass a JSON configuration.
{
"ytd": "1d",
"1y": "1d",
"2y": "1wk",
"5y": "1mo",
"10y": "3mo",
"max": "3mo"
}The tool calculates the following 9 technical indicators:
| Indicator | Description | Key Parameters |
|---|---|---|
| SMA | Simple Moving Average | Window size varies by period/timeframe |
| EMA | Exponential Moving Average | Span varies by period/timeframe |
| MACD | Moving Average Convergence Divergence | Short, Long, Signal windows |
| RSI | Relative Strength Index | Lookback window (typically 14 periods) |
| Bollinger Bands | Upper and Lower Bands | Window size and standard deviations |
| ATR | Average True Range | Rolling window for volatility |
| OBV | On-Balance Volume | Cumulative volume indicator |
| ROC | Rate of Change | Percentage change window |
| Stochastic | Stochastic Oscillator | %K and %D calculations |
All indicators are calculated with period-appropriate parameters that automatically adjust based on your chosen timeframe and period.
The tool supports multiple output formats to suit your workflow:
| Format | Extension | Use Case |
|---|---|---|
| CSV | .csv |
Universal compatibility, Excel-friendly |
| Parquet | .parquet |
High performance, columnar storage |
| JSON | .json |
API integration, web applications |
| XLSX | .xlsx |
Native Excel format with formatting |
| AVRO | .avro |
Big data systems, Apache ecosystem |
Example:
# CSV for Excel
indicators AAPL -f csv -o analysis.csv
# Parquet for data pipelines
indicators AAPL -f parquet -o analysis.parquet
# JSON for web apps
indicators AAPL -f json -o analysis.jsonCreate a text file with one ticker per line:
tickers.txt:
AAPL
MSFT
GOOGL
AMZN
TSLA
Run:
indicators tickers.txt -p 2y -t 1wk -f parquetconfig.json:
{
"sma_window": {
"5y": { "1d": 100 }
},
"rsi_window": {
"5y": { "1d": 21 }
}
}Run:
indicators AAPL -c config.json -p 5yFor large datasets or multiple tickers, use GPU acceleration:
indicators AAPL MSFT NVDA GOOGL AMZN -e gpu -t 1d -p 5yNote: Requires compatible GPU and drivers.
Here are the explanations and interpretations of each of the technical indicators added
-
Moving Averages (MA)
Simple Moving Average (sma): This is the average of the stock’s closing prices over a specific period (e.g., 20 days). It smoothens out price data to help identify the direction of the trend. A higher SMA generally indicates a longer-term trend.
Exponential Moving Average (ema): This is similar to SMA but gives more weight to recent prices, making it more responsive to recent price changes. EMAs are useful for identifying short-term trends and can be combined with SMAs to detect trend reversals.
Interpretation:
When a short-term MA (like a 20-day EMA) crosses above a long-term MA (like a 50-day SMA), it’s often a bullish signal, indicating an upward trend.
Conversely, when a short-term MA crosses below a long-term MA, it’s considered bearish.
-
Moving Average Convergence Divergence (macd)
MACD is the difference between a short-term EMA (usually 12-day) and a long-term EMA (usually 26-day). It’s accompanied by a signal line (9-day EMA of the MACD), and their crossover points are used to identify buy or sell signals. MACD Histogram: The difference between the MACD line and the signal line, showing the strength of the trend.
Interpretation:
When the MACD line crosses above the signal line, it’s a bullish signal (suggesting a potential buy).
When the MACD line crosses below the signal line, it’s a bearish signal (suggesting a potential sell).
A growing MACD histogram indicates increasing momentum, while a shrinking histogram suggests weakening momentum.
-
Relative Strength Index (rsi)
RSI is a momentum oscillator that measures the speed and change of price movements on a scale from 0 to 100. Typically, values above 70 suggest the stock is overbought (price may decline), while values below 30 indicate the stock is oversold (price may increase).
Interpretation:
RSI helps identify overbought and oversold conditions. If RSI goes above 70, the stock might be overvalued, which can signal a pullback. Below 30, the stock might be undervalued, signaling a potential buying opportunity.
RSI divergences (when price moves in the opposite direction of RSI) can indicate a trend reversal.
-
Bollinger Bands (bb_upper/bb_lower)
Bollinger Bands consist of a middle band (usually a 20-day SMA) and two outer bands, set at two standard deviations above and below the SMA. The bands expand and contract based on price volatility.
Interpretation:
When prices touch or move outside the bands, they indicate high volatility and potential trend continuation or reversal. For example, if the price touches the upper band, it could be overbought, and if it touches the lower band, it could be oversold.
Squeeze: When the bands contract significantly, it indicates low volatility and often precedes a sharp price move in either direction.
-
Average True Range (atr)
ATR measures volatility by calculating the average range between high and low prices over a given period. Higher ATR values indicate higher volatility.
Interpretation:
ATR does not indicate trend direction but rather the strength of price movements. High ATR values suggest high volatility and potential trend changes, while low ATR values indicate a stable trend or consolidation phase.
ATR can be used as a trailing stop-loss: if a stock’s ATR is high, setting a wider stop-loss might be necessary to avoid premature exits.
-
Volume
Volume is the number of shares traded over a certain period. Volume can validate trends: for example, a price move accompanied by high volume is generally more significant and likely to continue than a move with low volume.
Interpretation:
High volume often accompanies strong moves, such as breakouts or breakdowns, and indicates increased trader interest.
Low volume can indicate a lack of conviction in a price move, potentially signaling a reversal or a period of consolidation.
-
On-Balance Volume (obv)
OBV accumulates volume based on the price movement: it adds volume on up days and subtracts volume on down days. This helps measure buying and selling pressure.
Interpretation:
Rising OBV indicates accumulation (more buying pressure), which often supports upward price moves.
Falling OBV suggests distribution (more selling pressure), supporting potential downward price moves.
Divergences between OBV and price can indicate potential reversals.
-
Rate of Change (roc)
ROC calculates the percentage change in price over a given time period. It’s used to measure the momentum of a stock’s price movement.
Interpretation:
Positive ROC indicates upward momentum, while negative ROC shows downward momentum.
Extreme high or low ROC values could indicate overbought or oversold conditions, respectively.
ROC is also useful for identifying trend reversals when it diverges from the stock price.
-
Stochastic Oscillator (%K and %D)
This indicator compares the current price to its range over a set period (typically 14 days). It has two lines, %K and %D, and fluctuates between 0 and 100.
Interpretation:
Like RSI, a value above 80 suggests overbought conditions, while a value below 20 suggests oversold conditions.
When the %K line crosses above the %D line in the oversold region (below 20), it’s a potential buy signal. Conversely, when it crosses below the %D line in the overbought region (above 80), it’s a potential sell signal.
Divergences between price and the Stochastic Oscillator can indicate potential trend reversals.
The package is automatically built and published to PyPI when a git tag starting with "v" (e.g., v1.1.0) is pushed. This process is managed by the GitHub Actions workflow located at: .github/workflows/workflow.yaml
- Lazy Evaluation: Polars uses lazy evaluation to optimize query plans before execution
- Parallel Processing: Multi-threaded operations for faster computation
- Memory Efficiency: Columnar data format reduces memory footprint
- GPU Acceleration: Optional GPU support for compute-intensive operations
- Async I/O: Non-blocking file operations and data fetching
-
Use Parquet Format: Faster read/write operations compared to CSV
indicators AAPL -f parquet
-
Enable GPU for Large Datasets: Significant speedup for multiple tickers
indicators AAPL MSFT GOOGL AMZN TSLA -e gpu
-
Choose Appropriate Timeframes: Coarser timeframes (1wk, 1mo) process faster
indicators AAPL -p 10y -t 1mo # Faster than 1d
Typical processing times on a standard laptop (4-core CPU):
- Single ticker, 5-year daily data: ~2-5 seconds
- 5 tickers, 5-year daily data: ~8-15 seconds
- Single ticker with GPU acceleration: ~1-2 seconds
Issue: ModuleNotFoundError: No module named 'indicators'
- Solution: Ensure you installed the package:
pip install indicators-cli
Issue: Ticker not found or No data available
- Solution: Verify the ticker symbol on Yahoo Finance. Some delisted or international stocks may not be available.
Issue: GPU acceleration not working
- Solution:
- Verify you have a compatible NVIDIA GPU
- Install CUDA toolkit
- Install GPU-enabled Polars:
pip install polars-gpu
Issue: Permission denied when saving files
- Solution: Ensure you have write permissions in the target directory or specify a different directory with
-d
Issue: Out of memory errors
- Solution:
- Use coarser timeframes (1wk instead of 1d)
- Process fewer tickers at once
- Use Parquet format which is more memory-efficient
For detailed error messages, run Python with verbose output:
python -v -m src.cli AAPLContributions are welcome! Here's how you can help:
- Report Bugs: Open an issue with detailed information
- Suggest Features: Share your ideas for new indicators or features
- Submit Pull Requests: Fix bugs or add features
- Improve Documentation: Help make the docs better
# Clone the repository
git clone https://github.com/ibitec7/indicators-cli.git
cd indicators-cli
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .
# Run the tool
indicators AAPLThis project is licensed under the MIT License - see the LICENSE file for details.
- Yahoo Finance API (via yfinance) for providing stock data
- Polars for high-performance data processing
- Click for the intuitive CLI interface
- Issues: GitHub Issues
- Email: syed.ibrahim.omer.2@gmail.com
- PyPI: indicators-cli
If you find this tool useful, please consider giving it a star on GitHub! ⭐
Made with ❤️ for the trading community