internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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 BarEvent

type BarEvent interface {
	DataEvent
	Open() float64
	High() float64
	Low() float64
	Close() float64
	AdjClose() float64
	Volume() int64
}

BarEvent declares a bar event interface.

type BarEventFromCSVFileData

type BarEventFromCSVFileData struct {
	Data
	FileDir string
}

BarEventFromCSVFileData is a data struct, which loads the market data from csv files. It expands the underlying data struct

func (*BarEventFromCSVFileData) Load

func (d *BarEventFromCSVFileData) Load(symbols []string) (err error)

Load loads single data endpoints into a stream ordered by date (latest first).

type BuyAndHoldStrategy

type BuyAndHoldStrategy struct {
}

BuyAndHoldStrategy is a basic test strategy, which interprets the first DataEvent on a symbal as a signal to buy if the portfolio is not already invested.

func (*BuyAndHoldStrategy) CalculateSignal

func (s *BuyAndHoldStrategy) CalculateSignal(e DataEvent, data DataHandler, p PortfolioHandler) (se SignalEvent, err error)

CalculateSignal handles the single Event

type Casher

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

Casher handles basic portolio info

type Data

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

Data is a basic data struct

func (*Data) History

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

History returns the historic data stream

func (*Data) Latest

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

Latest returns the last known data event for a symbol.

func (*Data) List

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

List returns the data event list for a symbol.

func (*Data) Load

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

Load loads data endpoints into a stream

func (*Data) Next

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

Next returns the first element of the data stream deletes it from the stream and appends it to history

func (*Data) Stream

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

Stream returns the data stream

type DataEvent

type DataEvent interface {
	Event
	LatestPrice() float64
}

DataEvent declares a data event interface

type DataHandler

type DataHandler interface {
	DataLoader
	DataStreamer
}

DataHandler is the combined data interface

type DataLoader

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

DataLoader is the interface loading the data into the data stream

type DataStreamer

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

DataStreamer is the interface returning the data streams

type Directioner

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

Directioner defines the direction interface

type Event

type Event interface {
	Timestamp() time.Time
	Symbol() string
}

Event declares the basic event interface

type EventTracker

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

EventTracker is responsible for all event tracking during a backtest

type Exchange

type Exchange struct {
	Symbol      string
	ExchangeFee float64
}

Exchange is a basic execution handler implementation

func (*Exchange) ExecuteOrder

func (e *Exchange) ExecuteOrder(order OrderEvent, data DataHandler) (FillEvent, error)

ExecuteOrder executes an order event

type ExecutionHandler

type ExecutionHandler interface {
	ExecuteOrder(OrderEvent, DataHandler) (FillEvent, error)
}

ExecutionHandler is the basic interface for executing orders

type FillEvent

type FillEvent interface {
	Event
	Directioner
	Qtyer
	IsFill() bool
	Price() float64
	Commission() float64
	ExchangeFee() float64
	Cost() float64
	Value() float64
	NetValue() float64
}

FillEvent declares the fill event interface.

type Investor

type Investor interface {
	IsInvested(string) (position, bool)
	IsLong(string) (position, bool)
	IsShort(string) (position, bool)
}

Investor is an inteface to check if a portfolio has a position of a symbol

type Limiter

type Limiter interface {
	SetLimit(float64)
	Limit() float64
}

Limiter defines the limit interface

type OnFiller

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

OnFiller as an intercafe for the OnFill method

type OnSignaler

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

OnSignaler as an intercafe for the OnSignal method

type OrderEvent

type OrderEvent interface {
	Event
	Directioner
	Qtyer
	IsOrder() bool
}

OrderEvent declares the order event interface.

type Portfolio

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

Portfolio represent a simple portfolio struct.

func (Portfolio) Cash

func (p Portfolio) Cash() float64

Cash returns the current cash value of the portfolio

func (Portfolio) InitialCash

func (p Portfolio) InitialCash() float64

InitialCash returns the initial cash value of the portfolio

func (Portfolio) IsInvested

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

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

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

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

OnFill handles an incomming fill event

