Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 23, 2024
1 parent 4073c9f commit fd89e3d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
6 changes: 4 additions & 2 deletions ta_lib/strategies/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ extern crate alloc;
mod constants;
mod ffi;
mod model;
mod price;
mod source;
mod strategy;
mod traits;
mod volatility;

pub mod prelude {
pub use crate::constants::*;
pub use crate::ffi::*;
pub use crate::model::{OHLCVSeries, OHLCV};
pub use crate::price::*;
pub use crate::source::*;
pub use crate::strategy::{BaseStrategy, StopLossLevels, TradeAction};
pub use crate::traits::*;
pub use crate::volatility::*;
}

pub use prelude::*;
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use crate::OHLCVSeries;
use core::prelude::*;
use price::prelude::*;
use volatility::{atr, tr};

pub trait Price {
pub trait Source {
fn hl2(&self) -> Series<f32>;
fn hlc3(&self) -> Series<f32>;
fn hlcc4(&self) -> Series<f32>;
fn ohlc4(&self) -> Series<f32>;
fn atr(&self, period: usize, smooth_type: Smooth) -> Series<f32>;
fn tr(&self) -> Series<f32>;
}

impl Price for OHLCVSeries {
impl Source for OHLCVSeries {
#[inline]
fn hl2(&self) -> Series<f32> {
median_price(&self.high, &self.low)
Expand All @@ -32,14 +29,4 @@ impl Price for OHLCVSeries {
fn ohlc4(&self) -> Series<f32> {
average_price(&self.open, &self.high, &self.low, &self.close)
}

#[inline]
fn atr(&self, period: usize, smooth_type: Smooth) -> Series<f32> {
atr(&self.high, &self.low, &self.close, smooth_type, period)
}

#[inline]
fn tr(&self) -> Series<f32> {
tr(&self.high, &self.low, &self.close)
}
}
4 changes: 2 additions & 2 deletions ta_lib/strategies/base/src/strategy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::price::Price;
use crate::source::Source;
use crate::{BaseLine, Confirm, Exit, OHLCVSeries, Pulse, Signal, StopLoss, Strategy, OHLCV};
use core::prelude::*;
use std::collections::VecDeque;
Expand Down Expand Up @@ -170,7 +170,7 @@ impl BaseStrategy {

#[cfg(test)]
mod tests {
use crate::price::Price;
use crate::source::Source;
use crate::{
BaseLine, BaseStrategy, Confirm, Exit, OHLCVSeries, Pulse, Signal, StopLoss, Strategy,
TradeAction, OHLCV,
Expand Down
20 changes: 20 additions & 0 deletions ta_lib/strategies/base/src/volatility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::OHLCVSeries;
use core::prelude::*;
use volatility::{atr, tr};

pub trait Volatility {
fn atr(&self, period: usize, smooth_type: Smooth) -> Series<f32>;
fn tr(&self) -> Series<f32>;
}

impl Volatility for OHLCVSeries {
#[inline]
fn atr(&self, period: usize, smooth_type: Smooth) -> Series<f32> {
atr(&self.high, &self.low, &self.close, smooth_type, period)
}

#[inline]
fn tr(&self) -> Series<f32> {
tr(&self.high, &self.low, &self.close)
}
}

0 comments on commit fd89e3d

Please sign in to comment.