gobacktest: github.com/dirkolbrich/gobacktest Index | Files | Directories

package gobacktest

import "github.com/dirkolbrich/gobacktest"

Package gobacktest is a simple placeholder to root all gobacktest documentation

Index

Package Files

algo.go asset.go backtest.go commission.go data.go doc.go event.go exchangefee.go execution.go fill.go metric.go order.go orderbook.go portfolio.go position.go risk.go signal.go size.go statistic.go strategy.go tree.go

Constants

const DP = 4 // DP

DP sets the the precision of rounded floating numbers used after calculations to format

type Algo Uses

type Algo struct {
    // contains filtered or unexported fields
}

Algo is a base algo structure, implements AlgoHandler

func (Algo) Always Uses

func (a Algo) Always() bool

Always returns the runAlways property.

func (Algo) Run Uses

func (a Algo) Run(_ StrategyHandler) (bool, error)

Run implements the Algo interface.

func (*Algo) SetAlways Uses

func (a *Algo) SetAlways()

SetAlways set the runAlways property.

func (*Algo) Value Uses

func (a *Algo) Value() float64

Value returns the value of this Algo.

type AlgoHandler Uses

type AlgoHandler interface {
    Run(StrategyHandler) (bool, error)
    Always() bool
    SetAlways()
    Value() float64
}

AlgoHandler defines the base algorythm functionality.

func RunAlways Uses

func RunAlways(a AlgoHandler) AlgoHandler

RunAlways set the runAlways property on the AlgoHandler

type AlgoStack Uses

type AlgoStack struct {
    Algo
    // contains filtered or unexported fields
}

AlgoStack represents a single stack of algos.

func (AlgoStack) Run Uses

func (as AlgoStack) Run(s StrategyHandler) (bool, error)

Run implements the Algo interface on the AlgoStack, which makes it itself an Algo.

type Asset Uses

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 NewAsset Uses

func NewAsset(name string) *Asset

NewAsset return a new strategy node ready to use.

func (Asset) Children Uses

func (a Asset) Children() ([]NodeHandler, bool)

Children returns an empty slice and false, an Asset is not allowed to have children.

func (*Asset) SetChildren Uses

func (a *Asset) SetChildren(c ...NodeHandler) NodeHandler

SetChildren return itself without change, as an Asset ist not allowed to have children.

type Backtest Uses

type Backtest struct {
    // contains filtered or unexported fields
}

Backtest is the main struct which holds all elements.

func New Uses

func New() *Backtest

New creates a default backtest with sensible defaults ready for use.

func (*Backtest) Reset Uses

func (t *Backtest) Reset() error

Reset the backtest into a clean state with loaded data.

func (*Backtest) Run Uses

func (t *Backtest) Run() error

Run starts the backtest.

func (*Backtest) SetData Uses

func (t *Backtest) SetData(data DataHandler)

SetData sets the data provider to be used within the backtest.

func (*Backtest) SetExchange Uses

func (t *Backtest) SetExchange(exchange ExecutionHandler)

SetExchange sets the execution provider to be used within the backtest.

func (*Backtest) SetPortfolio Uses

func (t *Backtest) SetPortfolio(portfolio PortfolioHandler)

SetPortfolio sets the portfolio provider to be used within the backtest.

func (*Backtest) SetStatistic Uses

func (t *Backtest) SetStatistic(statistic StatisticHandler)

SetStatistic sets the statistic provider to be used within the backtest.

func (*Backtest) SetStrategy Uses

func (t *Backtest) SetStrategy(strategy StrategyHandler)

SetStrategy sets the strategy provider to be used within the backtest.

func (*Backtest) SetSymbols Uses

func (t *Backtest) SetSymbols(symbols []string)

SetSymbols sets the symbols to include into the backtest.

func (*Backtest) Stats Uses

func (t *Backtest) Stats() StatisticHandler

Stats returns the statistic handler of the backtest.

type Bar Uses

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.

func (Bar) Price Uses

func (b Bar) Price() float64

Price returns the close price of the bar event.

type BarEvent Uses

type BarEvent interface {
    DataEvent
}

BarEvent declares a bar event interface.

type Booker Uses

type Booker interface {
    OrderBook() ([]OrderEvent, bool)
    OrdersBySymbol(symbol string) ([]OrderEvent, bool)
}

Booker defines methods for handling the order book of the portfolio

type Casher Uses

type Casher interface {
    InitialCash() float64
    SetInitialCash(float64)
    Cash() float64
    SetCash(float64)
}

Casher handles basic portolio info

type CommissionHandler Uses

type CommissionHandler interface {
    Calculate(qty, price float64) (float64, error)
}

CommissionHandler is the basic interface for executing orders

type Data Uses

type Data struct {
    // contains filtered or unexported fields
}

Data is a basic data provider struct.

func (*Data) History Uses

func (d *Data) History() []DataEvent

History returns the historic data stream.

func (*Data) Latest Uses

func (d *Data) Latest(symbol string) DataEvent

Latest returns the last known data event for a symbol.

func (*Data) List Uses

func (d *Data) List(symbol string) []DataEvent

List returns the data event list for a symbol.

func (*Data) Load Uses

func (d *Data) Load(s []string) error

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 Uses

func (d *Data) Next() (dh DataEvent, ok bool)

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 Uses

func (d *Data) Reset() error

Reset implements Reseter to reset the data struct to a clean state with loaded data events.

func (*Data) SetStream Uses

func (d *Data) SetStream(stream []DataEvent)

SetStream sets the data stream.

func (*Data) SortStream Uses

func (d *Data) SortStream()

SortStream sorts the data stream in ascending order.

func (*Data) Stream Uses

func (d *Data) Stream() []DataEvent

Stream returns the data stream.

type DataEvent Uses

type DataEvent interface {
    EventHandler
    MetricHandler
    Pricer
}

DataEvent declares a data event interface

type DataHandler Uses

type DataHandler interface {
    DataLoader
    DataStreamer
    Reseter
}

DataHandler is the combined data interface.

type DataLoader Uses

type DataLoader interface {
    Load([]string) error
}

DataLoader defines how to load data into the data stream.

type DataStreamer Uses

type DataStreamer interface {
    Next() (DataEvent, bool)
    Stream() []DataEvent
    History() []DataEvent
    Latest(string) DataEvent
    List(string) []DataEvent
}

DataStreamer defines data stream functionality.

type Direction Uses

type Direction int

Direction defines which direction a signal indicates

const (
    // Buy
    BOT Direction = iota // 0
    // Sell
    SLD
    // Hold
    HLD
    // Exit
    EXT
)

different types of order directions

type Directioner Uses

type Directioner interface {
    Direction() Direction
    SetDirection(Direction)
}

Directioner defines a direction interface

type Event Uses

type Event struct {
    // contains filtered or unexported fields
}

Event is the implementation of the basic event interface.

func (*Event) SetSymbol Uses

func (e *Event) SetSymbol(s string)

SetSymbol returns the symbol string of the event

func (*Event) SetTime Uses

func (e *Event) SetTime(t time.Time)

SetTime returns the timestamp of an event

func (Event) Symbol Uses

func (e Event) Symbol() string

Symbol returns the symbol string of the event

func (Event) Time Uses

func (e Event) Time() time.Time

Time returns the timestamp of an event

type EventHandler Uses

type EventHandler interface {
    Timer
    Symboler
}

EventHandler declares the basic event interface

type EventTracker Uses

type EventTracker interface {
    TrackEvent(EventHandler)
    Events() []EventHandler
}

EventTracker is responsible for all event tracking during a backtest

type Exchange Uses

type Exchange struct {
    Symbol      string
    Commission  CommissionHandler
    ExchangeFee ExchangeFeeHandler
}

Exchange is a basic execution handler implementation

func NewExchange Uses

func NewExchange() *Exchange

NewExchange creates a default exchange with sensible defaults ready for use.

func (*Exchange) OnData Uses

func (e *Exchange) OnData(data DataEvent) (*Fill, error)

OnData executes any open order on new data

func (*Exchange) OnOrder Uses

func (e *Exchange) OnOrder(order OrderEvent, data DataHandler) (*Fill, error)

OnOrder executes an order event

type ExchangeFeeHandler Uses

type ExchangeFeeHandler interface {
    Fee() (float64, error)
}

