#indicator #trading #moving-average #stock #charts #standard-deviation

m4rs

支持SMA、EMA、布林带、MACD、RSI、随机指标、一目均衡表等的交易指标库

10个重大版本更新

0.11.0 2024年8月24日
0.9.0 2024年8月10日
0.7.0 2024年7月27日

#35 in 金融

Download history 238/week @ 2024-06-22 206/week @ 2024-06-29 158/week @ 2024-07-06 119/week @ 2024-07-13 122/week @ 2024-07-20 132/week @ 2024-07-27 119/week @ 2024-08-03 125/week @ 2024-08-10 137/week @ 2024-08-17

515次每月下载

MIT/Apache

73KB
1.5K SLoC

m4rs - Rust移动平均

crates.io

  • 交易指标库
  • 小巧简单实现
  • 无额外依赖
  • 支持以下指标
    • ATR
    • Awesome Oscillator
    • 布林带
    • CCI
    • DEMA
    • DMI/ADX
    • EMA
    • envelopes
    • Heikin Ashi
    • HMA
    • Ichimoku Kinko Hyo
    • MACD
    • Momentum
    • Parabolic SAR
    • RCI
    • RMA
    • RSI
    • SMA
    • 标准差
    • Stochastics (Fast, Slow)
    • TEMA
    • VWMA
    • Williams %R
    • WMA
  • 称为“Mars”

安装

cargo add m4rs

示例

// Prepare candlesticks in some way such as by retrieving them from the exchange's API
// And make them into m4rs::Candlestick objects
let entries: Vec<m4rs::Candlestick> = vec![
    (1719400001, 100.0, 130.0, 90.0, 110.0, 1000.0),
    (1719400002, 110.0, 140.0, 100.0, 130.0, 1000.0),
    (1719400003, 130.0, 135.0, 120.0, 120.0, 1000.0),
    (1719400004, 120.0, 130.0, 80.0, 90.0, 1000.0),
    (1719400005, 90.0, 100.0, 70.0, 80.0, 1000.0),
    (1719400006, 80.0, 180.0, 60.0, 120.0, 1000.0),
    (1719400007, 120.0, 210.0, 110.0, 180.0, 1000.0),
    (1719400008, 180.0, 185.0, 170.0, 180.0, 1000.0),
    (1719400009, 180.0, 220.0, 140.0, 200.0, 1000.0),
]
.iter()
.map(|(at, o, h, l, c, v)| m4rs::Candlestick::new(*at, *o, *h, *l, *c, *v))
.collect();

// Get 3SMA calculation result
let result = m4rs::sma(&entries, 3).unwrap();

for x in &result {
    println!("{}: {:.1}", x.at, x.value);
}
// 1719400003: 120.0
// 1719400004: 113.3
// 1719400005: 96.7
// 1719400006: 96.7
// 1719400007: 126.7
// 1719400008: 160.0
// 1719400009: 186.7

API参考

无运行时依赖