我正在使用ta库计算指数移动平均线。目前,我使用迭代器添加每个close
值。next
我想要做的是将 ema 的输入限制为 201 个值(当您在 201 个输入值或例如 500 个输入值上计算 ema200 时,输出是不同的)。这有可能吗?
use ta::indicators::ExponentialMovingAverage as EMA;
use ta::Next;
pub fn main() {
let mut reader = csv::Reader::from_path("datafile.csv").unwrap();
let mut ema = EMA::new(200).unwrap();
for record in reader.deserialize() {
let (timestamp, open, high, low, close, volume): (String, f64, f64, f64, f64, f64) = record.unwrap();
let ema_val = ema.next(close);
println!("{} - ema: {}", timestamp, ema_val);
}
}
我的数据文件看起来像这样:
timestamp,open,high,low,close,volume
2017-01-03,757.919983,758.760010,747.700012,753.669983,3521100
2017-01-04,758.390015,759.679993,754.200012,757.179993,2510500
2017-01-05,761.549988,782.400024,760.260010,780.450012,5830100
2017-01-06,782.359985,799.440002,778.479980,795.989990,5986200
2017-01-09,798.000000,801.770020,791.770020,796.919983,3440100
2017-01-10,796.599976,798.000000,789.539978,795.900024,2558400
2017-01-11,793.659973,799.500000,789.510010,799.020020,2992800
2017-01-12,800.309998,814.130005,799.500000,813.640015,4873900
2017-01-13,814.320007,821.650024,811.400024,817.140015,3791900
2017-01-17,815.700012,816.000000,803.440002,809.719971,3659400
2017-01-18,809.500000,811.729980,804.270020,807.479980,2354200
2017-01-19,810.000000,813.510010,807.320007,809.039978,2540800
2017-01-20,815.280029,816.020020,806.260010,808.330017,3376200
2017-01-23,806.799988,818.500000,805.080017,817.880005,2797500
2017-01-24,822.000000,823.989990,814.500000,822.440002,2971700
2017-01-25,825.789978,837.419983,825.289978,836.520020,3922600
2017-01-26,835.530029,843.840027,833.000000,839.150024,3586300
2017-01-27,839.000000,839.700012,829.440002,835.770020,2998700
2017-01-30,833.000000,833.500000,816.380005,830.380005,3747300
2017-01-31,823.750000,826.989990,819.559998,823.479980,3137200