strategy

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package strategy implements technical analysis strategies as CLI subcommands. Each strategy is a pure computation function + a display wrapper.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBollCLI

func NewBollCLI() *cobra.Command

func NewMACDCLI

func NewMACDCLI() *cobra.Command

func NewMACLI

func NewMACLI() *cobra.Command

func NewRSICLI

func NewRSICLI() *cobra.Command

func NewStrategyCLI

func NewStrategyCLI() *cobra.Command

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL