gitee.com/quant1x/engine@v1.8.4/factors/feature_box_qsfz.go (about)

     1  package factors
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/utils"
     5  	"gitee.com/quant1x/exchange"
     6  	"gitee.com/quant1x/num"
     7  	"gitee.com/quant1x/pandas"
     8  	. "gitee.com/quant1x/pandas/formula"
     9  )
    10  
    11  // QuShiFanZhuan 趋势反转
    12  type QuShiFanZhuan struct {
    13  	QSFZ bool    // 反转信号
    14  	CP   float64 // 股价涨幅
    15  	CV   float64 // 成交量涨幅
    16  	VP   float64 // 价量比
    17  	VP3  float64 // 3日价量比
    18  	VP5  float64 // 5日价量比
    19  }
    20  
    21  // 趋势反转
    22  func computeQuShiFanZhuan(date string, OPEN, CLOSE, HIGH, LOW, VOL pandas.Series) *QuShiFanZhuan {
    23  	CURRBARSCOUNT := utils.IndexReverse(OPEN)
    24  	// {趋势反转, V1.0.7, 2023-09-15}
    25  	// MV5:=MA(VOL,5);
    26  	MV5 := MA(VOL, 5)
    27  	// LB0:VOL/REF(MV5,1),NODRAW;
    28  	R1MV5 := REF(MV5, 1)
    29  	LB0 := VOL.Div(R1MV5)
    30  	// FIX:=IFF(CURRBARSCOUNT=1,FROMOPEN/TOTALFZNUM,1);
    31  	FIX := IFF(CURRBARSCOUNT.Eq(1), float64(exchange.Minutes(date))/float64(exchange.CN_DEFAULT_TOTALFZNUM), 1.00)
    32  	// LB:LB0/FIX,NODRAW;
    33  	LB := LB0.Div(FIX)
    34  	// NVOL:LB*REF(MV5,1),NODRAW;
    35  	NVOL := R1MV5.Mul(LB)
    36  	// CVOL:VOL,NODRAW;
    37  	// XVOL:=NVOL;
    38  	XVOL := NVOL
    39  	// CVX:VOL/REF(VOL,1),NODRAW;
    40  	// QSCV:XVOL/REF(VOL,1),NODRAW;
    41  	//cv := VOL.Div(REF(VOL, 1))
    42  	cv := XVOL.Div(REF(VOL, 1))
    43  	// QSCP:(CLOSE/REF(CLOSE,1)-1)*100;
    44  	cp := CLOSE.Div(REF(CLOSE, 1)).Sub(1.00).Mul(100)
    45  	//cp := CLOSE.Div(REF(CLOSE, 1))
    46  	//cp = cp.Sub(1)
    47  	//fmt.Println(cp)
    48  	// QSVP:QSCP/QSCV;
    49  	vp := cp.Div(cv)
    50  	// QSVP3:MA(QSVP,3);
    51  	vp3 := MA(vp, 3)
    52  	// QSVP5:MA(QSVP,5);
    53  	vp5 := MA(vp, 5)
    54  	// VP20:=MA(QSVP,20);
    55  	// B:CROSS(QSVP,QSVP3),NODRAW;
    56  	// DRAWICON(B,CLOSE,1);
    57  	vpBuy := CROSS(vp, vp3)
    58  	fz := num.AnyToBool(vpBuy.IndexOf(-1))
    59  	qsfz := QuShiFanZhuan{
    60  		QSFZ: fz,
    61  		CV:   utils.SeriesIndexOf(cv, -1),
    62  		CP:   utils.SeriesIndexOf(cp, -1),
    63  		VP:   utils.SeriesIndexOf(vp, -1),
    64  		VP3:  utils.SeriesIndexOf(vp3, -1),
    65  		VP5:  utils.SeriesIndexOf(vp5, -1),
    66  	}
    67  	return &qsfz
    68  }