-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added McGinley Dynamic, Average True Range, True Range, and On-Balanc…
…e Volume. Changed TEST_DATA into TestData struct. Added 365 candles test data. Split up `Line` trait into individual `Period, Value, and Next` traits. New trait, `AsValue` used to allow for specialized values to be passed to `Next` Varied Output from `Next` added. README updates.
- Loading branch information
Showing
33 changed files
with
1,953 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! Demonstrates how to initialize and use an ATR. | ||
use tatk::indicators::ATR; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 14; | ||
let candles = TestData::candles(); | ||
|
||
println!("Data (total): {:?}", candles.len()); | ||
println!("Period: {}", period); | ||
|
||
// Create the ATR. | ||
let mut atr = match ATR::new(period, &candles[..candles.len() - 2]) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
// Extract last candle. | ||
let last_candle = candles[candles.len() - 1]; | ||
|
||
println!("\nATR: {}", atr.value()); | ||
println!("Adding last candle. New ATR: {}", atr.next(last_candle)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
//! Demonstrates how to initialize and use a DEMA. | ||
use tatk::indicators::DEMA; | ||
use tatk::test_data::TEST_DATA; | ||
use tatk::traits::Line; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 10; | ||
const DATA: &[f64] = TestData::talib(); | ||
|
||
println!("Data: {:?}", TEST_DATA); | ||
println!("Data: {:?}", DATA); | ||
println!("Period: {}", period); | ||
|
||
let mut dema = match DEMA::new(period, TEST_DATA) { | ||
let mut dema = match DEMA::new(period, DATA) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
println!("\nDEMA: {}", dema.value()); | ||
println!("Adding 107.00. New DEMA: {}", dema.next(107.000000)); | ||
println!("Adding 107.00. New DEMA: {}", dema.next(107.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
//! Demonstrates how to initialize and use a EMA. | ||
use tatk::indicators::EMA; | ||
use tatk::test_data::TEST_DATA; | ||
use tatk::traits::Line; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 10; | ||
const DATA: &[f64] = TestData::talib(); | ||
|
||
println!("Data: {:?}", TEST_DATA); | ||
println!("Data: {:?}", DATA); | ||
println!("Period: {}", period); | ||
|
||
let mut ema = match EMA::new(period, TEST_DATA) { | ||
let mut ema = match EMA::new(period, DATA) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
println!("\nEMA: {}", ema.value()); | ||
println!("Adding 107.00. New EMA: {}", ema.next(107.000000)); | ||
println!("Adding 107.00. New EMA: {}", ema.next(107.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
//! Demonstrates how to initialize and use a MACD. | ||
use tatk::indicators::MACD; | ||
use tatk::test_data::TEST_DATA; | ||
use tatk::traits::Line; | ||
|
||
// const TEST_DATA: &[f64] = &[ | ||
// 11.13, 11.3, 11.59, 11.71, 11.8, 11.8, 12.07, 12.14, 12.04, 12.02, 12.34, 12.61, 12.59, 12.66, | ||
// 12.82, 12.93, 12.79, 12.21, | ||
// ]; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 10; | ||
const DATA: &[f64] = TestData::talib(); | ||
|
||
println!("Data: {:?}", TEST_DATA); | ||
println!("Data: {:?}", DATA); | ||
println!("Period: {}", period); | ||
|
||
let mut macd = match MACD::new(12, 26, 9, TEST_DATA) { | ||
let mut macd = match MACD::new(12, 26, 9, DATA) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
println!("\nMACD: {}, signal: {}", macd.value(), macd.signal_value()); | ||
println!("Adding 107.00. New MACD: {}", macd.next(107.000000)); | ||
println!("Adding 107.00. New MACD: {}", macd.next(107.0).1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Demonstrates how to initialize and use a MD. | ||
use tatk::indicators::MD; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 10; | ||
let k: f64 = 0.6; | ||
const DATA: &[f64] = TestData::talib(); | ||
|
||
println!("Data: {:?}", DATA); | ||
println!("Period: {}", period); | ||
|
||
let mut md = match MD::new(period, DATA, k) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
println!("\nMD: {}", md.value()); | ||
println!("Adding 107.00. New MD: {}", md.next(107.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! Demonstrates how to initialize and use an OBV. | ||
use tatk::indicators::OBV; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 14; | ||
let candles = TestData::candles(); | ||
|
||
println!("Data (total): {:?}", candles.len()); | ||
println!("Period: {}", period); | ||
|
||
// Create the OBV. | ||
let mut atr = match OBV::new(period, &candles[..candles.len() - 2]) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
// Extract last candle. | ||
let last_candle = candles[candles.len() - 1]; | ||
|
||
println!("\nOBV: {}", atr.value()); | ||
println!("Adding last candle. New OBV: {}", atr.next(last_candle)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
//! Demonstrates how to initialize and use a SMA. | ||
use tatk::indicators::SMA; | ||
use tatk::test_data::TEST_DATA; | ||
use tatk::traits::Line; | ||
use tatk::test_data::TestData; | ||
use tatk::traits::{Next, Value}; | ||
|
||
fn main() { | ||
let period: usize = 10; | ||
const DATA: &[f64] = TestData::talib(); | ||
|
||
println!("Data: {:?}", TEST_DATA); | ||
println!("Data: {:?}", DATA); | ||
println!("Period: {}", period); | ||
|
||
let mut sma = match SMA::new(period, TEST_DATA) { | ||
let mut sma = match SMA::new(period, DATA) { | ||
Ok(value) => value, | ||
Err(error) => panic!("{}", error), | ||
}; | ||
|
||
println!("\nSMA: {}", sma.value()); | ||
println!("Adding 107.00. New SMA: {}", sma.next(107.000000)); | ||
println!("Adding 107.00. New SMA: {}", sma.next(107.0)); | ||
} |
Oops, something went wrong.