Documentation
¶
Index ¶
- Constants
- type BarEvent
- type BarEventFromCSVFileData
- type BuyAndHoldStrategy
- type Casher
- type Data
- type DataEvent
- type DataHandler
- type DataLoader
- type DataStreamer
- type Directioner
- type Event
- type EventTracker
- type Exchange
- type ExecutionHandler
- type FillEvent
- type Investor
- type Limiter
- type OnFiller
- type OnSignaler
- type OrderEvent
- type Portfolio
- func (p Portfolio) Cash() float64
- 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) (FillEvent, error)
- func (p *Portfolio) OnSignal(signal SignalEvent, data DataHandler) (OrderEvent, error)
- 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) Update(d DataEvent)
- func (p Portfolio) Value() float64
- type PortfolioHandler
- type Qtyer
- type Risk
- type RiskHandler
- type SignalEvent
- type SimpleStrategy
- type Size
- type SizeHandler
- type Statistic
- type StatisticHandler
- type StatisticPrinter
- type StrategyHandler
- type TickEvent
- type TransactionTracker
- type Updater
- type Valuer
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 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 ¶
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
type DataHandler ¶
type DataHandler interface {
DataLoader
DataStreamer
}
DataHandler is the combined data interface
type DataLoader ¶
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 ¶
Directioner defines the direction interface
type EventTracker ¶
EventTracker is responsible for all event tracking during a backtest
type Exchange ¶
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 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) InitialCash ¶
InitialCash returns the initial cash value of the portfolio
func (Portfolio) IsInvested ¶
IsInvested checks if the portfolio has an open position on the given symbol
func (Portfolio) IsLong ¶
IsLong checks if the portfolio has an open long position on the given symbol
func (Portfolio) IsShort ¶
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) SetInitialCash ¶
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
type PortfolioHandler ¶
PortfolioHandler is the combined interface building block for a portfolio.
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 ¶
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) PrintResult ¶
func (s Statistic) PrintResult()
PrintResult prints the backtest statistics to the screen
func (*Statistic) TrackTransaction ¶
TrackTransaction tracks a transaction aka a fill event
func (Statistic) Transactions ¶
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 TransactionTracker ¶
TransactionTracker is responsible for all transaction tracking during a backtest