Documentation ¶
Index ¶
- Variables
- type CurrencyPairStatistic
- type CurrencyStats
- type DataAtOffset
- 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 common.Event) error
- func (s *Statistic) AddHoldingsForTime(h *holdings.Holding) error
- func (s *Statistic) AddPNLForTime(pnl *portfolio.PNLSummary) error
- func (s *Statistic) CalculateAllResults() error
- func (s *Statistic) CreateLog(data common.Event) (string, 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() error
- func (s *Statistic) Serialise() (string, error)
- func (s *Statistic) SetEventForOffset(ev common.Event) error
- func (s *Statistic) SetStrategyName(name string)
- 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 { Exchange string Asset asset.Item Currency currency.Pair UnderlyingPair currency.Pair `json:"linked-spot-currency"` 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 ValueAtTime `json:"starting-close-price"` EndingClosePrice ValueAtTime `json:"ending-close-price"` LowestClosePrice ValueAtTime `json:"lowest-close-price"` HighestClosePrice ValueAtTime `json:"highest-close-price"` HighestUnrealisedPNL ValueAtTime `json:"highest-unrealised-pnl"` LowestUnrealisedPNL ValueAtTime `json:"lowest-unrealised-pnl"` HighestRealisedPNL ValueAtTime `json:"highest-realised-pnl"` LowestRealisedPNL ValueAtTime `json:"lowest-realised-pnl"` MarketMovement decimal.Decimal `json:"market-movement"` StrategyMovement decimal.Decimal `json:"strategy-movement"` UnrealisedPNL decimal.Decimal `json:"unrealised-pnl"` RealisedPNL decimal.Decimal `json:"realised-pnl"` CompoundAnnualGrowthRate decimal.Decimal `json:"compound-annual-growth-rate"` TotalAssetValue decimal.Decimal `json:"total-asset-value"` TotalFees decimal.Decimal `json:"total-fees"` TotalValueLostToVolumeSizing decimal.Decimal `json:"total-value-lost-to-volume-sizing"` TotalValueLostToSlippage decimal.Decimal `json:"total-value-lost-to-slippage"` TotalValueLost decimal.Decimal `json:"total-value-lost"` Events []DataAtOffset `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) error
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 DataAtOffset ¶
type DataAtOffset struct { Offset int64 ClosePrice decimal.Decimal Time time.Time Holdings holdings.Holding ComplianceSnapshot *compliance.Snapshot DataEvent data.Event SignalEvent signal.Event OrderEvent order.Event FillEvent fill.Event PNL portfolio.IPNL }
DataAtOffset 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 `json:"-"` // USD stats StartingClosePrice ValueAtTime `json:"starting-close-price"` EndingClosePrice ValueAtTime `json:"ending-close-price"` LowestClosePrice ValueAtTime `json:"lowest-close-price"` HighestClosePrice ValueAtTime `json:"highest-close-price"` MarketMovement decimal.Decimal `json:"market-movement"` StrategyMovement decimal.Decimal `json:"strategy-movement"` DidStrategyBeatTheMarket bool `json:"did-strategy-beat-the-market"` RiskFreeRate decimal.Decimal `json:"risk-free-rate"` CompoundAnnualGrowthRate decimal.Decimal `json:"compound-annual-growth-rate"` BuyOrders int64 `json:"buy-orders"` SellOrders int64 `json:"sell-orders"` TotalOrders int64 `json:"total-orders"` MaxDrawdown Swing `json:"max-drawdown"` HighestCommittedFunds ValueAtTime `json:"highest-committed-funds"` // CollateralPair stats IsCollateral bool `json:"is-collateral"` InitialCollateral ValueAtTime `json:"initial-collateral"` FinalCollateral ValueAtTime `json:"final-collateral"` HighestCollateral ValueAtTime `json:"highest-collateral"` LowestCollateral ValueAtTime `json:"lowest-collateral"` // Contracts LowestHoldings ValueAtTime `json:"lowest-holdings"` HighestHoldings ValueAtTime `json:"highest-holdings"` InitialHoldings ValueAtTime `json:"initial-holdings"` FinalHoldings ValueAtTime `json:"final-holdings"` }
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 `json:"-"` Items []FundingItemStatistics `json:"funding-item-statistics"` TotalUSDStatistics *TotalFundingStatistics `json:"total-usd-statistics"` }
FundingStatistics stores all funding related statistics
func CalculateFundingStatistics ¶
func CalculateFundingStatistics(funds funding.IFundingManager, currStats map[key.ExchangePairAsset]*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) SetEventForOffset(common.Event) error AddHoldingsForTime(*holdings.Holding) error AddComplianceSnapshotForTime(*compliance.Snapshot, common.Event) error CalculateAllResults() error Reset() error Serialise() (string, error) AddPNLForTime(*portfolio.PNLSummary) error CreateLog(common.Event) (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[key.ExchangePairAsset]*CurrencyPairStatistic `json:"-"` CurrencyStatistics []*CurrencyPairStatistic `json:"currency-statistics"` TotalBuyOrders int64 `json:"total-buy-orders"` TotalLongOrders int64 `json:"total-long-orders"` TotalShortOrders int64 `json:"total-short-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"` WasAnyDataMissing bool `json:"was-any-data-missing"` FundingStatistics *FundingStatistics `json:"funding-statistics"` FundManager funding.IFundingManager `json:"-"` HasCollateral bool `json:"has-collateral"` }
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) AddPNLForTime ¶
func (s *Statistic) AddPNLForTime(pnl *portfolio.PNLSummary) error
AddPNLForTime stores PNL data for tracking purposes
func (*Statistic) CalculateAllResults ¶
CalculateAllResults calculates the statistics of all exchange asset pair holdings, orders, ratios and drawdowns
func (*Statistic) CreateLog ¶
CreateLog renders a string log depending on what events are populated at a given offset. Can render logs live, or at the end of a backtesting run
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 ¶
SetEventForOffset sets up the big map for to store important data at each time interval
func (*Statistic) SetStrategyName ¶
SetStrategyName sets the name for statistical identification
type Swing ¶
type Swing struct { Highest ValueAtTime `json:"highest"` Lowest ValueAtTime `json:"lowest"` DrawdownPercent decimal.Decimal `json:"drawdown"` IntervalDuration int64 `json:"interval-duration"` }
Swing holds a drawdown
func CalculateBiggestEventDrawdown ¶
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 `json:"-"` HighestHoldingValue ValueAtTime `json:"highest-holding-value"` LowestHoldingValue ValueAtTime `json:"lowest-holding-value"` BenchmarkMarketMovement decimal.Decimal `json:"benchmark-market-movement"` RiskFreeRate decimal.Decimal `json:"risk-free-rate"` CompoundAnnualGrowthRate decimal.Decimal `json:"compound-annual-growth-rate"` MaxDrawdown Swing `json:"max-drawdown"` GeometricRatios *Ratios `json:"geometric-ratios"` ArithmeticRatios *Ratios `json:"arithmetic-ratios"` DidStrategyBeatTheMarket bool `json:"did-strategy-beat-the-market"` DidStrategyMakeProfit bool `json:"did-strategy-make-profit"` HoldingValueDifference decimal.Decimal `json:"holding-value-difference"` }
TotalFundingStatistics holds values for overall statistics for funding items