business

package
v0.0.0-...-3f3263e Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitConditionNormal = 0
	ExitConditionStop   = -1
	ExitConditionProfit = +1
)
View Source
const SlotNum int = 48 * 5

Variables

View Source
var DefaultFrom = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
View Source
var DefaultTo = time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC)

Functions

func AddBiasAnalysis

func AddBiasAnalysis(tx *gorm.DB, c *auth.Context, bas *BiasAnalysisSpec) (*db.BiasAnalysis, error)

func AddBiasConfig

func AddBiasConfig(tx *gorm.DB, c *auth.Context, baId uint, bcs *BiasConfigSpec) (*db.BiasConfig, error)

func AddDataInstrumentAndJob

func AddDataInstrumentAndJob(tx *gorm.DB, c *auth.Context, productId uint, spec *DatafileUploadSpec, filename string, bytes int64) error

func CreateDataConfig

func CreateDataConfig(tx *gorm.DB, id uint) (*ds.DataConfig, error)

func DeleteBiasConfig

func DeleteBiasConfig(tx *gorm.DB, c *auth.Context, baId uint, id uint) (bool, error)

func GetBiasAnalyses

func GetBiasAnalyses(tx *gorm.DB, c *auth.Context, filter map[string]any, offset int, limit int, details bool) (*[]db.BiasAnalysisFull, error)

func GetBiasConfigsByAnalysisId

func GetBiasConfigsByAnalysisId(tx *gorm.DB, c *auth.Context, baId uint) (*[]*BiasConfig, error)

func GetBiasSummaryData

func GetBiasSummaryData(c *auth.Context, id uint, bsr *BiasSummaryResponse) error

func GetDataInstruments

func GetDataInstruments(tx *gorm.DB, c *auth.Context) (*[]db.DataInstrumentFull, error)

func GetDataInstrumentsByProductId

func GetDataInstrumentsByProductId(tx *gorm.DB, c *auth.Context, productId uint) (*[]db.DataInstrument, error)

func RunBacktest

func RunBacktest(c *auth.Context, bbr *BiasBacktestResponse) error

func UpdateBiasAnalysis

func UpdateBiasAnalysis(tx *gorm.DB, c *auth.Context, id uint, bas *BiasAnalysisSpec) (*db.BiasAnalysis, error)

func UpdateBiasConfig

func UpdateBiasConfig(tx *gorm.DB, c *auth.Context, baId uint, id uint, bcs *BiasConfigSpec) (*db.BiasConfig, error)

Types

type BacktestedConfig

type BacktestedConfig struct {
	BiasConfig    *BiasConfig           `json:"biasConfig"`
	GrossProfit   float64               `json:"grossProfit"`
	NetProfit     float64               `json:"netProfit"`
	GrossAvgTrade float64               `json:"grossAvgTrade"`
	NetAvgTrade   float64               `json:"netAvgTrade"`
	Trades        []*BiasTrade          `json:"biasTrades"`
	Sequences     []*TriggeringSequence `json:"sequences"`
	Equity        *Equity               `json:"equity"`
	ProfitDistrib *ProfitDistribution   `json:"profitDistrib"`
	// contains filtered or unexported fields
}

func NewBacktestedConfig

func NewBacktestedConfig(bc *BiasConfig, bp *db.BrokerProduct, spec *BiasBacktestSpec) (*BacktestedConfig, error)

func (*BacktestedConfig) EndTrade

func (btc *BacktestedConfig) EndTrade(currDp *ds.DataPoint, exitCondition int8)

func (*BacktestedConfig) Finish

func (btc *BacktestedConfig) Finish()

func (*BacktestedConfig) IsDayAllowed

func (btc *BacktestedConfig) IsDayAllowed(ti *TimeInfo) bool

func (*BacktestedConfig) IsEndOfTrade

func (btc *BacktestedConfig) IsEndOfTrade(ti *TimeInfo) bool

func (*BacktestedConfig) IsStartOfTrade

func (btc *BacktestedConfig) IsStartOfTrade(ti *TimeInfo) bool

func (*BacktestedConfig) RunBacktest

func (btc *BacktestedConfig) RunBacktest(ti *TimeInfo, currDp *ds.DataPoint, prevDp *ds.DataPoint, i int, dataPoints []*ds.DataPoint)