ExchangeFeeHandler is the basic interface for managing the exchange fee

type ExecutionHandler Uses

type ExecutionHandler interface {
    OnData(DataEvent) (*Fill, error)
    OnOrder(OrderEvent, DataHandler) (*Fill, error)
}

ExecutionHandler is the basic interface for executing orders

type Fill Uses

type Fill struct {
    Event

    Exchange string // exchange symbol
    // contains filtered or unexported fields
}

Fill declares a basic fill event

func (Fill) Commission Uses

func (f Fill) Commission() float64

Commission returns the Commission field of a fill.

func (Fill) Cost Uses

func (f Fill) Cost() float64

Cost returns the Cost field of a Fill

func (Fill) Direction Uses

func (f Fill) Direction() Direction

Direction returns the direction of a Fill

func (Fill) ExchangeFee Uses

func (f Fill) ExchangeFee() float64

ExchangeFee returns the ExchangeFee Field of a fill

func (Fill) NetValue Uses

func (f Fill) NetValue() float64

NetValue returns the net value including cost.

func (Fill) Price Uses

func (f Fill) Price() float64

Price returns the Price field of a fill

func (Fill) Qty Uses

func (f Fill) Qty() int64

Qty returns the qty field of a fill

func (*Fill) SetDirection Uses

func (f *Fill) SetDirection(dir Direction)

SetDirection sets the Directions field of a Fill

func (*Fill) SetQty Uses

func (f *Fill) SetQty(i int64)

SetQty sets the Qty field of a Fill

func (Fill) Value Uses

func (f Fill) Value() float64

Value returns the value without cost.

type FillEvent Uses

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 Uses

type FixedCommission struct {
    Commission float64
}

FixedCommission is a commission handler implementation which returns a fixed price commission

func (*FixedCommission) Calculate Uses

func (c *FixedCommission) Calculate(qty, price float64) (float64, error)

Calculate calculates the commission of the trade

type FixedExchangeFee Uses

type FixedExchangeFee struct {
    ExchangeFee float64
}

FixedExchangeFee returns a fixed exchange fee

func (*FixedExchangeFee) Fee Uses

func (e *FixedExchangeFee) Fee() (float64, error)

Fee returns the set exchange fee of the trade

type IDer Uses

type IDer interface {
    ID() int
    SetID(int)
}

IDer declares setting and retrieving of an Id.

type Investor Uses

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 Uses

type Metric map[string]float64

Metric holds metric propertys to a data point.

func (Metric) Add Uses

func (m Metric) Add(key string, value float64) error

Add ads a value to the metrics map

func (Metric) Get Uses

func (m Metric) Get(key string) (float64, bool)

Get return a metric by name, if not found it returns false.

type MetricHandler Uses

type MetricHandler interface {
    Add(string, float64) error
    Get(string) (float64, bool)
}

MetricHandler defines the handling of metrics to a data event

type Node Uses

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 Uses

func (n Node) Children() ([]NodeHandler, bool)

Children returns the children of this Node.

func (Node) Name Uses

func (n Node) Name() string

Name returns the name of Node.

func (Node) Root Uses

func (n Node) Root() bool

Root checks if this Node is a root node.

func (*Node) SetChildren Uses

func (n *Node) SetChildren(children ...NodeHandler) NodeHandler

SetChildren sets the Children of this Node.

func (*Node) SetName Uses

func (n *Node) SetName(s string) NodeHandler

SetName sets the name of Node.

func (*Node) SetRoot Uses

func (n *Node) SetRoot(b bool)

SetRoot sets the root status of this Node.

func (*Node) SetTolerance Uses

func (n *Node) SetTolerance(t float64)

SetTolerance of the Node

func (*Node) SetWeight Uses

func (n *Node) SetWeight(w float64)

SetWeight of the node

func (Node) Tolerance Uses

func (n Node) Tolerance() float64

Tolerance spcifies the possible tollerance from the weight.

func (Node) Weight Uses

func (n Node) Weight() float64

Weight returns the weight of this node within this strategy level.

type NodeHandler Uses

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 Uses

type OnFiller interface {
    OnFill(FillEvent, DataHandler) (*Fill, error)
}

