statistics

package
v0.0.0-...-ae86ed1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 16 Imported by: 0

README

GoCryptoTrader Backtester: Statistics package

Build Status Software License GoDoc Coverage Status Go Report Card

This statistics package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Statistics package overview

The statistics package is used for storing all relevant data over the course of a GoCryptoTrader Backtesting run. All types of events are tracked by exchange, asset and currency pair. When multiple currencies are included in your strategy, the statistics package will be able to calculate which exchange asset currency pair has performed the best, along with the biggest drop downs in the market.

Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FinalResultsHolder

type FinalResultsHolder struct {
	Exchange         string                   `json:"exchange"`
	Asset            asset.Item               `json:"asset"`
	Pair             currency.Pair            `json:"currency"`
	MaxDrawdown      currencystatistics.Swing `json:"max-drawdown"`
	MarketMovement   float64                  `json:"market-movement"`
	StrategyMovement float64                  `json:"strategy-movement"`
}

FinalResultsHolder holds important stats about a currency's performance

type Handler

type Handler interface {
	SetStrategyName(string)
	SetupEventForTime(common.DataEventHandler) error
	SetEventForOffset(e common.EventHandler) error
	AddHoldingsForTime(*holdings.Holding) error
	AddComplianceSnapshotForTime(compliance.Snapshot, fill.Event) error
	CalculateAllResults() error
	Reset()
	Serialise() (string, error)
}

Handler interface details what a statistic is expected to do

type ResultEvent

type ResultEvent struct {
	Time time.Time `json:"time"`
}

ResultEvent stores the time

type ResultTransactions

type ResultTransactions struct {
	Time      time.Time     `json:"time"`
	Direction gctorder.Side `json:"direction"`
	Price     float64       `json:"price"`
	Amount    float64       `json:"amount"`
	Reason    string        `json:"reason,omitempty"`
}

ResultTransactions stores details on a transaction

type Results

type Results struct {
	Pair              string               `json:"pair"`
	TotalEvents       int                  `json:"totalEvents"`
	TotalTransactions int                  `json:"totalTransactions"`
	Events            []ResultEvent        `json:"events"`
	Transactions      []ResultTransactions `json:"transactions"`
	StrategyName      string               `json:"strategyName"`
}

Results holds some statistics on results

type Statistic

type Statistic struct {
	StrategyName                string                                                                            `json:"strategy-name"`
	StrategyDescription         string                                                                            `json:"strategy-description"`
	StrategyNickname            string                                                                            `json:"strategy-nickname"`
	StrategyGoal                string                                                                            `json:"strategy-goal"`
	ExchangeAssetPairStatistics map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic `json:"-"`
	RiskFreeRate                float64                                                                           `json:"risk-free-rate"`
	TotalBuyOrders              int64                                                                             `json:"total-buy-orders"`
	TotalSellOrders             int64                                                                             `json:"total-sell-orders"`
	TotalOrders                 int64                                                                             `json:"total-orders"`
	BiggestDrawdown             *FinalResultsHolder                                                               `json:"biggest-drawdown,omitempty"`
	BestStrategyResults         *FinalResultsHolder                                                               `json:"best-start-results,omitempty"`
	BestMarketMovement          *FinalResultsHolder                                                               `json:"best-market-movement,omitempty"`
	AllStats                    []currencystatistics.CurrencyStatistic                                            `json:"results"` // as ExchangeAssetPairStatistics cannot be rendered via json.Marshall, we append all result to this slice instead
	WasAnyDataMissing           bool                                                                              `json:"was-any-data-missing"`
}

Statistic holds all statistical information for a backtester run, from drawdowns to ratios. Any currency specific information is handled in currencystatistics

func (*Statistic) AddComplianceSnapshotForTime

func (s *Statistic) AddComplianceSnapshotForTime(c compliance.Snapshot, e fill.Event) error

AddComplianceSnapshotForTime adds the compliance snapshot to the statistics at the time period

func (*Statistic) AddHoldingsForTime

func (s *Statistic) AddHoldingsForTime(h *holdings.Holding) error

AddHoldingsForTime adds all holdings to the statistics at the time period

func (*Statistic) CalculateAllResults

func (s *Statistic) CalculateAllResults() error

CalculateAllResults calculates the statistics of all exchange asset pair holdings, orders, ratios and drawdowns

func (*Statistic) GetBestMarketPerformer

func (s *Statistic) GetBestMarketPerformer(results []FinalResultsHolder) *FinalResultsHolder

GetBestMarketPerformer returns the best final market movement

func (*Statistic) GetBestStrategyPerformer

func (s *Statistic) GetBestStrategyPerformer(results []FinalResultsHolder) *FinalResultsHolder

GetBestStrategyPerformer returns the best performing strategy result

func (*Statistic) GetTheBiggestDrawdownAcrossCurrencies

func (s *Statistic) GetTheBiggestDrawdownAcrossCurrencies(results []FinalResultsHolder) *FinalResultsHolder

GetTheBiggestDrawdownAcrossCurrencies returns the biggest drawdown across all currencies in a backtesting run

func (*Statistic) PrintAllEvents

func (s *Statistic) PrintAllEvents()

PrintAllEvents outputs all event details in the CMD

func (*Statistic) PrintTotalResults

func (s *Statistic) PrintTotalResults()

PrintTotalResults outputs all results to the CMD

func (*Statistic) Reset

func (s *Statistic) Reset()

Reset returns the struct to defaults

func (*Statistic) Serialise

func (s *Statistic) Serialise() (string, error)

Serialise outputs the Statistic struct in json

func (*Statistic) SetEventForOffset

func (s *Statistic) SetEventForOffset(e common.EventHandler) error

SetEventForOffset sets the event for the time period in the event

func (*Statistic) SetStrategyName

func (s *Statistic) SetStrategyName(name string)

SetStrategyName sets the name for statistical identification

func (*Statistic) SetupEventForTime

func (s *Statistic) SetupEventForTime(e common.DataEventHandler) error

SetupEventForTime sets up the big map for to store important data at each time interval

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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