geoffroy-pradier/php-trader
最新稳定版本:v1.0.0
Composer 安装命令:
composer require geoffroy-pradier/php-trader
包简介
PHP implementation of technical indicators for trading. Alternative to the Trader extension.
README 文档
README
A pure PHP implementation of technical indicators for trading, including the Relative Strength Index (RSI) and Stochastic Oscillator. No native extensions (e.g., Trader PECL) are required, making it portable across PHP environments.
Installation
Install the package via Composer:
composer require geoffroy-pradier/php-trader
Requirements
- PHP >= 8.2
Usage
Relative Strength Index (RSI)
Calculate the RSI for a series of closing prices:
use GeoffroyPradier\Trader\Rsi; $prices = [100, 102, 101, 105, 103, 107, 110, 108, 112, 115, 113, 118, 120, 122, 119]; $rsi = Rsi::calculate($prices, 14); print_r($rsi); // Outputs array of RSI values
Stochastic Oscillator (%K and %D)
Calculate the %K and %D lines for high, low, and closing prices:
use GeoffroyPradier\Trader\Stochastic; $highs = [101, 103, 102, 106, 104, 108, 111, 109, 113, 116, 114, 119, 121, 123, 120, 126, 124]; $lows = [99, 101, 100, 104, 102, 106, 109, 107, 111, 114, 112, 117, 119, 121, 118, 124, 122]; $closes = [100, 102, 101, 105, 103, 107, 110, 108, 112, 115, 113, 118, 120, 122, 119, 125, 123]; $stoch = Stochastic::calculate($highs, $lows, $closes, 14, 3); print_r($stoch['k']); // %K values print_r($stoch['d']); // %D values
Testing
Run the PHPUnit tests to verify functionality:
composer test
Development
To contribute:
- Fork the repository on GitHub.
- Add your changes and include corresponding PHPUnit tests.
- Submit a pull request.
License
MIT
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-30