aggregator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentName = "aggregator"

Variables

This section is empty.

Functions

func ConfidenceInDifference

func ConfidenceInDifference(min, max float64) float64

ConfidenceInDifference calculates the percentage difference between the max and min and subtract this from 100%. Example: min 1, max 2 Difference is 1 which is 100% so the final confidence is 100-100 equals 0%.

Types

type Aggregator

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

func New

func New(
	ctx context.Context,
	logger log.Logger,
	cfg Config,
	tsDB storage.SampleAndChunkQueryable,
) (*Aggregator, error)

func (*Aggregator) ManualValue

func (self *Aggregator) ManualValue(oracleName string, reqID int64, ts time.Time) (float64, bool, error)

func (*Aggregator) MeanAt

func (self *Aggregator) MeanAt(symbol string, at time.Time) (float64, float64, error)

func (*Aggregator) MedianAt

func (self *Aggregator) MedianAt(symbol string, at time.Time) (float64, float64, error)

func (*Aggregator) MedianAtEOD

func (self *Aggregator) MedianAtEOD(symbol string, at time.Time) (float64, float64, error)

func (*Aggregator) TimeWeightedAvg

func (self *Aggregator) TimeWeightedAvg(
	symbol string,
	start time.Time,
	lookBack time.Duration,
) (float64, float64, error)

TimeWeightedAvg returns price and confidence level for a given symbol. Confidence is calculated based on maximum possible samples over the actual samples for a given period. avg(maxPossibleSamplesCount/actualSamplesCount) For example with 1h look back and source interval of 60sec maxPossibleSamplesCount = 36 with actualSamplesCount = 18 this is 50% confidence. The same calculation is done for all source and the final value is the average of all.

Example for 1h. maxDataPointCount is calculated by deviding the seconds in 1h by how often the tracker queries the APIs. avg(count_over_time(trackerIndex_value{symbol="AMPL_USD"}[1h]) / (3.6e+12/trackerIndex_interval)).

func (*Aggregator) VolumWeightedAvg

func (self *Aggregator) VolumWeightedAvg(
	symbol string,
	start time.Time,
	end time.Time,
	aggrWindow time.Duration,
) (float64, float64, error)

VolumWeightedAvg returns price and confidence level for a given symbol. Confidence is calculated based on maximum possible samples over the actual samples for a given period. avg(maxPossibleSamplesCount/actualSamplesCount) For example with 1h look back and source interval of 60sec maxPossibleSamplesCount = 36 with actualSamplesCount = 18 this is 50% confidence. The same calculation is done for all source and the final value is the average of all. maxDataPointCount is calculated by deviding the seconds in 1h by how often the tracker queries the APIs.

Example for 1h. avg(count_over_time(trackerIndex_value{symbol="AMPL_USD"}[1h]) / (3.6e+12/30s)).

vals are calculated using the official VWAP formula from https://tradingtuitions.com/vwap-trading-strategy-excel-sheet/

type Config

type Config struct {
	LogLevel       string
	ManualDataFile string
}

type IAggregator

type IAggregator interface {
	TimeWeightedAvg(symbol string, start time.Time, lookBack time.Duration) (float64, float64, error)
}

Jump to

Keyboard shortcuts

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