func (*Portfolio) OnSignal

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

OnSignal handles an incomming signal event

func (*Portfolio) SetCash

func (p *Portfolio) SetCash(cash float64)

SetCash sets the current cash value of the portfolio

func (*Portfolio) SetInitialCash

func (p *Portfolio) SetInitialCash(initial float64)

SetInitialCash sets the initial cash value of the portfolio

func (*Portfolio) SetRiskManager

func (p *Portfolio) SetRiskManager(risk RiskHandler)

SetRiskManager sets the risk manager to be used with the portfolio

func (*Portfolio) SetSizeManager

func (p *Portfolio) SetSizeManager(size SizeHandler)

SetSizeManager sets the size manager to be used with the portfolio

func (*Portfolio) Update

func (p *Portfolio) Update(d DataEvent)

Update updates the holding on a data event

func (Portfolio) Value

func (p Portfolio) Value() float64

Value return the current vlue of the portfolio

type PortfolioHandler

type PortfolioHandler interface {
	OnSignaler
	OnFiller
	Investor
	Updater
	Casher
	Valuer
}

PortfolioHandler is the combined interface building block for a portfolio.

type Qtyer

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

Qtyer defines the Quantity interface

type Risk

type Risk struct {
}

Risk is a basic risk handler implementation

func (*Risk) EvaluateOrder

func (r *Risk) EvaluateOrder(order OrderEvent, data DataEvent, positions map[string]position) (OrderEvent, error)

EvaluateOrder handles the risk of an order, refines or cancel it

type RiskHandler

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

RiskHandler is the basic interface for accessing risks of a portfolio

type SignalEvent

type SignalEvent interface {
	Event
	Directioner
	IsSignal() bool
}

SignalEvent declares the signal event interface.

type SimpleStrategy

type SimpleStrategy struct {
}

SimpleStrategy is a basic test strategy, which interprets every DataEvent as a signal to buy

func (*SimpleStrategy) CalculateSignal

func (s *SimpleStrategy) CalculateSignal(e DataEvent, data DataHandler, p PortfolioHandler) (se SignalEvent, err error)

CalculateSignal handles the single Event

type Size

type Size struct {
	DefaultSize  int64
	DefaultValue float64
}

Size is a basic size handler implementation

func (*Size) SizeOrder

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

SizeOrder adjusts the size of an order

type SizeHandler

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

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

type Statistic

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

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

func (Statistic) Events

func (s Statistic) Events() []Event

Events returns the complete events history

func (Statistic) PrintResult

func (s Statistic) PrintResult()

PrintResult prints the backtest statistics to the screen

func (*Statistic) TrackEvent

func (s *Statistic) TrackEvent(e Event)

TrackEvent tracks an event

func (*Statistic) TrackTransaction

func (s *Statistic) TrackTransaction(f FillEvent)

TrackTransaction tracks a transaction aka a fill event

func (Statistic) Transactions

func (s Statistic) Transactions() []FillEvent

Transactions returns the complete events history

func (*Statistic) Update

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

Update updates the complete statistics to a given data event

type StatisticHandler

type StatisticHandler interface {
	EventTracker
	TransactionTracker
	StatisticPrinter
	Update(DataEvent, PortfolioHandler)
}

StatisticHandler is a basic statistic interface

type StatisticPrinter

type StatisticPrinter interface {
	PrintResult()
}

StatisticPrinter handles printing of the statistics to screen

type StrategyHandler

type StrategyHandler interface {
	CalculateSignal(DataEvent, DataHandler, PortfolioHandler) (SignalEvent, error)
}

StrategyHandler is a basic strategy interface

type TickEvent

type TickEvent interface {
	DataEvent
	Bid() float64
	Ask() float64
}

TickEvent declares a tick event interface.

type TransactionTracker

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

TransactionTracker is responsible for all transaction tracking during a backtest

type Updater

type Updater interface {
	Update(DataEvent)
}

Updater handles the updating of the portfolio on data events

type Valuer

type Valuer interface {
	Value() float64
}

Valuer returns the values of the portfolio

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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