OnFiller is an interface for the OnFill method

type OnSignaler Uses

type OnSignaler interface {
    OnSignal(SignalEvent, DataHandler) (*Order, error)
}

OnSignaler is an interface for the OnSignal method

type Order Uses

type Order struct {
    Event
    // contains filtered or unexported fields
}

Order declares a basic order event.

func (*Order) Cancel Uses

func (o *Order) Cancel()

Cancel cancels an order

func (Order) Direction Uses

func (o Order) Direction() Direction

Direction returns the Direction of an Order

func (Order) ID Uses

func (o Order) ID() int

ID returns the id of the Order.

func (Order) Limit Uses

func (o Order) Limit() float64

Limit returns the limit price of an Order

func (Order) Qty Uses

func (o Order) Qty() int64

Qty returns the Qty field of an Order

func (*Order) SetDirection Uses

func (o *Order) SetDirection(dir Direction)

SetDirection sets the Directions field of an Order

func (*Order) SetID Uses

func (o *Order) SetID(id int)

SetID of the Order.

func (*Order) SetQty Uses

func (o *Order) SetQty(i int64)

SetQty sets the Qty field of an Order

func (Order) Status Uses

func (o Order) Status() OrderStatus

Status returns the status of an Order

func (Order) Stop Uses

func (o Order) Stop() float64

Stop returns the stop price of an Order

func (*Order) Update Uses

func (o *Order) Update(fill FillEvent)

Update updates an order on a fill event

type OrderBook Uses

type OrderBook struct {
    // contains filtered or unexported fields
}

OrderBook represents an order book.

func (*OrderBook) Add Uses

func (ob *OrderBook) Add(order OrderEvent) error

Add an order to the order book.

func (OrderBook) OrderBy Uses

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 Uses

func (ob OrderBook) Orders() ([]OrderEvent, bool)

Orders returns all Orders from the order book

func (OrderBook) OrdersAskBySymbol Uses

func (ob OrderBook) OrdersAskBySymbol(symbol string) ([]OrderEvent, bool)

OrdersAskBySymbol returns all bid orders of a specific symbol from the order book.

func (OrderBook) OrdersBidBySymbol Uses

func (ob OrderBook) OrdersBidBySymbol(symbol string) ([]OrderEvent, bool)

OrdersBidBySymbol returns all bid orders of a specific symbol from the order book.

func (OrderBook) OrdersBySymbol Uses

func (ob OrderBook) OrdersBySymbol(symbol string) ([]OrderEvent, bool)

OrdersBySymbol returns the order of a specific symbol from the order book.

func (OrderBook) OrdersCanceled Uses

func (ob OrderBook) OrdersCanceled() ([]OrderEvent, bool)

OrdersCanceled returns all orders which are canceled from the order book.

func (OrderBook) OrdersOpen Uses

func (ob OrderBook) OrdersOpen() ([]OrderEvent, bool)

OrdersOpen returns all orders which are open from the order book.

func (*OrderBook) Remove Uses

func (ob *OrderBook) Remove(id int) error

Remove an order from the order book, append it to history.

type OrderEvent Uses

type OrderEvent interface {
    EventHandler
    Directioner
    Quantifier
    IDer
    Status() OrderStatus
    Limit() float64
    Stop() float64
}

OrderEvent declares the order event interface.

type OrderStatus Uses

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 OrderType Uses

type OrderType int

OrderType defines which type an order is

const (
    MarketOrder OrderType = iota // 0
    MarketOnOpenOrder
    MarketOnCloseOrder
    StopMarketOrder
    LimitOrder
    StopLimitOrder
)

different types of orders

type PercentageCommission Uses

type PercentageCommission struct {
    Commission float64
}

PercentageCommission is a commission handler implementation which returns a percentage price commission calculated of the value of the trade

func (*PercentageCommission) Calculate Uses

func (c *PercentageCommission) Calculate(qty, price float64) (float64, error)

Calculate calculates the commission of the trade

type Portfolio Uses

type Portfolio struct {
    // contains filtered or unexported fields
}

Portfolio represent a simple portfolio struct.

func NewPortfolio Uses

func NewPortfolio() *Portfolio

