use traquer::statistic::regression::*; mod common; #[test] fn test_mse() { let stats = common::test_data(); let result = mse(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( vec![ 25.0, 14.789798693847843, 41.80790510457397, 40.38594878463846, 39.460837932740105, 34.710045583599516, 29.867181340247043, 28.391596172716163, 26.01725305209887, 23.46881768005551, 22.169915400281422, 20.839098146821925, 19.719941450262784, 18.547974124469743, 17.479982548520397, 16.663108238694804, 15.741748930536286, 14.981608931136886, 14.201950559754838, 13.926978256834264, 13.27716494489245, 12.74354854569736, 12.218715978471902, 11.71110695762521, 11.266317181275808, 11.09299774745215, 10.880636212498993, 10.610342022379752, 10.374113601077939, 10.16976333630737, 9.924286942142286, 9.641181117938686, 9.777435853090013, 9.585688507460445, ], result ); } #[test] fn test_rmse() { let stats = common::test_data(); let result = rmse(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( mse(&stats.close, &stats.high) .map(|x| x.sqrt()) .collect::>(), result ); } #[test] fn test_mae() { let stats = common::test_data(); let result = mae(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( vec![ 5.0, 3.5699996948242188, 5.643333435058594, 5.734999656677246, 5.783999633789063, 5.371665954589844, 4.732856205531529, 4.672499179840088, 4.447777218288845, 4.075999450683594, 3.9809084805575283, 3.8566662470499673, 3.7529226449819713, 3.614856719970703, 3.4798662821451822, 3.3936245441436768, 3.2528231003705192, 3.151833004421658, 3.0075259961579976, 3.0046497344970704, 2.8868092128208707, 2.8119543248956855, 2.7253476018491, 2.6197080612182617, 2.5456797790527346, 2.5477691063514123, 2.539148118760851, 2.5134642464773997, 2.4936551061169854, 2.479199981689453, 2.450838642735635, 2.4033124446868896, 2.4444241379246567, 2.4256175546085132 ], result ); } #[test] fn test_mape() { let stats = common::test_data(); let result = mape(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( vec![ 10.869565217391305, 7.224079780059318, 9.82808453046002, 9.972794272967613, 10.403214971998818, 9.869402901833887, 8.714336763817764, 8.755604321509157, 8.425932445909215, 7.736829428643285, 7.630348959382129, 7.455597968038579, 7.3404487870393265, 7.108068994900376, 6.884966616732182, 6.782780964767841, 6.526777636953273, 6.3677078613281495, 6.084288589449163, 6.140886376936299, 5.908496604711524, 5.771557986517684, 5.603244458848264, 5.388425196040363, 5.240596839038663, 5.25511167683952, 5.253414080726349, 5.207466054214349, 5.1680702497721995, 5.143028328371067, 5.08404951195821, 4.984003953857399, 5.054645398122806, 5.013674348870559, ], result ); } #[test] fn test_smape() { let stats = common::test_data(); let result = smape(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( vec![ 10.309278350515463, 6.912483291571219, 9.269894351681222, 9.425467593055519, 9.826743641750468, 9.347307386005967, 8.26457324580098, 8.313146671710687, 8.014545157816704, 7.365411878300978, 7.27372561132519, 7.116279261147159, 7.01397060076308, 6.799064210679083, 6.591932840353765, 6.499668845558642, 6.258602267518184, 6.1107700219673236, 5.840620884034387, 5.89683687819611, 5.6756924602958, 5.547457157523905, 5.388109464302675, 5.18221251742101, 5.042064419304636, 5.058311391390701, 5.059004973313347, 5.01724477059905, 4.9816160856665626, 4.959608182859544, 4.904802917750622, 4.8098102061126635, 4.877908497316335, 4.8401993453835095, ], result ); } #[test] fn test_mda() { let stats = common::test_data(); let result = mda(&stats.close, &stats.high).collect::>(); assert_eq!(stats.close.len(), result.len()); assert_eq!( vec![ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.8571428571428571, 0.75, 0.7777777777777778, 0.7, 0.6363636363636364, 0.6666666666666666, 0.6923076923076923, 0.7142857142857143, 0.7333333333333333, 0.75, 0.7647058823529411, 0.7777777777777778, 0.7368421052631579, 0.75, 0.7619047619047619, 0.7727272727272727, 0.782608695652174, 0.7916666666666666, 0.8, 0.7692307692307693, 0.7777777777777778, 0.7857142857142857, 0.7586206896551724, 0.7666666666666667, 0.7741935483870968, 0.78125, 0.7878787878787878, ], result[1..] ); }