第一版

This commit is contained in:
YuWuKunCheng
2026-05-25 02:16:35 +08:00
parent ff4e6ae570
commit f92eef11fb
37 changed files with 11615 additions and 0 deletions
+173
View File
@@ -0,0 +1,173 @@
use crate::kline::chan_kline::K线;
use crate::types::;
use crate::types::;
use std::rc::Rc;
/// 分型 — 由三根缠K构成(可能缺左或右)
#[derive(Debug, Clone)]
pub struct {
pub : Option<Rc<K线>>,
pub : Rc<K线>,
pub : Option<Rc<K线>>,
pub : ,
pub : i64,
pub : f64,
}
impl {
pub fn new(: Option<Rc<K线>>, : Rc<K线>, : Option<Rc<K线>>) -> Self {
let = ..unwrap_or(::);
let = .;
let = .;
Self {
,
,
,
,
,
,
}
}
/// 左中右三组关系
pub fn (&self) -> Option<(, , )> {
let = self..as_ref()?;
let = self..as_ref()?;
Some((
::(., ., self.., self..),
::(self.., self.., ., .),
::(., ., ., .),
))
}
/// 分型强度
pub fn (&self) -> f64 {
match self. {
:: | :: => {
if let Some(ref ) = self. {
self.. - .
} else {
0.0
}
}
:: | :: => {
if let Some(ref ) = self. {
. - self..
} else {
0.0
}
}
:: => 0.0,
}
}
/// MACD柱子分型匹配
pub fn MACD柱子分型匹配(&self) -> bool {
match self. {
:: | :: => {
if let Some(ref ) = self. {
.MACD柱子匹配()
} else {
false
}
}
:: | :: => {
if let Some(ref ) = self. {
.MACD柱子匹配()
} else {
false
}
}
:: => false,
}
}
/// 判断两个分型是否匹配
pub fn (: &, : &, : &str) -> bool {
match {
"" => .. == ..,
_ => false,
}
}
/// 从缠K序列中获取以指定缠K为中元素的分型
pub fn K序列中获取分型(K线序列: &[Rc<K线>], : &Rc<K线>) -> Option<Self> {
let idx = K线序列.iter().position(|k| Rc::as_ptr(k) == Rc::as_ptr())?;
let = if idx > 0 {
Some(Rc::clone(&K线序列[idx - 1]))
} else {
None
};
let = if idx + 1 < K线序列.len() {
Some(Rc::clone(&K线序列[idx + 1]))
} else {
None
};
Some(Self::new(, Rc::clone(), ))
}
/// 向分型序列中添加新分型
pub fn (: &mut Vec<Rc<>>, : Rc<>) {
if let Some() = .last() {
if . == . {
// 同一时间戳: 比较强度,保留更强的
match . {
:: | :: => {
if . >= . {
.pop();
.push();
}
return;
}
:: | :: => {
if . <= . {
.pop();
.push();
}
return;
}
:: => {}
}
}
// 相同结构只保留更强的
if . == . {
if (. == :: || . == ::)
&& . >= .
{
.pop();
.push();
} else if (. == :: || . == ::)
&& . <= .
{
.pop();
.push();
}
return;
}
}
.push();
}
}
impl crate::types::fractal:: for {
fn (&self) -> f64 {
self..
}
fn (&self) -> f64 {
self..
}
}
impl std::fmt::Display for {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}<{}, {}, None: {}, None: {}>",
self...unwrap_or(crate::types::::),
self.,
crate::utils::format_f64_g(self.),
if self..is_none() { "True" } else { "False" },
if self..is_none() { "True" } else { "False" },
)
}
}