Documentation
¶
Overview ¶
Package strategy implements technical analysis strategies as CLI subcommands. Each strategy is a pure computation function + a display wrapper.
Index ¶
- func NewBollCLI() *cobra.Command
- func NewMACDCLI() *cobra.Command
- func NewMACLI() *cobra.Command
- func NewRSICLI() *cobra.Command
- func NewStrategyCLI() *cobra.Command
- type Signal
- func ComputeBollinger(quotes []*eastmoney.Quote, period int, k float64) (headers []string, data [][]string, signals []Signal)
- func ComputeMA(quotes []*eastmoney.Quote, fastPeriod, slowPeriod int) (headers []string, data [][]string, signals []Signal)
- func ComputeMACD(quotes []*eastmoney.Quote, fast, slow, signal int) (headers []string, data [][]string, signals []Signal)
- func ComputeRSI(quotes []*eastmoney.Quote, period int, overbought, oversold float64) (headers []string, data [][]string, signals []Signal)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBollCLI ¶
func NewMACDCLI ¶
func NewStrategyCLI ¶
NewStrategyCLI returns the parent strategy command with subcommands.
Types ¶
type Signal ¶
type Signal struct {
Date time.Time
Type string // "buy", "sell", "hold"
Price float64
Reason string
}
Signal represents a trading signal at a specific date.
func ComputeBollinger ¶
func ComputeBollinger(quotes []*eastmoney.Quote, period int, k float64) (headers []string, data [][]string, signals []Signal)
ComputeBollinger calculates Bollinger Bands:
Middle = SMA(period) Upper = Middle + k × σ Lower = Middle - k × σ
Buy when price touches lower band and starts rising. Sell when price touches upper band and starts falling.
func ComputeMA ¶
func ComputeMA(quotes []*eastmoney.Quote, fastPeriod, slowPeriod int) (headers []string, data [][]string, signals []Signal)
ComputeMA calculates fast and slow moving averages from closing prices. A buy signal is generated when fast MA crosses above slow MA (golden cross). A sell signal is generated when fast MA crosses below slow MA (dead cross).
func ComputeMACD ¶
func ComputeMACD(quotes []*eastmoney.Quote, fast, slow, signal int) (headers []string, data [][]string, signals []Signal)
ComputeMACD calculates the MACD indicator:
MACD = EMA(fast) - EMA(slow) Signal = EMA(MACD, signalPeriod) Histogram = MACD - Signal
A buy signal fires when MACD crosses above Signal; sell when below.
func ComputeRSI ¶
func ComputeRSI(quotes []*eastmoney.Quote, period int, overbought, oversold float64) (headers []string, data [][]string, signals []Signal)
ComputeRSI calculates the Relative Strength Index for a given period. RSI > overbought suggests overbought (sell signal when crossing back down). RSI < oversold suggests oversold (buy signal when crossing back up).