gobacktest

package module
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: 2 Imported by: 1

README

Software License Travis Go Doc Coverage Status Go Report Card

Heads up: This is a framework in development, with only limited basic functionality. A lot of the features are still missing.

You can read along and follow the development of this project. And if you like, give me some tips or discussion points for improvement.


gobacktest - Fundamental stock analysis backtesting

My attempt to create a event-driven backtesting framework to test stock trading strategies based on fundamental analysis. Preferably this package will be the core of a backend service exposed via a REST API.

Usage

Example tests are in the /examples folder.

package main

import (
	"github.com/dirkolbrich/gobacktest"
	"github.com/dirkolbrich/gobacktest/internal"
)

func main() {
	// we need a new blanc backtester
	test := gobacktest.New()

	// define the symbols to be tested and load them into the backtest
	var symbols = []string{"TEST.DE"}
	test.SetSymbols(symbols)

	// create a data provider and load the data into the backtest
	data := &internal.BarEventFromCSVFileData{FileDir: "../testdata/test/"}
	data.Load(symbols)
	test.SetData(data)

	// set portfolio with initial cash and default size and risk manager
	portfolio := &internal.Portfolio{}
	portfolio.SetInitialCash(10000)
	
	sizeManager := &internal.Size{DefaultSize: 100, DefaultValue: 1000}
	portfolio.SetSizeManager(sizeManager)

	riskManager := &internal.Risk{}
	portfolio.SetRiskManager(riskManager)

	test.SetPortfolio(portfolio)

	// create a strategy provider and load it into the backtest
	strategy := &internal.SimpleStrategy{}
	test.SetStrategy(strategy)

	// create an execution provider and load it into the backtest
	exchange := &internal.Exchange{}
	test.SetExchange(exchange)

	// choose a statisitc and load into the backtest
	statistic := &internal.Statistic{}
	test.SetStatistic(statistic)

	// run the backtest
	test.Run()
}

Dependencies

The internal calculations use the github.com/shopspring/decimal package for arbitrary-precision fixed-point decimals.

Make sure to install it into your $GOPATH with

go get github.com/shopspring/decimal

Basic components

These are the basic components of an event-driven framework.

  1. BackTester - general test case, bundles the follwing elements into a single test
  2. DataHandler - interface to a set of data, e.g historical quotes, fundamental data etc.
  3. StrategyHandler - generates a buy/sell signal based on the data
  4. PortfolioHandler - generates orders and manages profit & loss
    • (RiskHandler) - manages the risk allocation of a portfolio
  5. ExecutionHandler - sends orders to the broker and receives the “fills” or signals that the stock has been bought or sold
  6. EventHandler - the different types of events, which travel through this system - data event, signal event, order event and fill event

Infrastructure example

An overviev of the infrastructure of a complete backtesting and trading environment. Taken from the production roadmap of QuantRocket.

  • General
    • API gateway
    • configuration loader
    • logging service
    • cron service
  • Data
    • database backup and download service
    • securities master services
    • historical market data service
    • fundamental data service
    • earnings data service
    • dividend data service
    • real-time market data service
    • exchange calendar service
  • Strategy
    • performance analysis service - tearsheet
  • Portfolio
    • account and portfolio service
    • risk management service
  • Execution
    • trading platform gateway service
    • order management and trade ledger service
    • backtesting and trading engine

Resources

Articles

These links to articles are a good starting point to understand the intentions and basic functions of an event-driven backtesting framework.

Other backtesting frameworks
General information on Quantitative Finance

Documentation

Overview

Package gobacktest provides a simple stock backtesting framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Test

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

Test is a basic back test struct

func New

func New() *Test

New creates a default test backtest value for use.

func (*Test) Run

func (t *Test) Run() error

Run starts the test.

func (*Test) SetData

func (t *Test) SetData(data internal.DataHandler)

SetData sets the data provider to to be used within the test

func (*Test) SetExchange

func (t *Test) SetExchange(exchange internal.ExecutionHandler)

SetExchange sets the execution provider to to be used within the test

func (*Test) SetPortfolio

func (t *Test) SetPortfolio(portfolio internal.PortfolioHandler)

SetPortfolio sets the portfolio provider to to be used within the test

func (*Test) SetStatistic

func (t *Test) SetStatistic(statistic internal.StatisticHandler)

SetStatistic sets the statistic provider to to be used within the test

func (*Test) SetStrategy

func (t *Test) SetStrategy(strategy internal.StrategyHandler)

SetStrategy sets the strategy provider to to be used within the test

func (*Test) SetSymbols

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

SetSymbols sets the symbols to include into the test

Directories

Path Synopsis
examples
basic command
buy-and-hold command

Jump to

Keyboard shortcuts

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