Documentation ¶
Index ¶
- Constants
- Variables
- func Close(candles []Candle) []float64
- func GetNewContextFromCandle(c Candle) context.Context
- func High(candles []Candle) []float64
- func Low(candles []Candle) []float64
- func NoAggregation(inputCandleChan <-chan Candle) <-chan AggregatedCandle
- func Open(candles []Candle) []float64
- func RandUid() string
- func RegisterViews(views ...*view.View)
- func SignalsToGrafana() []byte
- type AggregatedCandle
- type BacktestBrocker
- func (b *BacktestBrocker) AvailableCash() float64
- func (b *BacktestBrocker) ClosePosition(position Position) error
- func (b *BacktestBrocker) GetOrderByID(orderID string) (Order, error)
- func (b *BacktestBrocker) GetPosition(symbol Symbol) Position
- func (b *BacktestBrocker) GetPositions() []Position
- func (b *BacktestBrocker) ProcessOrders(candle Candle) []Order
- func (b *BacktestBrocker) Shutdown()
- func (b *BacktestBrocker) SubmitOrder(_ Candle, order Order) (string, error)
- type Broker
- type Candle
- type Cerbero
- type DataFeed
- type EvaluateCommissions
- type ExecutionResult
- type IBZippedCSV
- type MemorySignals
- type Metric
- type Order
- type OrderStatus
- type OrderType
- type Position
- type SimplePsarStrategy
- type Strategy
- type Symbol
- type TimeAggregation
- type TimeSerie
Constants ¶
View Source
const ( OrderBuy = iota OrderSell )
View Source
const ( OrderStatusSubmitted = iota OrderStatusAccepted OrderStatusPartiallyFilled OrderStatusFullFilled OrderStatusRejected )
Variables ¶
View Source
var ( ErrOrderNotFound = errors.New("order not found") ErrInvalidSize = errors.New("order.size should be > 0") )
View Source
var ( MetricActivePosition = NewMetricWithDefaultViews("broker_position") BrockerPosition = NewMetricWithDefaultViews("broker") // Stdout is used to log everything that is not considered an error Stdout = log.New(os.Stdout, "", log.Lshortfile|log.Ltime) // Stderr log errors that need attention Stderr = log.New(os.Stderr, "[ERROR]", log.Lmsgprefix|log.Lshortfile|log.Ltime) )
View Source
var ( ErrMetricNotFound = errors.New("metric not founc") MCandleOpen = NewMetricWithDefaultViews("candle_open") MCandleHigh = NewMetricWithDefaultViews("candle_high") MCandleClose = NewMetricWithDefaultViews("candle_close") MCandleLow = NewMetricWithDefaultViews("candle_low") MTradesBuy = NewMetricWithDefaultViews("trades_buy") MTradesSell = NewMetricWithDefaultViews("trades_sell") MCash = NewMetricWithDefaultViews("cash") MPosition = NewMetricWithDefaultViews("position") KeySymbol, _ = tag.NewKey("symbol") )
View Source
var Nocommissions = func(order Order, price float64) float64 { return 0 }
Functions ¶
func GetNewContextFromCandle ¶
func NoAggregation ¶
func NoAggregation(inputCandleChan <-chan Candle) <-chan AggregatedCandle
func RegisterViews ¶
RegisterViews register the Opencensus views and enable the internal TimeSeries collection
func SignalsToGrafana ¶
func SignalsToGrafana() []byte
Types ¶
type AggregatedCandle ¶
type BacktestBrocker ¶
type BacktestBrocker struct { BrokerAvailableCash float64 OrderMap map[string]*Order Portfolio map[Symbol]Position EvalCommissions EvaluateCommissions }
BacktestBrocker is the default broker to back-test a strategy
func (*BacktestBrocker) AvailableCash ¶
func (b *BacktestBrocker) AvailableCash() float64
func (*BacktestBrocker) ClosePosition ¶
func (b *BacktestBrocker) ClosePosition(position Position) error
ClosePosition @deprecated
func (*BacktestBrocker) GetOrderByID ¶
func (b *BacktestBrocker) GetOrderByID(orderID string) (Order, error)
func (*BacktestBrocker) GetPosition ¶
func (b *BacktestBrocker) GetPosition(symbol Symbol) Position
func (*BacktestBrocker) GetPositions ¶
func (b *BacktestBrocker) GetPositions() []Position
func (*BacktestBrocker) ProcessOrders ¶
func (b *BacktestBrocker) ProcessOrders(candle Candle) []Order
func (*BacktestBrocker) Shutdown ¶
func (b *BacktestBrocker) Shutdown()
func (*BacktestBrocker) SubmitOrder ¶
func (b *BacktestBrocker) SubmitOrder(_ Candle, order Order) (string, error)
type Broker ¶
type Broker interface { SubmitOrder(candle Candle, order Order) (string, error) GetOrderByID(OrderID string) (Order, error) ProcessOrders(candle Candle) []Order GetPosition(symbol Symbol) Position Shutdown() AvailableCash() float64 ClosePosition(position Position) error GetPositions() []Position }
Broker interacts with a stock broker
type Candle ¶
type Cerbero ¶
type Cerbero struct { Broker Broker Strategy Strategy DataFeed DataFeed TimeAggregationFunc TimeAggregation // contains filtered or unexported fields }
Cerbero is in honor to https://www.backtrader.com/ that deeply inspired this code
func (*Cerbero) Run ¶
func (cerbero *Cerbero) Run() (ExecutionResult, error)
type DataFeed ¶
type DataFeed interface { // Run starts a go routine that poll the data source, and push the candles in the returned channel. // The channel is expected to have a buffer larger enough to handle 1 day of data Run() (chan Candle, error) }
DataFeed provides a stream of Candle.
type EvaluateCommissions ¶
type ExecutionResult ¶
type IBZippedCSV ¶
type IBZippedCSV struct { DataFolder string Sday time.Time Slowtime int Symbol Symbol Symbols []Symbol }
func (*IBZippedCSV) Run ¶
func (d *IBZippedCSV) Run() (chan Candle, error)
type MemorySignals ¶
type Metric ¶
type Metric struct { Name string // contains filtered or unexported fields }
type Order ¶
type OrderStatus ¶
type OrderStatus int
type SimplePsarStrategy ¶
type SimplePsarStrategy struct {
Symbol Symbol
}
func (*SimplePsarStrategy) Eval ¶
func (s *SimplePsarStrategy) Eval(candles []Candle)
func (*SimplePsarStrategy) Initialize ¶
func (s *SimplePsarStrategy) Initialize(_ *Cerbero)
type TimeAggregation ¶
type TimeAggregation func(<-chan Candle) <-chan AggregatedCandle
TimeAggregation aggregate the candles from a channel and write the output in a separate channel
func AggregateBySeconds ¶
func AggregateBySeconds(sec int) TimeAggregation
Click to show internal directories.
Click to hide internal directories.