Documentation ¶
Overview ¶
Package gobacktest is a simple placeholder to root all gobacktest documentation
Index ¶
- Constants
- type Algo
- type AlgoHandler
- type AlgoStack
- type Asset
- type Backtest
- func (t *Backtest) Reset() error
- func (t *Backtest) Run() error
- func (t *Backtest) SetData(data DataHandler)
- func (t *Backtest) SetExchange(exchange ExecutionHandler)
- func (t *Backtest) SetPortfolio(portfolio PortfolioHandler)
- func (t *Backtest) SetStatistic(statistic StatisticHandler)
- func (t *Backtest) SetStrategy(strategy StrategyHandler)
- func (t *Backtest) SetSymbols(symbols []string)
- func (t *Backtest) Stats() StatisticHandler
- type Bar
- type BarEvent
- type Booker
- type Casher
- type CommissionHandler
- type Data
- func (d *Data) History() []DataEvent
- func (d *Data) Latest(symbol string) DataEvent
- func (d *Data) List(symbol string) []DataEvent
- func (d *Data) Load(s []string) error
- func (d *Data) Next() (dh DataEvent, ok bool)
- func (d *Data) Reset() error
- func (d *Data) SetStream(stream []DataEvent)
- func (d *Data) SortStream()
- func (d *Data) Stream() []DataEvent
- type DataEvent
- type DataHandler
- type DataLoader
- type DataStreamer
- type Direction
- type Directioner
- type Event
- type EventHandler
- type EventTracker
- type Exchange
- type ExchangeFeeHandler
- type ExecutionHandler
- type Fill
- func (f Fill) Commission() float64
- func (f Fill) Cost() float64
- func (f Fill) Direction() Direction
- func (f Fill) ExchangeFee() float64
- func (f Fill) NetValue() float64
- func (f Fill) Price() float64
- func (f Fill) Qty() int64
- func (f *Fill) SetDirection(dir Direction)
- func (f *Fill) SetQty(i int64)
- func (f Fill) Value() float64
- type FillEvent
- type FixedCommission
- type FixedExchangeFee
- type IDer
- type Investor
- type Metric
- type MetricHandler
- type Node
- func (n Node) Children() ([]NodeHandler, bool)
- func (n Node) Name() string
- func (n Node) Root() bool
- func (n *Node) SetChildren(children ...NodeHandler) NodeHandler
- func (n *Node) SetName(s string) NodeHandler
- func (n *Node) SetRoot(b bool)
- func (n *Node) SetTolerance(t float64)
- func (n *Node) SetWeight(w float64)
- func (n Node) Tolerance() float64
- func (n Node) Weight() float64
- type NodeHandler
- type OnFiller
- type OnSignaler
- type Order
- func (o *Order) Cancel()
- func (o Order) Direction() Direction
- func (o Order) ID() int
- func (o Order) Limit() float64
- func (o Order) Qty() int64
- func (o *Order) SetDirection(dir Direction)
- func (o *Order) SetID(id int)
- func (o *Order) SetQty(i int64)
- func (o Order) Status() OrderStatus
- func (o Order) Stop() float64
- func (o *Order) Update(fill FillEvent)
- type OrderBook
- func (ob *OrderBook) Add(order OrderEvent) error
- func (ob OrderBook) OrderBy(fn func(order OrderEvent) bool) ([]OrderEvent, bool)
- func (ob OrderBook) Orders() ([]OrderEvent, bool)
- func (ob OrderBook) OrdersAskBySymbol(symbol string) ([]OrderEvent, bool)
- func (ob OrderBook) OrdersBidBySymbol(symbol string) ([]OrderEvent, bool)
- func (ob OrderBook) OrdersBySymbol(symbol string) ([]OrderEvent, bool)
- func (ob OrderBook) OrdersCanceled() ([]OrderEvent, bool)
- func (ob OrderBook) OrdersOpen() ([]OrderEvent, bool)
- func (ob *OrderBook) Remove(id int) error
- type OrderEvent
- type OrderStatus
- type OrderType
- type PercentageCommission
- type Portfolio
- func (p Portfolio) Cash() float64
- func (p Portfolio) Holdings() map[string]Position
- func (p Portfolio) InitialCash() float64
- func (p Portfolio) IsInvested(symbol string) (pos Position, ok bool)
- func (p Portfolio) IsLong(symbol string) (pos Position, ok bool)
- func (p Portfolio) IsShort(symbol string) (pos Position, ok bool)
- func (p *Portfolio) OnFill(fill FillEvent, data DataHandler) (*Fill, error)
- func (p *Portfolio) OnSignal(signal SignalEvent, data DataHandler) (*Order, error)
- func (p Portfolio) OrderBook() ([]OrderEvent, bool)
- func (p Portfolio) OrdersBySymbol(symbol string) ([]OrderEvent, bool)
- func (p *Portfolio) Reset() error
- func (p Portfolio) RiskManager() RiskHandler
- func (p *Portfolio) SetCash(cash float64)
- func (p *Portfolio) SetInitialCash(initial float64)
- func (p *Portfolio) SetRiskManager(risk RiskHandler)
- func (p *Portfolio) SetSizeManager(size SizeHandler)
- func (p Portfolio) SizeManager() SizeHandler
- func (p *Portfolio) Update(d DataEvent)
- func (p Portfolio) Value() float64
- type PortfolioHandler
- type Position
- type Pricer
- type Quantifier
- type Reseter
- type Resulter
- type Risk
- type RiskHandler
- type Signal
- type SignalEvent
- type Size
- type SizeHandler
- type Spreader
- type Statistic
- func (s Statistic) Events() []EventHandler
- func (s Statistic) MaxDrawdown() float64
- func (s Statistic) MaxDrawdownDuration() (d time.Duration)
- func (s Statistic) MaxDrawdownTime() time.Time
- func (s Statistic) PrintResult()
- func (s *Statistic) Reset() error
- func (s *Statistic) SharpRatio(riskfree float64) float64
- func (s *Statistic) SortinoRatio(riskfree float64) float64
- func (s Statistic) TotalEquityReturn() (r float64, err error)
- func (s *Statistic) TrackEvent(e EventHandler)
- func (s *Statistic) TrackTransaction(f FillEvent)
- func (s Statistic) Transactions() []FillEvent
- func (s *Statistic) Update(d DataEvent, p PortfolioHandler)
- type StatisticHandler
- type StatisticPrinter
- type StatisticUpdater
- type Strategy
- func (s *Strategy) AddSignal(signals ...SignalEvent) error
- func (s *Strategy) Assets() ([]*Asset, bool)
- func (s *Strategy) Data() (DataHandler, bool)
- func (s *Strategy) Event() (DataEvent, bool)
- func (s *Strategy) OnData(event DataEvent) (signals []SignalEvent, err error)
- func (s *Strategy) Portfolio() (PortfolioHandler, bool)
- func (s *Strategy) SetAlgo(algos ...AlgoHandler) *Strategy
- func (s *Strategy) SetData(data DataHandler) error
- func (s *Strategy) SetEvent(event DataEvent) error
- func (s *Strategy) SetPortfolio(portfolio PortfolioHandler) error
- func (s *Strategy) Signals() ([]SignalEvent, bool)
- func (s *Strategy) Strategies() ([]StrategyHandler, bool)
- type StrategyHandler
- type Symboler
- type Tick
- type TickEvent
- type Timer
- type TransactionTracker
- type TresholdFixedCommission
- type Updater
- type ValueCommission
- type Valuer
- type WeightHandler
Constants ¶
const DP = 4 // DP
DP sets the the precision of rounded floating numbers used after calculations to format
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Algo ¶ added in v0.3.0
type Algo struct {
// contains filtered or unexported fields
}
Algo is a base algo structure, implements AlgoHandler
func (Algo) Run ¶ added in v0.3.0
func (a Algo) Run(_ StrategyHandler) (bool, error)
Run implements the Algo interface.
type AlgoHandler ¶ added in v0.3.0
type AlgoHandler interface { Run(StrategyHandler) (bool, error) Always() bool SetAlways() Value() float64 }
AlgoHandler defines the base algorythm functionality.
func RunAlways ¶ added in v0.3.0
func RunAlways(a AlgoHandler) AlgoHandler
RunAlways set the runAlways property on the AlgoHandler
type AlgoStack ¶ added in v0.3.0
type AlgoStack struct { Algo // contains filtered or unexported fields }
AlgoStack represents a single stack of algos.
type Asset ¶ added in v0.3.0
type Asset struct {
Node
}
Asset is a data building block for the tree structure, eg. Stock, Option, Cash etc. It implements the NodeHandler interface via the promoted Node field.
func (Asset) Children ¶ added in v0.3.0
func (a Asset) Children() ([]NodeHandler, bool)
Children returns an empty slice and false, an Asset is not allowed to have children.
func (*Asset) SetChildren ¶ added in v0.3.0
func (a *Asset) SetChildren(c ...NodeHandler) NodeHandler
SetChildren return itself without change, as an Asset ist not allowed to have children.
type Backtest ¶ added in v0.3.0
type Backtest struct {
// contains filtered or unexported fields
}
Backtest is the main struct which holds all elements.
func New ¶
func New() *Backtest
New creates a default backtest with sensible defaults ready for use.
func (*Backtest) SetData ¶ added in v0.3.0
func (t *Backtest) SetData(data DataHandler)
SetData sets the data provider to be used within the backtest.
func (*Backtest) SetExchange ¶ added in v0.3.0
func (t *Backtest) SetExchange(exchange ExecutionHandler)
SetExchange sets the execution provider to be used within the backtest.
func (*Backtest) SetPortfolio ¶ added in v0.3.0
func (t *Backtest) SetPortfolio(portfolio PortfolioHandler)
SetPortfolio sets the portfolio provider to be used within the backtest.
func (*Backtest) SetStatistic ¶ added in v0.3.0
func (t *Backtest) SetStatistic(statistic StatisticHandler)
SetStatistic sets the statistic provider to be used within the backtest.
func (*Backtest) SetStrategy ¶ added in v0.3.0
func (t *Backtest) SetStrategy(strategy StrategyHandler)
SetStrategy sets the strategy provider to be used within the backtest.
func (*Backtest) SetSymbols ¶ added in v0.3.0
SetSymbols sets the symbols to include into the backtest.
func (*Backtest) Stats ¶ added in v0.3.0
func (t *Backtest) Stats() StatisticHandler
Stats returns the statistic handler of the backtest.
type Bar ¶ added in v0.3.0
type Bar struct { Event Metric Open float64 High float64 Low float64 Close float64 AdjClose float64 Volume int64 }
Bar declares a data event for an OHLCV bar.
type BarEvent ¶ added in v0.3.0
type BarEvent interface { DataEvent }
BarEvent declares a bar event interface.
type Booker ¶ added in v0.3.0
type Booker interface { OrderBook() ([]OrderEvent, bool) OrdersBySymbol(symbol string) ([]OrderEvent, bool) }
Booker defines methods for handling the order book of the portfolio
type Casher ¶ added in v0.3.0
type Casher interface { InitialCash() float64 SetInitialCash(float64) Cash() float64 SetCash(float64) }
Casher handles basic portolio info
type CommissionHandler ¶ added in v0.3.0
CommissionHandler is the basic interface for executing orders
type Data ¶ added in v0.3.0
type Data struct {
// contains filtered or unexported fields
}
Data is a basic data provider struct.
func (*Data) Load ¶ added in v0.3.0
Load data events into a stream. This method satisfies the DataLoader interface, but should be overwritten by the specific data loading implementation.
func (*Data) Next ¶ added in v0.3.0
Next returns the first element of the data stream, deletes it from the data stream and appends it to the historic data stream.
func (*Data) Reset ¶ added in v0.3.0
Reset implements Reseter to reset the data struct to a clean state with loaded data events.
func (*Data) SortStream ¶ added in v0.3.0
func (d *Data) SortStream()
SortStream sorts the data stream in ascending order.
type DataEvent ¶ added in v0.3.0
type DataEvent interface { EventHandler MetricHandler Pricer }
DataEvent declares a data event interface
type DataHandler ¶ added in v0.3.0
type DataHandler interface { DataLoader DataStreamer Reseter }
DataHandler is the combined data interface.
type DataLoader ¶ added in v0.3.0
DataLoader defines how to load data into the data stream.
type DataStreamer ¶ added in v0.3.0
type DataStreamer interface { Next() (DataEvent, bool) Stream() []DataEvent History() []DataEvent Latest(string) DataEvent List(string) []DataEvent }
DataStreamer defines data stream functionality.
type Direction ¶ added in v0.3.0
type Direction int
Direction defines which direction a signal indicates
type Directioner ¶ added in v0.3.0
Directioner defines a direction interface
type Event ¶ added in v0.3.0
type Event struct {
// contains filtered or unexported fields
}
Event is the implementation of the basic event interface.
type EventHandler ¶ added in v0.3.0
EventHandler declares the basic event interface
type EventTracker ¶ added in v0.3.0
type EventTracker interface { TrackEvent(EventHandler) Events() []EventHandler }
EventTracker is responsible for all event tracking during a backtest
type Exchange ¶ added in v0.3.0
type Exchange struct { Symbol string Commission CommissionHandler ExchangeFee ExchangeFeeHandler }
Exchange is a basic execution handler implementation
func NewExchange ¶ added in v0.3.0
func NewExchange() *Exchange
NewExchange creates a default exchange with sensible defaults ready for use.
func (*Exchange) OnOrder ¶ added in v0.3.0
func (e *Exchange) OnOrder(order OrderEvent, data DataHandler) (*Fill, error)
OnOrder executes an order event
type ExchangeFeeHandler ¶ added in v0.3.0
ExchangeFeeHandler is the basic interface for managing the exchange fee
type ExecutionHandler ¶ added in v0.3.0
type ExecutionHandler interface { OnData(DataEvent) (*Fill, error) OnOrder(OrderEvent, DataHandler) (*Fill, error) }
ExecutionHandler is the basic interface for executing orders
type Fill ¶ added in v0.3.0
type Fill struct { Event Exchange string // exchange symbol // contains filtered or unexported fields }
Fill declares a basic fill event
func (Fill) Commission ¶ added in v0.3.0
Commission returns the Commission field of a fill.
func (Fill) ExchangeFee ¶ added in v0.3.0
ExchangeFee returns the ExchangeFee Field of a fill
func (*Fill) SetDirection ¶ added in v0.3.0
SetDirection sets the Directions field of a Fill
type FillEvent ¶ added in v0.3.0
type FillEvent interface { EventHandler Directioner Quantifier Price() float64 Commission() float64 ExchangeFee() float64 Cost() float64 Value() float64 NetValue() float64 }
FillEvent declares fill event functionality.
type FixedCommission ¶ added in v0.3.0
type FixedCommission struct {
Commission float64
}
FixedCommission is a commission handler implementation which returns a fixed price commission
type FixedExchangeFee ¶ added in v0.3.0
type FixedExchangeFee struct {
ExchangeFee float64
}
FixedExchangeFee returns a fixed exchange fee
func (*FixedExchangeFee) Fee ¶ added in v0.3.0
func (e *FixedExchangeFee) Fee() (float64, error)
Fee returns the set exchange fee of the trade
type Investor ¶ added in v0.3.0
type Investor interface { IsInvested(string) (Position, bool) IsLong(string) (Position, bool) IsShort(string) (Position, bool) }
Investor is an interface to check if a portfolio has a position of a symbol
type Metric ¶ added in v0.3.0
Metric holds metric propertys to a data point.
type MetricHandler ¶ added in v0.3.0
MetricHandler defines the handling of metrics to a data event
type Node ¶ added in v0.3.0
type Node struct {
// contains filtered or unexported fields
}
Node implements NodeHandler. It represents the base information of each tree node. This is the main building block of the tree.
func (Node) Children ¶ added in v0.3.0
func (n Node) Children() ([]NodeHandler, bool)
Children returns the children of this Node.
func (*Node) SetChildren ¶ added in v0.3.0
func (n *Node) SetChildren(children ...NodeHandler) NodeHandler
SetChildren sets the Children of this Node.
func (*Node) SetName ¶ added in v0.3.0
func (n *Node) SetName(s string) NodeHandler
SetName sets the name of Node.
func (*Node) SetTolerance ¶ added in v0.3.0
SetTolerance of the Node
type NodeHandler ¶ added in v0.3.0
type NodeHandler interface { WeightHandler Name() string SetName(string) NodeHandler Root() bool SetRoot(bool) Children() ([]NodeHandler, bool) SetChildren(...NodeHandler) NodeHandler }
NodeHandler defines the basic node functionality.
type OnFiller ¶ added in v0.3.0
type OnFiller interface {
OnFill(FillEvent, DataHandler) (*Fill, error)
}
OnFiller is an interface for the OnFill method
type OnSignaler ¶ added in v0.3.0
type OnSignaler interface {
OnSignal(SignalEvent, DataHandler) (*Order, error)
}
OnSignaler is an interface for the OnSignal method
type Order ¶ added in v0.3.0
type Order struct { Event // contains filtered or unexported fields }
Order declares a basic order event.
func (*Order) SetDirection ¶ added in v0.3.0
SetDirection sets the Directions field of an Order
func (Order) Status ¶ added in v0.3.0
func (o Order) Status() OrderStatus
Status returns the status of an Order
type OrderBook ¶ added in v0.3.0
type OrderBook struct {
// contains filtered or unexported fields
}
OrderBook represents an order book.
func (*OrderBook) Add ¶ added in v0.3.0
func (ob *OrderBook) Add(order OrderEvent) error
Add an order to the order book.
func (OrderBook) OrderBy ¶ added in v0.3.0
func (ob OrderBook) OrderBy(fn func(order OrderEvent) bool) ([]OrderEvent, bool)
OrderBy returns the order by a select function from the order book.
func (OrderBook) Orders ¶ added in v0.3.0
func (ob OrderBook) Orders() ([]OrderEvent, bool)
Orders returns all Orders from the order book
func (OrderBook) OrdersAskBySymbol ¶ added in v0.3.0
func (ob OrderBook) OrdersAskBySymbol(symbol string) ([]OrderEvent, bool)
OrdersAskBySymbol returns all bid orders of a specific symbol from the order book.
func (OrderBook) OrdersBidBySymbol ¶ added in v0.3.0
func (ob OrderBook) OrdersBidBySymbol(symbol string) ([]OrderEvent, bool)
OrdersBidBySymbol returns all bid orders of a specific symbol from the order book.
func (OrderBook) OrdersBySymbol ¶ added in v0.3.0
func (ob OrderBook) OrdersBySymbol(symbol string) ([]OrderEvent, bool)
OrdersBySymbol returns the order of a specific symbol from the order book.
func (OrderBook) OrdersCanceled ¶ added in v0.3.0
func (ob OrderBook) OrdersCanceled() ([]OrderEvent, bool)
OrdersCanceled returns all orders which are canceled from the order book.
func (OrderBook) OrdersOpen ¶ added in v0.3.0
func (ob OrderBook) OrdersOpen() ([]OrderEvent, bool)
OrdersOpen returns all orders which are open from the order book.
type OrderEvent ¶ added in v0.3.0
type OrderEvent interface { EventHandler Directioner Quantifier IDer Status() OrderStatus Limit() float64 Stop() float64 }
OrderEvent declares the order event interface.
type OrderStatus ¶ added in v0.3.0
type OrderStatus int
OrderStatus defines an order status
const ( OrderNone OrderStatus = iota // 0 OrderNew OrderSubmitted OrderPartiallyFilled OrderFilled OrderCanceled OrderCancelPending OrderInvalid )
different types of order status
type PercentageCommission ¶ added in v0.3.0
type PercentageCommission struct {
Commission float64
}
PercentageCommission is a commission handler implementation which returns a percentage price commission calculated of the value of the trade
type Portfolio ¶ added in v0.3.0
type Portfolio struct {
// contains filtered or unexported fields
}
Portfolio represent a simple portfolio struct.
func NewPortfolio ¶ added in v0.3.0
func NewPortfolio() *Portfolio
NewPortfolio creates a default portfolio with sensible defaults ready for use.
func (Portfolio) InitialCash ¶ added in v0.3.0
InitialCash returns the initial cash value of the portfolio
func (Portfolio) IsInvested ¶ added in v0.3.0
IsInvested checks if the portfolio has an open position on the given symbol
func (Portfolio) IsLong ¶ added in v0.3.0
IsLong checks if the portfolio has an open long position on the given symbol
func (Portfolio) IsShort ¶ added in v0.3.0
IsShort checks if the portfolio has an open short position on the given symbol
func (*Portfolio) OnFill ¶ added in v0.3.0
func (p *Portfolio) OnFill(fill FillEvent, data DataHandler) (*Fill, error)
OnFill handles an incomming fill event
func (*Portfolio) OnSignal ¶ added in v0.3.0
func (p *Portfolio) OnSignal(signal SignalEvent, data DataHandler) (*Order, error)
OnSignal handles an incomming signal event
func (Portfolio) OrderBook ¶ added in v0.3.0
func (p Portfolio) OrderBook() ([]OrderEvent, bool)
OrderBook returns the order book of the portfolio
func (Portfolio) OrdersBySymbol ¶ added in v0.3.0
func (p Portfolio) OrdersBySymbol(symbol string) ([]OrderEvent, bool)
OrdersBySymbol returns the order of a specific symbol from the order book.
func (*Portfolio) Reset ¶ added in v0.3.0
Reset the portfolio into a clean state with set initial cash.
func (Portfolio) RiskManager ¶ added in v0.3.0
func (p Portfolio) RiskManager() RiskHandler
RiskManager returns the risk manager of the portfolio.
func (*Portfolio) SetInitialCash ¶ added in v0.3.0
SetInitialCash sets the initial cash value of the portfolio
func (*Portfolio) SetRiskManager ¶ added in v0.3.0
func (p *Portfolio) SetRiskManager(risk RiskHandler)
SetRiskManager sets the risk manager to be used with the portfolio.
func (*Portfolio) SetSizeManager ¶ added in v0.3.0
func (p *Portfolio) SetSizeManager(size SizeHandler)
SetSizeManager sets the size manager to be used with the portfolio.
func (Portfolio) SizeManager ¶ added in v0.3.0
func (p Portfolio) SizeManager() SizeHandler
SizeManager return the size manager of the portfolio.
type PortfolioHandler ¶ added in v0.3.0
PortfolioHandler is the combined interface building block for a portfolio.
type Position ¶ added in v0.3.0
type Position struct {
// contains filtered or unexported fields
}
Position represents the holdings position
func (*Position) UpdateValue ¶ added in v0.3.0
UpdateValue updates the current market value of a position
type Pricer ¶ added in v0.3.0
type Pricer interface {
Price() float64
}
Pricer defines the handling otf the latest Price Information
type Quantifier ¶ added in v0.3.0
Quantifier defines a qty interface.
type Reseter ¶ added in v0.3.0
type Reseter interface {
Reset() error
}
Reseter provides a resting interface.
type Resulter ¶ added in v0.3.0
type Resulter interface { TotalEquityReturn() (float64, error) MaxDrawdown() float64 MaxDrawdownTime() time.Time MaxDrawdownDuration() time.Duration SharpRatio(float64) float64 SortinoRatio(float64) float64 }
Resulter bundles all methods which return the results of the backtest
type Risk ¶ added in v0.3.0
type Risk struct { }
Risk is a basic risk handler implementation
func (*Risk) EvaluateOrder ¶ added in v0.3.0
func (r *Risk) EvaluateOrder(order OrderEvent, data DataEvent, positions map[string]Position) (*Order, error)
EvaluateOrder handles the risk of an order, refines or cancel it
type RiskHandler ¶ added in v0.3.0
type RiskHandler interface {
EvaluateOrder(OrderEvent, DataEvent, map[string]Position) (*Order, error)
}
RiskHandler is the basic interface for accessing risks of a portfolio
type Signal ¶ added in v0.3.0
type Signal struct { Event // contains filtered or unexported fields }
Signal declares a basic signal event
func (*Signal) SetDirection ¶ added in v0.3.0
SetDirection sets the Directions field of a Signal
type SignalEvent ¶ added in v0.3.0
type SignalEvent interface { EventHandler Directioner }
SignalEvent declares the signal event interface.
type Size ¶ added in v0.3.0
Size is a basic size handler implementation
func (*Size) SizeOrder ¶ added in v0.3.0
func (s *Size) SizeOrder(order OrderEvent, data DataEvent, pf PortfolioHandler) (*Order, error)
SizeOrder adjusts the size of an order
type SizeHandler ¶ added in v0.3.0
type SizeHandler interface {
SizeOrder(OrderEvent, DataEvent, PortfolioHandler) (*Order, error)
}
SizeHandler is the basic interface for setting the size of an order
type Spreader ¶ added in v0.3.0
type Spreader interface {
Spread() float64
}
Spreader declares functionality to get spre spread of a tick.
type Statistic ¶ added in v0.3.0
type Statistic struct {
// contains filtered or unexported fields
}
Statistic is a basic test statistic, which holds simple lists of historic events
func (Statistic) Events ¶ added in v0.3.0
func (s Statistic) Events() []EventHandler
Events returns the complete events history
func (Statistic) MaxDrawdown ¶ added in v0.3.0
MaxDrawdown returns the maximum draw down value in percent.
func (Statistic) MaxDrawdownDuration ¶ added in v0.3.0
MaxDrawdownDuration returns the maximum draw down value in percent
func (Statistic) MaxDrawdownTime ¶ added in v0.3.0
MaxDrawdownTime returns the time of the maximum draw down value.
func (Statistic) PrintResult ¶ added in v0.3.0
func (s Statistic) PrintResult()
PrintResult prints the backtest statistics to the screen
func (*Statistic) SharpRatio ¶ added in v0.3.0
SharpRatio returns the Sharp ratio compared to a risk free benchmark return.
func (*Statistic) SortinoRatio ¶ added in v0.3.0
SortinoRatio returns the Sortino ratio compared to a risk free benchmark return.
func (Statistic) TotalEquityReturn ¶ added in v0.3.0
TotalEquityReturn calculates the the total return on the first and last equity point
func (*Statistic) TrackEvent ¶ added in v0.3.0
func (s *Statistic) TrackEvent(e EventHandler)
TrackEvent tracks an event
func (*Statistic) TrackTransaction ¶ added in v0.3.0
TrackTransaction tracks a transaction aka a fill event
func (Statistic) Transactions ¶ added in v0.3.0
Transactions returns the complete events history
func (*Statistic) Update ¶ added in v0.3.0
func (s *Statistic) Update(d DataEvent, p PortfolioHandler)
Update the complete statistics to a given data event.
type StatisticHandler ¶ added in v0.3.0
type StatisticHandler interface { EventTracker TransactionTracker StatisticPrinter Reseter StatisticUpdater Resulter }
StatisticHandler is a basic statistic interface
type StatisticPrinter ¶ added in v0.3.0
type StatisticPrinter interface {
PrintResult()
}
StatisticPrinter handles printing of the statistics to screen
type StatisticUpdater ¶ added in v0.3.0
type StatisticUpdater interface {
Update(DataEvent, PortfolioHandler)
}
StatisticUpdater handles the updateing of the statistics
type Strategy ¶ added in v0.3.0
type Strategy struct { Node // contains filtered or unexported fields }
Strategy implements NodeHandler via Node, used as a strategy building block.
func NewStrategy ¶ added in v0.3.0
NewStrategy return a new strategy node ready to use.
func (*Strategy) AddSignal ¶ added in v0.3.0
func (s *Strategy) AddSignal(signals ...SignalEvent) error
AddSignal sets the data property.
func (*Strategy) Data ¶ added in v0.3.0
func (s *Strategy) Data() (DataHandler, bool)
Data returns the underlying data property.
func (*Strategy) OnData ¶ added in v0.3.0
func (s *Strategy) OnData(event DataEvent) (signals []SignalEvent, err error)
OnData handles an incoming data event. It runs the algo stack on this data.
func (*Strategy) Portfolio ¶ added in v0.3.0
func (s *Strategy) Portfolio() (PortfolioHandler, bool)
Portfolio returns the underlying portfolio property.
func (*Strategy) SetAlgo ¶ added in v0.3.0
func (s *Strategy) SetAlgo(algos ...AlgoHandler) *Strategy
SetAlgo sets the algo stack for the Strategy
func (*Strategy) SetData ¶ added in v0.3.0
func (s *Strategy) SetData(data DataHandler) error
SetData sets the data property.
func (*Strategy) SetPortfolio ¶ added in v0.3.0
func (s *Strategy) SetPortfolio(portfolio PortfolioHandler) error
SetPortfolio sets the portfolio property.
func (*Strategy) Signals ¶ added in v0.3.0
func (s *Strategy) Signals() ([]SignalEvent, bool)
Signals returns a slice of all from th ealgo loop created signals.
func (*Strategy) Strategies ¶ added in v0.3.0
func (s *Strategy) Strategies() ([]StrategyHandler, bool)
Strategies return all children which are a strategy.
type StrategyHandler ¶ added in v0.3.0
type StrategyHandler interface { Data() (DataHandler, bool) SetData(d DataHandler) error Portfolio() (PortfolioHandler, bool) SetPortfolio(p PortfolioHandler) error Event() (DataEvent, bool) SetEvent(DataEvent) error Signals() ([]SignalEvent, bool) AddSignal(...SignalEvent) error Strategies() ([]StrategyHandler, bool) Assets() ([]*Asset, bool) OnData(DataEvent) ([]SignalEvent, error) }
StrategyHandler is a basic strategy interface.
type Tick ¶ added in v0.3.0
Tick declares a data event for a price tick.
type TransactionTracker ¶ added in v0.3.0
TransactionTracker is responsible for all transaction tracking during a backtest
type TresholdFixedCommission ¶ added in v0.3.0
TresholdFixedCommission is a commission handler implementation which returns a fixed price commission if the value of the trade is above a set treshold
type Updater ¶ added in v0.3.0
type Updater interface {
Update(DataEvent)
}
Updater handles the updating of the portfolio on data events
type ValueCommission ¶ added in v0.3.0
ValueCommission is a commission handler implementation which returns a percentage price commission calculated of the value of the trade, if the value of the trade is within a given commission span