Skip to content

Commit 3a91894

Browse files
weekend commit
1 parent 335f659 commit 3a91894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+17998
-1
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ Cargo.lock
88

99
# These are backup files generated by rustfmt
1010
**/*.rs.bk
11+
12+
13+
# Added by cargo
14+
#
15+
# already existing elements were commented out
16+
17+
/target
18+
/refs

Cargo.toml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "ux-indicators"
3+
version = "0.1.0"
4+
authors = ["Victor Dudochkin <[email protected]>"]
5+
readme = "README.md"
6+
homepage = "https://angular-rust.github.io/ux-indicators"
7+
repository = "https://github.com/angular-rust/ux-indicators"
8+
documentation = "https://docs.rs/ux-indicators"
9+
description = "Technical Analysis Function Library"
10+
keywords = ["technical-analysis", "financial-analysis", "technical-analysis-library", "technical-analysis-indicators"]
11+
categories = ["mathematics", "science"]
12+
edition = "2018"
13+
license = "MPL-2.0"
14+
15+
[badges]
16+
maintenance = { status = "actively-developed" }
17+
18+
[dependencies]
19+
serde = "1.0"
20+
serde_json = "1.0"
21+
serde_derive = "1.0"
22+
lazy_static = "1.4.0"
23+
error-chain = "0.12"
24+
ux-primitives = { git = "https://github.com/angular-rust/ux-primitives.git" }
25+
26+
rust_decimal = "1.7.0"
27+
rust_decimal_macros = "1.7.0"
28+
29+
[dev-dependencies]
30+
31+
assert_approx_eq = "1.1.0"
32+
csv = "1.1.3"
33+
bencher = "0.1.5"
34+
rand = "0.7.3"
35+
json = "0.12.4"
36+
lazy_static = "1.4.0"
37+
rspec = "0.1.0"
38+
# cucumber = { package = "cucumber_rust", version = "^0.6.0" }
39+
cucumber_rust = "0.6.8"
40+
# cucumber = "0.3.1"
41+
42+
43+
[[bench]]
44+
name = "indicators"
45+
path = "benches/indicators.rs"
46+
harness = false

README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
# ux-indicators
1+
# ux-indicators
2+
3+
Actively WIP
4+
5+
```rust
6+
pub struct FlowMeta<'a> {
7+
pub name: &'a str,
8+
pub tag: u8,
9+
pub visible: bool
10+
}
11+
12+
pub struct DataFrame<M, D>
13+
where
14+
M: fmt::Display,
15+
{
16+
// metric contain something like a timestamp, or month names
17+
pub metric: M,
18+
// data key is tag for stream meta (a.k.a column tag)
19+
// D is
20+
pub data: HashMap<u8, D>,
21+
}
22+
23+
```

benches/indicators.rs.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#[macro_use]
2+
extern crate bencher;
3+
extern crate core;
4+
5+
use bencher::Bencher;
6+
use rand::Rng;
7+
use core::indicators::{
8+
BollingerBands, EfficiencyRatio, ExponentialMovingAverage, FastStochastic, Maximum, Minimum,
9+
MoneyFlowIndex, MovingAverageConvergenceDivergence, OnBalanceVolume, RateOfChange,
10+
RelativeStrengthIndex, SimpleMovingAverage, SlowStochastic, StandardDeviation, TrueRange,
11+
};
12+
use core::DataItem;
13+
use core::Next;
14+
15+
const ITEMS_COUNT: usize = 5_000;
16+
17+
fn rand_data_item() -> DataItem {
18+
let mut rng = rand::thread_rng();
19+
20+
let low = rng.gen_range(0.0, 500.0);
21+
let high = rng.gen_range(500.0, 1000.0);
22+
let open = rng.gen_range(low, high);
23+
let close = rng.gen_range(low, high);
24+
let volume = rng.gen_range(0.0, 10_000.0);
25+
26+
DataItem::builder()
27+
.open(open)
28+
.high(high)
29+
.low(low)
30+
.close(close)
31+
.volume(volume)
32+
.build()
33+
.unwrap()
34+
}
35+
36+
macro_rules! bench_indicators {
37+
($($indicator:ident), *) => {
38+
$(
39+
fn $indicator(bench: &mut Bencher) {
40+
let items: Vec<DataItem> = (0..ITEMS_COUNT).map( |_| rand_data_item() ).collect();
41+
let mut indicator = $indicator::default();
42+
43+
bench.iter(|| {
44+
for item in items.iter() {
45+
indicator.next(item);
46+
}
47+
})
48+
}
49+
)*
50+
51+
benchmark_group!(benches, $($indicator,)*);
52+
benchmark_main!(benches);
53+
}
54+
}
55+
56+
bench_indicators!(
57+
SimpleMovingAverage,
58+
ExponentialMovingAverage,
59+
StandardDeviation,
60+
BollingerBands,
61+
EfficiencyRatio,
62+
FastStochastic,
63+
Maximum,
64+
Minimum,
65+
MovingAverageConvergenceDivergence,
66+
RateOfChange,
67+
RelativeStrengthIndex,
68+
SlowStochastic,
69+
TrueRange,
70+
MoneyFlowIndex,
71+
OnBalanceVolume
72+
);

examples/data/AMZN.csv

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Date,Open,High,Low,Close,Volume
2+
2017-01-03,757.919983,758.760010,747.700012,753.669983,3521100
3+
2017-01-04,758.390015,759.679993,754.200012,757.179993,2510500
4+
2017-01-05,761.549988,782.400024,760.260010,780.450012,5830100
5+
2017-01-06,782.359985,799.440002,778.479980,795.989990,5986200
6+
2017-01-09,798.000000,801.770020,791.770020,796.919983,3440100
7+
2017-01-10,796.599976,798.000000,789.539978,795.900024,2558400
8+
2017-01-11,793.659973,799.500000,789.510010,799.020020,2992800
9+
2017-01-12,800.309998,814.130005,799.500000,813.640015,4873900
10+
2017-01-13,814.320007,821.650024,811.400024,817.140015,3791900
11+
2017-01-17,815.700012,816.000000,803.440002,809.719971,3659400
12+
2017-01-18,809.500000,811.729980,804.270020,807.479980,2354200
13+
2017-01-19,810.000000,813.510010,807.320007,809.039978,2540800
14+
2017-01-20,815.280029,816.020020,806.260010,808.330017,3376200
15+
2017-01-23,806.799988,818.500000,805.080017,817.880005,2797500
16+
2017-01-24,822.000000,823.989990,814.500000,822.440002,2971700
17+
2017-01-25,825.789978,837.419983,825.289978,836.520020,3922600
18+
2017-01-26,835.530029,843.840027,833.000000,839.150024,3586300
19+
2017-01-27,839.000000,839.700012,829.440002,835.770020,2998700
20+
2017-01-30,833.000000,833.500000,816.380005,830.380005,3747300
21+
2017-01-31,823.750000,826.989990,819.559998,823.479980,3137200

examples/ema.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate csv;
2+
extern crate core;
3+
4+
use ux_indicators::{
5+
indicators::ExponentialMovingAverage as Ema,
6+
DataItem,
7+
Next
8+
9+
};
10+
11+
fn main() {
12+
let mut ema = Ema::new(9).unwrap();
13+
let mut reader = csv::Reader::from_path("./examples/data/AMZN.csv").unwrap();
14+
15+
for record in reader.deserialize() {
16+
let (date, open, high, low, close, volume): (String, f64, f64, f64, f64, f64) =
17+
record.unwrap();
18+
let dt = DataItem::builder()
19+
.open(open)
20+
.high(high)
21+
.low(low)
22+
.close(close)
23+
.volume(volume)
24+
.build()
25+
.unwrap();
26+
let ema_val = ema.next(&dt);
27+
println!("{}: {} = {:2.2}", date, ema, ema_val);
28+
}
29+
}

0 commit comments

Comments
 (0)