Documentation
¶
Index ¶
- Variables
- type CurrencyPairStatistic
- type CurrencyStats
- type EventStore
- type FinalResultsHolder
- type FundingItemStatistics
- type FundingStatistics
- type Handler
- type Ratios
- type ResultEvent
- type ResultTransactions
- type Results
- type Statistic
- func (s *Statistic) AddComplianceSnapshotForTime(c compliance.Snapshot, e fill.Event) error
- func (s *Statistic) AddHoldingsForTime(h *holdings.Holding) error
- func (s *Statistic) CalculateAllResults() error
- func (s *Statistic) GetBestMarketPerformer(results []FinalResultsHolder) *FinalResultsHolder
- func (s *Statistic) GetBestStrategyPerformer(results []FinalResultsHolder) *FinalResultsHolder
- func (s *Statistic) GetTheBiggestDrawdownAcrossCurrencies(results []FinalResultsHolder) *FinalResultsHolder
- func (s *Statistic) PrintAllEventsChronologically()
- func (s *Statistic) PrintTotalResults()
- func (s *Statistic) Reset()
- func (s *Statistic) Serialise() (string, error)
- func (s *Statistic) SetEventForOffset(ev common.EventHandler) error
- func (s *Statistic) SetStrategyName(name string)
- func (s *Statistic) SetupEventForTime(ev common.DataEventHandler) error
- type Swing
- type TotalFundingStatistics
- type ValueAtTime
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyProcessed occurs when an event has already been processed ErrAlreadyProcessed = errors.New("this event has been processed already") )
Functions ¶
This section is empty.
Types ¶
type CurrencyPairStatistic ¶
type CurrencyPairStatistic struct {
ShowMissingDataWarning bool `json:"-"`
IsStrategyProfitable bool `json:"is-strategy-profitable"`
DoesPerformanceBeatTheMarket bool `json:"does-performance-beat-the-market"`
BuyOrders int64 `json:"buy-orders"`
SellOrders int64 `json:"sell-orders"`
TotalOrders int64 `json:"total-orders"`
StartingClosePrice decimal.Decimal `json:"starting-close-price"`
EndingClosePrice decimal.Decimal `json:"ending-close-price"`
LowestClosePrice decimal.Decimal `json:"lowest-close-price"`
HighestClosePrice decimal.Decimal `json:"highest-close-price"`
MarketMovement decimal.Decimal `json:"market-movement"`
StrategyMovement decimal.Decimal `json:"strategy-movement"`
CompoundAnnualGrowthRate decimal.Decimal `json:"compound-annual-growth-rate"`
TotalAssetValue decimal.Decimal
TotalFees decimal.Decimal
TotalValueLostToVolumeSizing decimal.Decimal
TotalValueLostToSlippage decimal.Decimal
TotalValueLost decimal.Decimal
Events []EventStore `json:"-"`
MaxDrawdown Swing `json:"max-drawdown,omitempty"`
HighestCommittedFunds ValueAtTime `json:"highest-committed-funds"`
GeometricRatios *Ratios `json:"geometric-ratios"`
ArithmeticRatios *Ratios `json:"arithmetic-ratios"`
InitialHoldings holdings.Holding `json:"initial-holdings-holdings"`
FinalHoldings holdings.Holding `json:"final-holdings"`
FinalOrders compliance.Snapshot `json:"final-orders"`
}
CurrencyPairStatistic Holds all events and statistics relevant to an exchange, asset type and currency pair
func (*CurrencyPairStatistic) CalculateResults ¶
func (c *CurrencyPairStatistic) CalculateResults(riskFreeRate decimal.Decimal) error
CalculateResults calculates all statistics for the exchange, asset, currency pair
func (*CurrencyPairStatistic) PrintResults ¶
func (c *CurrencyPairStatistic) PrintResults(e string, a asset.Item, p currency.Pair, usingExchangeLevelFunding bool)
PrintResults outputs all calculated statistics to the command line
type CurrencyStats ¶
type CurrencyStats interface {
TotalEquityReturn() (decimal.Decimal, error)
MaxDrawdown() Swing
LongestDrawdown() Swing
SharpeRatio(decimal.Decimal) decimal.Decimal
SortinoRatio(decimal.Decimal) decimal.Decimal
}
CurrencyStats defines what is expected in order to calculate statistics based on an exchange, asset type and currency pair
type EventStore ¶
type EventStore struct {
Holdings holdings.Holding
Transactions compliance.Snapshot
DataEvent common.DataEventHandler
SignalEvent signal.Event
OrderEvent order.Event
FillEvent fill.Event
}
EventStore is used to hold all event information at a time interval
type FinalResultsHolder ¶
type FinalResultsHolder struct {
Exchange string `json:"exchange"`
Asset asset.Item `json:"asset"`
Pair currency.Pair `json:"currency"`
MaxDrawdown Swing `json:"max-drawdown"`
MarketMovement decimal.Decimal `json:"market-movement"`
StrategyMovement decimal.Decimal `json:"strategy-movement"`
}
FinalResultsHolder holds important stats about a currency's performance
type FundingItemStatistics ¶
type FundingItemStatistics struct {
ReportItem *funding.ReportItem
// USD stats
StartingClosePrice ValueAtTime
EndingClosePrice ValueAtTime
LowestClosePrice ValueAtTime
HighestClosePrice ValueAtTime
MarketMovement decimal.Decimal
StrategyMovement decimal.Decimal
DidStrategyBeatTheMarket bool
RiskFreeRate decimal.Decimal
CompoundAnnualGrowthRate decimal.Decimal
BuyOrders int64
SellOrders int64
TotalOrders int64
MaxDrawdown Swing
HighestCommittedFunds ValueAtTime
}
FundingItemStatistics holds statistics for funding items
func CalculateIndividualFundingStatistics ¶
func CalculateIndividualFundingStatistics(disableUSDTracking bool, reportItem *funding.ReportItem, relatedStats []relatedCurrencyPairStatistics) (*FundingItemStatistics, error)
CalculateIndividualFundingStatistics calculates statistics for an individual report item
type FundingStatistics ¶
type FundingStatistics struct {
Report *funding.Report
Items []FundingItemStatistics
TotalUSDStatistics *TotalFundingStatistics
}
FundingStatistics stores all funding related statistics
func CalculateFundingStatistics ¶
func CalculateFundingStatistics(funds funding.IFundingManager, currStats map[string]map[asset.Item]map[currency.Pair]*CurrencyPairStatistic, riskFreeRate decimal.Decimal, interval gctkline.Interval) (*FundingStatistics, error)
CalculateFundingStatistics calculates funding statistics for total USD strategy results along with individual funding item statistics
func (*FundingStatistics) PrintResults ¶
func (f *FundingStatistics) PrintResults(wasAnyDataMissing bool) error
PrintResults outputs all calculated funding statistics to the command line
type Handler ¶
type Handler interface {
SetStrategyName(string)
SetupEventForTime(common.DataEventHandler) error
SetEventForOffset(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 Ratios ¶
type Ratios struct {
SharpeRatio decimal.Decimal `json:"sharpe-ratio"`
SortinoRatio decimal.Decimal `json:"sortino-ratio"`
InformationRatio decimal.Decimal `json:"information-ratio"`
CalmarRatio decimal.Decimal `json:"calmar-ratio"`
}
Ratios stores all the ratios used for statistics
func CalculateRatios ¶
func CalculateRatios(benchmarkRates, returnsPerCandle []decimal.Decimal, riskFreeRatePerCandle decimal.Decimal, maxDrawdown *Swing, logMessage string) (arithmeticStats, geometricStats *Ratios, err error)
CalculateRatios creates arithmetic and geometric ratios from funding or currency pair data
type ResultEvent ¶
ResultEvent stores the time
type ResultTransactions ¶
type ResultTransactions struct {
Time time.Time `json:"time"`
Direction gctorder.Side `json:"direction"`
Price decimal.Decimal `json:"price"`
Amount decimal.Decimal `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"`
StartDate time.Time `json:"start-date"`
EndDate time.Time `json:"end-date"`
CandleInterval gctkline.Interval `json:"candle-interval"`
RiskFreeRate decimal.Decimal `json:"risk-free-rate"`
ExchangeAssetPairStatistics map[string]map[asset.Item]map[currency.Pair]*CurrencyPairStatistic `json:"exchange-asset-pair-statistics"`
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"`
CurrencyPairStatistics []CurrencyPairStatistic `json:"currency-pair-statistics"` // as ExchangeAssetPairStatistics cannot be rendered via json.Marshall, we append all result to this slice instead
WasAnyDataMissing bool `json:"was-any-data-missing"`
FundingStatistics *FundingStatistics `json:"funding-statistics"`
FundManager funding.IFundingManager `json:"-"`
}
Statistic holds all statistical information for a backtester run, from drawdowns to ratios. Any currency specific information is handled in currencystatistics
func (*Statistic) AddComplianceSnapshotForTime ¶
AddComplianceSnapshotForTime adds the compliance snapshot to the statistics at the time period
func (*Statistic) AddHoldingsForTime ¶
AddHoldingsForTime adds all holdings to the statistics at the time period
func (*Statistic) CalculateAllResults ¶
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) PrintAllEventsChronologically ¶
func (s *Statistic) PrintAllEventsChronologically()
PrintAllEventsChronologically outputs all event details in the CMD rather than separated by exchange, asset and currency pair, it's grouped by time to allow a clearer picture of events
func (*Statistic) PrintTotalResults ¶
func (s *Statistic) PrintTotalResults()
PrintTotalResults outputs all results to the CMD
func (*Statistic) SetEventForOffset ¶
func (s *Statistic) SetEventForOffset(ev common.EventHandler) error
SetEventForOffset sets the event for the time period in the event
func (*Statistic) SetStrategyName ¶
SetStrategyName sets the name for statistical identification
func (*Statistic) SetupEventForTime ¶
func (s *Statistic) SetupEventForTime(ev common.DataEventHandler) error
SetupEventForTime sets up the big map for to store important data at each time interval
type Swing ¶
type Swing struct {
Highest ValueAtTime `json:"highest"`
Lowest ValueAtTime `json:"lowest"`
DrawdownPercent decimal.Decimal `json:"drawdown"`
IntervalDuration int64
}
Swing holds a drawdown
func CalculateBiggestEventDrawdown ¶
func CalculateBiggestEventDrawdown(closePrices []common.DataEventHandler) (Swing, error)
CalculateBiggestEventDrawdown calculates the biggest drawdown using a slice of DataEvents
func CalculateBiggestValueAtTimeDrawdown ¶
func CalculateBiggestValueAtTimeDrawdown(closePrices []ValueAtTime, interval gctkline.Interval) (Swing, error)
CalculateBiggestValueAtTimeDrawdown calculates the biggest drawdown using a slice of ValueAtTimes
type TotalFundingStatistics ¶
type TotalFundingStatistics struct {
HoldingValues []ValueAtTime
InitialHoldingValue ValueAtTime
FinalHoldingValue ValueAtTime
HighestHoldingValue ValueAtTime
LowestHoldingValue ValueAtTime
BenchmarkMarketMovement decimal.Decimal
StrategyMovement decimal.Decimal
RiskFreeRate decimal.Decimal
CompoundAnnualGrowthRate decimal.Decimal
BuyOrders int64
SellOrders int64
TotalOrders int64
MaxDrawdown Swing
GeometricRatios *Ratios
ArithmeticRatios *Ratios
DidStrategyBeatTheMarket bool
DidStrategyMakeProfit bool
HoldingValueDifference decimal.Decimal
}
TotalFundingStatistics holds values for overal statistics for funding items