drift

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ID = "drift"

Variables

View Source
var Fee = 0.0008 // taker fee % * 2, for upper bound

Functions

This section is empty.

Types

type DriftMA

type DriftMA struct {
	types.SeriesBase
	// contains filtered or unexported fields
}

func (*DriftMA) Clone

func (s *DriftMA) Clone() *DriftMA

func (*DriftMA) Index

func (s *DriftMA) Index(i int) float64

func (*DriftMA) Last

func (s *DriftMA) Last(i int) float64

func (*DriftMA) Length

func (s *DriftMA) Length() int

func (*DriftMA) TestUpdate

func (s *DriftMA) TestUpdate(v, weight float64) *DriftMA

func (*DriftMA) Update

func (s *DriftMA) Update(value, weight float64)

func (*DriftMA) ZeroPoint

func (s *DriftMA) ZeroPoint() float64

type Strategy

type Strategy struct {
	Symbol string `json:"symbol"`

	bbgo.OpenPositionOptions
	bbgo.StrategyController
	types.Market
	types.IntervalWindow
	bbgo.SourceSelector

	*bbgo.Environment
	*types.Position    `persistence:"position"`
	*types.ProfitStats `persistence:"profit_stats"`
	*types.TradeStats  `persistence:"trade_stats"`

	MinInterval types.Interval `json:"MinInterval"` // minimum interval referred for doing stoploss/trailing exists and updating highest/lowest

	Debug                     bool             `json:"debug" modifiable:"true"`                // to print debug message or not
	UseStopLoss               bool             `json:"useStopLoss" modifiable:"true"`          // whether to use stoploss rate to do stoploss
	UseAtr                    bool             `json:"useAtr" modifiable:"true"`               // use atr as stoploss
	StopLoss                  fixedpoint.Value `json:"stoploss" modifiable:"true"`             // stoploss rate
	PredictOffset             int              `json:"predictOffset"`                          // the lookback length for the prediction using linear regression
	HighLowVarianceMultiplier float64          `json:"hlVarianceMultiplier" modifiable:"true"` // modifier to set the limit order price
	NoTrailingStopLoss        bool             `json:"noTrailingStopLoss" modifiable:"true"`   // turn off the trailing exit and stoploss
	HLRangeWindow             int              `json:"hlRangeWindow"`                          // ma window for kline high/low changes
	SmootherWindow            int              `json:"smootherWindow"`                         // window that controls the smoothness of drift
	FisherTransformWindow     int              `json:"fisherTransformWindow"`                  // fisher transform window to filter drift's negative signals
	ATRWindow                 int              `json:"atrWindow"`                              // window for atr indicator
	PendingMinInterval        int              `json:"pendingMinInterval" modifiable:"true"`   // if order not be traded for pendingMinInterval of time, cancel it.
	NoRebalance               bool             `json:"noRebalance" modifiable:"true"`          // disable rebalance
	TrendWindow               int              `json:"trendWindow"`                            // trendLine is used for rebalancing the position. When trendLine goes up, hold base, otherwise hold quote
	RebalanceFilter           float64          `json:"rebalanceFilter" modifiable:"true"`      // beta filter on the Linear Regression of trendLine
	TrailingCallbackRate      []float64        `json:"trailingCallbackRate" modifiable:"true"`
	TrailingActivationRatio   []float64        `json:"trailingActivationRatio" modifiable:"true"`

	// This is not related to trade but for statistics graph generation
	// Will deduct fee in percentage from every trade
	GraphPNLDeductFee bool   `json:"graphPNLDeductFee"`
	CanvasPath        string `json:"canvasPath"`       // backtest related. the path to store the indicator graph
	GraphPNLPath      string `json:"graphPNLPath"`     // backtest related. the path to store the pnl % graph per trade graph.
	GraphCumPNLPath   string `json:"graphCumPNLPath"`  // backtest related. the path to store the asset changes in graph
	GraphElapsedPath  string `json:"graphElapsedPath"` // the path to store the elapsed time in ms
	GenerateGraph     bool   `json:"generateGraph"`    // whether to generate graph when shutdown

	ExitMethods bbgo.ExitMethodSet `json:"exits"`
	Session     *bbgo.ExchangeSession

	*bbgo.FastOrderExecutor
	// contains filtered or unexported fields
}

func (*Strategy) CalcAssetValue

func (s *Strategy) CalcAssetValue(price fixedpoint.Value) fixedpoint.Value

func (*Strategy) CheckStopLoss

func (s *Strategy) CheckStopLoss() bool

func (*Strategy) ClosePosition

func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error

func (*Strategy) CurrentPosition

func (s *Strategy) CurrentPosition() *types.Position

func (*Strategy) Draw

func (s *Strategy) Draw(time types.Time, profit types.Series, cumProfit types.Series)

func (*Strategy) DrawCumPNL

func (s *Strategy) DrawCumPNL(cumProfit types.Series) *types.Canvas

func (*Strategy) DrawElapsed

func (s *Strategy) DrawElapsed() *types.Canvas

func (*Strategy) DrawIndicators

func (s *Strategy) DrawIndicators(time types.Time) *types.Canvas

func (*Strategy) DrawPNL

func (s *Strategy) DrawPNL(profit types.Series) *types.Canvas

func (*Strategy) ID

func (s *Strategy) ID() string

func (*Strategy) InitDrawCommands

func (s *Strategy) InitDrawCommands(profit, cumProfit types.Series)

func (*Strategy) InstanceID

func (s *Strategy) InstanceID() string

func (*Strategy) Print

func (s *Strategy) Print(f io.Writer, pretty bool, withColor ...bool)

func (*Strategy) Rebalance

func (s *Strategy) Rebalance(ctx context.Context)

Sending new rebalance orders cost too much. Modify the position instead to expect the strategy itself rebalance on Close

func (*Strategy) Run

func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error

func (*Strategy) SubmitOrder

func (s *Strategy) SubmitOrder(ctx context.Context, submitOrder types.SubmitOrder) (*types.Order, error)

func (*Strategy) Subscribe

func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)

Jump to

Keyboard shortcuts

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