NewPortfolio creates a default portfolio with sensible defaults ready for use.

func (Portfolio) Cash Uses

func (p Portfolio) Cash() float64

Cash returns the current cash value of the portfolio

func (Portfolio) Holdings Uses

func (p Portfolio) Holdings() map[string]Position

Holdings returns the holdings of the portfolio

func (Portfolio) InitialCash Uses

func (p Portfolio) InitialCash() float64

InitialCash returns the initial cash value of the portfolio

func (Portfolio) IsInvested Uses

func (p Portfolio) IsInvested(symbol string) (pos Position, ok bool)

IsInvested checks if the portfolio has an open position on the given symbol

func (Portfolio) IsLong Uses

func (p Portfolio) IsLong(symbol string) (pos Position, ok bool)

IsLong checks if the portfolio has an open long position on the given symbol

func (Portfolio) IsShort Uses

func (p Portfolio) IsShort(symbol string) (pos Position, ok bool)

IsShort checks if the portfolio has an open short position on the given symbol

func (*Portfolio) OnFill Uses

func (p *Portfolio) OnFill(fill FillEvent, data DataHandler) (*Fill, error)

OnFill handles an incomming fill event

func (*Portfolio) OnSignal Uses

func (p *Portfolio) OnSignal(signal SignalEvent, data DataHandler) (*Order, error)

OnSignal handles an incomming signal event

func (Portfolio) OrderBook Uses

func (p Portfolio) OrderBook() ([]OrderEvent, bool)

OrderBook returns the order book of the portfolio

func (Portfolio) OrdersBySymbol Uses

func (p Portfolio) OrdersBySymbol(symbol string) ([]OrderEvent, bool)

OrdersBySymbol returns the order of a specific symbol from the order book.

func (*Portfolio) Reset Uses

func (p *Portfolio) Reset() error

Reset the portfolio into a clean state with set initial cash.

func (Portfolio) RiskManager Uses

func (p Portfolio) RiskManager() RiskHandler

RiskManager returns the risk manager of the portfolio.

func (*Portfolio) SetCash Uses

func (p *Portfolio) SetCash(cash float64)

SetCash sets the current cash value of the portfolio

func (*Portfolio) SetInitialCash Uses

func (p *Portfolio) SetInitialCash(initial float64)

SetInitialCash sets the initial cash value of the portfolio

func (*Portfolio) SetRiskManager Uses

func (p *Portfolio) SetRiskManager(risk RiskHandler)

SetRiskManager sets the risk manager to be used with the portfolio.

func (*Portfolio) SetSizeManager Uses

func (p *Portfolio) SetSizeManager(size SizeHandler)

SetSizeManager sets the size manager to be used with the portfolio.

func (Portfolio) SizeManager Uses

func (p Portfolio) SizeManager() SizeHandler

SizeManager return the size manager of the portfolio.

func (*Portfolio) Update Uses

func (p *Portfolio) Update(d DataEvent)

Update updates the holding on a data event

func (Portfolio) Value Uses

func (p Portfolio) Value() float64

Value return the current total value of the portfolio

type PortfolioHandler Uses

type PortfolioHandler interface {
    OnSignaler
    OnFiller
    Investor
    Updater
    Casher
    Valuer
    Reseter
}

PortfolioHandler is the combined interface building block for a portfolio.

type Position Uses

type Position struct {
    // contains filtered or unexported fields
}

Position represents the holdings position

func (*Position) Create Uses

func (p *Position) Create(fill FillEvent)

Create a new position based on a fill event

func (*Position) Update Uses

func (p *Position) Update(fill FillEvent)

Update a position on a new fill event

func (*Position) UpdateValue Uses

func (p *Position) UpdateValue(data DataEvent)

UpdateValue updates the current market value of a position

type Pricer Uses

type Pricer interface {
    Price() float64
}

Pricer defines the handling otf the latest Price Information

type Quantifier Uses

type Quantifier interface {
    Qty() int64
    SetQty(int64)
}

Quantifier defines a qty interface.

type Reseter Uses

type Reseter interface {
    Reset() error
}

Reseter provides a resting interface.

type Resulter Uses

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 Uses

type Risk struct {
}

Risk is a basic risk handler implementation