func (*BacktestedConfig) StartTrade

func (btc *BacktestedConfig) StartTrade(currDp, prevDp *ds.DataPoint, index int, dataPoints []*ds.DataPoint)

type BiasAnalysisExt

type BiasAnalysisExt struct {
	db.BiasAnalysis
	DataInstrument db.DataInstrument `json:"dataInstrument"`
	BrokerProduct  db.BrokerProduct  `json:"brokerProduct"`
	Configs        *[]*BiasConfig    `json:"configs"`
}

func GetBiasAnalysisById

func GetBiasAnalysisById(tx *gorm.DB, c *auth.Context, id uint, details bool) (*BiasAnalysisExt, error)

type BiasAnalysisSpec

type BiasAnalysisSpec struct {
	DataInstrumentId uint   `json:"dataInstrumentId"`
	BrokerProductId  uint   `json:"brokerProductId"`
	Name             string `json:"name"`
	Notes            string `json:"notes"`
}

type BiasBacktestResponse

type BiasBacktestResponse struct {
	BiasAnalysis      *db.BiasAnalysis    `json:"biasAnalysis"`
	BrokerProduct     *db.BrokerProduct   `json:"brokerProduct"`
	Spec              *BiasBacktestSpec   `json:"spec"`
	BacktestedConfigs []*BacktestedConfig `json:"backtestedConfigs"`
	// contains filtered or unexported fields
}

func GetBacktestInfo

func GetBacktestInfo(tx *gorm.DB, c *auth.Context, id uint, spec *BiasBacktestSpec) (*BiasBacktestResponse, error)

type BiasBacktestSpec

type BiasBacktestSpec struct {
	StopLoss   float64                 `json:"stopLoss"`
	TakeProfit float64                 `json:"takeProfit"`
	Session    *session.TradingSession `json:"session"`
}

type BiasConfig

type BiasConfig struct {
	BiasConfigSpec
	Id             uint `json:"id"`
	BiasAnalysisId uint `json:"biasAnalysisId"`
}

func (*BiasConfig) FromBiasConfig

func (bc *BiasConfig) FromBiasConfig(dbc *db.BiasConfig)

type BiasConfigSpec

type BiasConfigSpec struct {
	StartDay    int16    `json:"startDay"`
	StartSlot   int16    `json:"startSlot"`
	EndDay      int16    `json:"endDay"`
	EndSlot     int16    `json:"endSlot"`
	Months      []bool   `json:"months"`
	Excludes    []string `json:"excludes"`
	Operation   int8     `json:"operation"`
	GrossProfit float64  `json:"grossProfit"`
	NetProfit   float64  `json:"netProfit"`
}

func (*BiasConfigSpec) ToBiasConfig

func (bcs *BiasConfigSpec) ToBiasConfig() *db.BiasConfig

type BiasSummaryResponse

type BiasSummaryResponse struct {
	BiasAnalysis  *db.BiasAnalysis     `json:"biasAnalysis"`
	BrokerProduct *db.BrokerProduct    `json:"brokerProduct"`
	Result        [7]*DataPointDowList `json:"result"`
	// contains filtered or unexported fields
}

func GetBiasSummaryInfo

func GetBiasSummaryInfo(tx *gorm.DB, c *auth.Context, id uint) (*BiasSummaryResponse, error)

func (*BiasSummaryResponse) Add

func (r *BiasSummaryResponse) Add(dpd *DataPointDelta)

type BiasTrade

type BiasTrade struct {
	EntryTime     time.Time `json:"entryTime"`
	EntryValue    float64   `json:"entryValue"`
	ExitTime      time.Time `json:"exitTime"`
	ExitValue     float64   `json:"exitValue"`
	Operation     int8      `json:"operation"`
	GrossProfit   float64   `json:"grossProfit"`
	NetProfit     float64   `json:"netProfit"`
	ExitCondition int8      `json:"exitCondition"`
	// contains filtered or unexported fields
}

func NewBiasTrade

func NewBiasTrade(currDp, prevDp *ds.DataPoint, btc *BacktestedConfig) *BiasTrade

func (*BiasTrade) Close

func (bt *BiasTrade) Close(dp *ds.DataPoint, bp *db.BrokerProduct, exitCondition int8)

func (*BiasTrade) IsInProfit