func (*Risk) EvaluateOrder Uses

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 Uses

type RiskHandler interface {
    EvaluateOrder(OrderEvent, DataEvent, map[string]Position) (*Order, error)
}

RiskHandler is the basic interface for accessing risks of a portfolio

type Signal Uses

type Signal struct {
    Event
    // contains filtered or unexported fields
}

Signal declares a basic signal event

func (Signal) Direction Uses

func (s Signal) Direction() Direction

Direction returns the Direction of a Signal

func (*Signal) SetDirection Uses

func (s *Signal) SetDirection(dir Direction)

SetDirection sets the Directions field of a Signal

type SignalEvent Uses

type SignalEvent interface {
    EventHandler
    Directioner
}

SignalEvent declares the signal event interface.

type Size Uses

type Size struct {
    DefaultSize  int64
    DefaultValue float64
}

Size is a basic size handler implementation

func (*Size) SizeOrder Uses

func (s *Size) SizeOrder(order OrderEvent, data DataEvent, pf PortfolioHandler) (*Order, error)

SizeOrder adjusts the size of an order

type SizeHandler Uses

type SizeHandler interface {
    SizeOrder(OrderEvent, DataEvent, PortfolioHandler) (*Order, error)
}

SizeHandler is the basic interface for setting the size of an order

type Spreader Uses

type Spreader interface {
    Spread() float64
}

Spreader declares functionality to get spre spread of a tick.

type Statistic Uses

type Statistic struct {
    // contains filtered or unexported fields
}

Statistic is a basic test statistic, which holds simple lists of historic events

func (Statistic) Events Uses

func (s Statistic) Events() []EventHandler

Events returns the complete events history

func (Statistic) MaxDrawdown Uses

func (s Statistic) MaxDrawdown() float64

MaxDrawdown returns the maximum draw down value in percent.

func (Statistic) MaxDrawdownDuration Uses

func (s Statistic) MaxDrawdownDuration() (d time.Duration)

MaxDrawdownDuration returns the maximum draw down value in percent

func (Statistic) MaxDrawdownTime Uses

func (s Statistic) MaxDrawdownTime() time.Time

MaxDrawdownTime returns the time of the maximum draw down value.

func (Statistic) PrintResult Uses

func (s Statistic) PrintResult()

PrintResult prints the backtest statistics to the screen

func (*Statistic) Reset Uses

func (s *Statistic) Reset() error

Reset the statistic to a clean state

func (*Statistic) SharpRatio Uses

func (s *Statistic) SharpRatio(riskfree float64) float64

SharpRatio returns the Sharp ratio compared to a risk free benchmark return.

func (*Statistic) SortinoRatio Uses

func (s *Statistic) SortinoRatio(riskfree float64) float64

SortinoRatio returns the Sortino ratio compared to a risk free benchmark return.

func (Statistic) TotalEquityReturn Uses

func (s Statistic) TotalEquityReturn() (r float64, err error)

TotalEquityReturn calculates the the total return on the first and last equity point

func (*Statistic) TrackEvent Uses

func (s *Statistic) TrackEvent(e EventHandler)

TrackEvent tracks an event

func (*Statistic) TrackTransaction Uses

func (s *Statistic) TrackTransaction(f FillEvent)

TrackTransaction tracks a transaction aka a fill event

func (Statistic) Transactions Uses

func (s Statistic) Transactions() []FillEvent

Transactions returns the complete events history

func (*Statistic) Update Uses

func (s *Statistic) Update(d DataEvent, p PortfolioHandler)

Update the complete statistics to a given data event.

type StatisticHandler Uses

type StatisticHandler interface {
    EventTracker
    TransactionTracker
    StatisticPrinter
    Reseter
    StatisticUpdater
    Resulter
}

StatisticHandler is a basic statistic interface

type StatisticPrinter Uses

type StatisticPrinter interface {
    PrintResult()
}

StatisticPrinter handles printing of the statistics to screen

type StatisticUpdater Uses

type StatisticUpdater interface {
    Update(DataEvent, PortfolioHandler)
}

StatisticUpdater handles the updateing of the statistics

type Strategy Uses

type Strategy struct {
    Node
    // contains filtered or unexported fields
}