func (bt *BiasTrade) IsInProfit(currDp *ds.DataPoint) bool

func (*BiasTrade) IsInStopLoss

func (bt *BiasTrade) IsInStopLoss(currDp *ds.DataPoint) bool

type DataInstrumentDataParams

type DataInstrumentDataParams struct {
	Location   *time.Location
	From       time.Time
	To         time.Time
	Reduction  int
	Aggregator *ds.DataAggregator
}

type DataInstrumentDataResponse

type DataInstrumentDataResponse struct {
	Id         uint            `json:"id"`
	Symbol     string          `json:"symbol"`
	From       string          `json:"from"`
	To         string          `json:"to"`
	Timeframe  string          `json:"timeframe"`
	Timezone   string          `json:"timezone"`
	Reduction  int             `json:"reduction,omitempty"`
	Reduced    bool            `json:"reduced"`
	Records    int             `json:"records"`
	DataPoints []*ds.DataPoint `json:"dataPoints"`
}

type DataInstrumentDataSpec

type DataInstrumentDataSpec struct {
	Id        uint
	From      string
	To        string
	Timezone  string
	Reduction string
	Config    *ds.DataConfig
}

type DataInstrumentExt

type DataInstrumentExt struct {
	db.DataInstrument
}

func GetDataInstrumentById

func GetDataInstrumentById(tx *gorm.DB, c *auth.Context, id uint, details bool) (*DataInstrumentExt, error)

type DataPointDelta

type DataPointDelta struct {
	Year  int
	Month int
	Day   int
	Hour  int
	Min   int
	Delta float64
	Dow   int
}

type DataPointDowList

type DataPointDowList struct {
	Slots [48]*DataPointSlotList `json:"slots"`
}

func (*DataPointDowList) Add

func (l *DataPointDowList) Add(dpd *DataPointDelta)

type DataPointEntry

type DataPointEntry struct {
	Year  int16   `json:"year"`
	Month int8    `json:"month"`
	Day   int8    `json:"day"`
	Delta float64 `json:"delta"`
}

type DataPointSlotList

type DataPointSlotList struct {
	List []*DataPointEntry `json:"list"`
}

func (*DataPointSlotList) Add

func (l *DataPointSlotList) Add(dpd *DataPointDelta)

type DatafileUploadResponse

type DatafileUploadResponse struct {
	Duration int   `json:"duration"`
	Bytes    int64 `json:"bytes"`
}

type DatafileUploadSpec

type DatafileUploadSpec struct {
	Symbol       string `json:"symbol"       binding:"required"`
	Name         string `json:"name"         binding:"required"`
	Continuous   bool   `json:"continuous"   binding:"required"`
	FileTimezone string `json:"fileTimezone" binding:"required"`
	Parser       string `json:"parser"       binding:"required"`
}

type Equity

type Equity struct {
	Time  []time.Time `json:"time"`
	Gross []float64   `json:"gross"`
	Net   []float64   `json:"net"`
}

func NewEquity

func NewEquity(trades []*BiasTrade) *Equity

type ExcludedPeriod

type ExcludedPeriod struct {
	Year  int16
	Month int16
}

func NewExcludedPeriod

func NewExcludedPeriod(value string) (*ExcludedPeriod, error)

func (*ExcludedPeriod) ShouldBeExcluded

func (ep *ExcludedPeriod) ShouldBeExcluded(month, year int16) bool

type ExcludedSet

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

func NewExcludedSet

func NewExcludedSet(items []string) (*ExcludedSet, error)

func (*ExcludedSet) ShouldBeExcluded

func (es *ExcludedSet) ShouldBeExcluded(month, year int16) bool

type ProfitDistribution

type ProfitDistribution struct {
	NetProfits [16]float64 `json:"netProfits"`
	NumTrades  [16]int     `json:"numTrades"`
	AvgTrades  [16]float64 `json:"avgTrades"`
}

func NewProfitDistribution

func NewProfitDistribution(trades []*BiasTrade, costPerOperation float64) *ProfitDistribution

type TimeInfo

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

type TriggeringSequence

type TriggeringSequence struct {
	DataPoints []*ds.DataPoint
}

func NewTriggeringSequence

func NewTriggeringSequence(index int, dataPoints []*ds.DataPoint, slotNum int) *TriggeringSequence

Jump to

Keyboard shortcuts

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