Strategy implements NodeHandler via Node, used as a strategy building block.

func NewStrategy Uses

func NewStrategy(name string) *Strategy

NewStrategy return a new strategy node ready to use.

func (*Strategy) AddSignal Uses

func (s *Strategy) AddSignal(signals ...SignalEvent) error

AddSignal sets the data property.

func (*Strategy) Assets Uses

func (s *Strategy) Assets() ([]*Asset, bool)

Assets return all children which are a strategy.

func (*Strategy) Data Uses

func (s *Strategy) Data() (DataHandler, bool)

Data returns the underlying data property.

func (*Strategy) Event Uses

func (s *Strategy) Event() (DataEvent, bool)

Event returns the underlying data property.

func (*Strategy) OnData Uses

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 Uses

func (s *Strategy) Portfolio() (PortfolioHandler, bool)

Portfolio returns the underlying portfolio property.

func (*Strategy) SetAlgo Uses

func (s *Strategy) SetAlgo(algos ...AlgoHandler) *Strategy

SetAlgo sets the algo stack for the Strategy

func (*Strategy) SetData Uses

func (s *Strategy) SetData(data DataHandler) error

SetData sets the data property.

func (*Strategy) SetEvent Uses

func (s *Strategy) SetEvent(event DataEvent) error

SetEvent sets the event property.

func (*Strategy) SetPortfolio Uses

func (s *Strategy) SetPortfolio(portfolio PortfolioHandler) error

SetPortfolio sets the portfolio property.

func (*Strategy) Signals Uses

func (s *Strategy) Signals() ([]SignalEvent, bool)

Signals returns a slice of all from th ealgo loop created signals.

func (*Strategy) Strategies Uses

func (s *Strategy) Strategies() ([]StrategyHandler, bool)

Strategies return all children which are a strategy.

type StrategyHandler Uses

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 Symboler Uses

type Symboler interface {
    Symbol() string
    SetSymbol(string)
}

Symboler declares the symboler interface

type Tick Uses

type Tick struct {
    Event
    Metric
    Bid       float64
    Ask       float64
    BidVolume int64
    AskVolume int64
}

Tick declares a data event for a price tick.

func (Tick) Price Uses

func (t Tick) Price() float64

Price returns the middle of Bid and Ask.

func (Tick) Spread Uses

func (t Tick) Spread() float64

Spread returns the difference or spread of Bid and Ask.

type TickEvent Uses

type TickEvent interface {
    DataEvent
    Spreader
}

TickEvent declares a bar event interface.

type Timer Uses

type Timer interface {
    Time() time.Time
    SetTime(time.Time)
}

Timer declares the timer interface

type TransactionTracker Uses

type TransactionTracker interface {
    TrackTransaction(FillEvent)
    Transactions() []FillEvent
}

TransactionTracker is responsible for all transaction tracking during a backtest

type TresholdFixedCommission Uses

type TresholdFixedCommission struct {
    Commission float64
    MinValue   float64
}

TresholdFixedCommission is a commission handler implementation which returns a fixed price commission if the value of the trade is above a set treshold

func (*TresholdFixedCommission) Calculate Uses

func (c *TresholdFixedCommission) Calculate(qty, price float64) (float64, error)

Calculate calculates the commission of the trade

type Updater Uses

type Updater interface {
    Update(DataEvent)
}

Updater handles the updating of the portfolio on data events

type ValueCommission Uses

type ValueCommission struct {
    Commission    float64
    MinCommission float64
    MaxCommission float64
}

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

func (*ValueCommission) Calculate Uses

func (c *ValueCommission) Calculate(qty, price float64) (float64, error)

Calculate calculates the commission of the trade

type Valuer Uses

type Valuer interface {
    Value() float64
}

Valuer returns the values of the portfolio

type WeightHandler Uses

type WeightHandler interface {
    Weight() float64
    SetWeight(float64)
    Tolerance() float64
    SetTolerance(float64)
}

WeightHandler defines weight functionality.

Directories

PathSynopsis
data
strategy
ta

Package gobacktest imports 6 packages (graph) and is imported by 2 packages. Updated 2018-08-03. Refresh now. Tools for package owners.