utils

package
v0.0.0-...-ed9ff44 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Debug = zap.DebugLevel
	Info  = zap.InfoLevel
	Warn  = zap.WarnLevel
	Error = zap.ErrorLevel
	Fatal = zap.FatalLevel
)
View Source
const (
	LT = iota
	GT
	LE
	GE
)
View Source
const (
	Ascending = iota
	Descending
)

Variables

View Source
var US = "America/New_York"

Functions

func NewZapLogger

func NewZapLogger(component string, level zapcore.Level) *zap.Logger

Types

type Asset

type Asset struct {
	Symbol string
	Name   string
	Id     string
	Rank   float64
}

type Comparison

type Comparison int

type Filter

type Filter struct {
	Indicator indicators.Indicator
	Operator  Comparison
	Value     interface{}
}

func NewFilter

func NewFilter(indicator indicators.Indicator, operator Comparison, value interface{}) *Filter

NewFilter creates a new Filter with the given indicator, comparison operator, and value. The indicator should be an implementation of the Indicator interface, which has a Compute method that returns a slice of float64 values.

The operator should be one of the Comparison constants: LT (less than), GT (greater than), LE (less than or equal to), or GE (greater than or equal to).

The value can be either a float64 or an implementation of the Indicator interface. If it's a float64, it represents the value that the indicator's computed result will be compared to. If it's an Indicator, its Compute method will be called to get the value to compare to.

The function returns a pointer to the newly created Filter.

Usage:

filter := NewFilter(MyIndicator{}, LT, 100.0)
filter := NewFilter(MyIndicator{}, LT, OtherIndicator{})

The first example creates a new Filter that uses MyIndicator as the indicator, LT as the comparison operator, and 100.0 as the value to compare to. The second example creates a new Filter that uses MyIndicator as the indicator, LT as the comparison operator, and the result of OtherIndicator's Compute method as the value to compare to.

type RankOrder

type RankOrder int

type Ranking

type Ranking struct {
	Indicator indicators.Indicator
	Order     RankOrder
}

type Stack

type Stack []interface{}

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

func (*Stack) Pop

func (s *Stack) Pop() interface{}

func (*Stack) Push

func (s *Stack) Push(v interface{})

type TimeWindow

type TimeWindow struct {
	Start    time.Time
	End      time.Time
	Location *time.Location
}

func NewTimeWindow

func NewTimeWindow(startHour, startMinute, endHour, endMinute int, location *time.Location) TimeWindow

func TradingWindowUS

func TradingWindowUS() (TimeWindow, error)

TradingWindowUS creates a new TradingWindow struct representing the standard trading hours of AMEX, ARCA, BATS, NYSE, NASDAQ, NYSEARCA. Here are the standard trading hours for these exchanges (in Eastern Time):

  • Pre-Market Trading Hours: 4:00 a.m. to 9:30 a.m.
  • Regular Trading Hours: 9:30 a.m. to 4:00 p.m.
  • After-Market Hours: 4:00 p.m. to 8:00 p.m.

func TradingWindowUSOnClose

func TradingWindowUSOnClose() (TimeWindow, error)

func TradingWindowUSOnOpen

func TradingWindowUSOnOpen() (TimeWindow, error)

type TradingCalendar

type TradingCalendar struct {
	Calendar     *cal.BusinessCalendar
	OnOpen       TimeWindow
	OnClose      TimeWindow
	TradingHours TimeWindow
}

func NewTradingCalendarUS

func NewTradingCalendarUS() (*TradingCalendar, error)

NewTradingCalendarUS creates a new TradingCalendar with specified opening and closing trading windows. It initializes a business calendar 'c' and adds US holidays to it. The function takes two arguments: 'OnOpen' and 'OnClose', which are TradingWindow structs representing the opening and closing hours of the trading day, respectively. It returns a TradingCalendar struct.

func (*TradingCalendar) IsOnClose

func (c *TradingCalendar) IsOnClose(t time.Time) bool

IsOnClose checks if the provided time 't' falls within the closing hours of the trading day. It does so by converting the given time to the same location as the calendar. It returns true if 't' is within the closing hours, and false otherwise.

func (*TradingCalendar) IsOnOpen

func (c *TradingCalendar) IsOnOpen(t time.Time) bool

IsOnOpen checks if the provided time 't' falls within the opening hours of the trading day. It does so by converting the given time to the same location as the calendar. It returns true if 't' is within the opening hours, and false otherwise.

func (*TradingCalendar) IsTradingDay

func (c *TradingCalendar) IsTradingDay(t time.Time) bool

IsTradingDay checks if the provided time 't' falls on a trading day according to the calendar 'c'. It returns true if 't' is a trading day, and false otherwise.

func (*TradingCalendar) NextBusinessDay

func (c *TradingCalendar) NextBusinessDay(t time.Time) time.Time

NextBusinessDay returns the next business day after the given time t. It checks if the given time t is a workday according to the TradingCalendar's calendar. If t is not a workday (it's a holiday or a weekend), it adds one day and checks again. It continues this process until it finds a workday, which it then returns. This function does not account for business hours; it only checks the date. If the given time t is already a workday, it will return the same day.

Parameters: t : A time.Time value representing the date to start from.

Returns: The next business day (as a time.Time value) after the given time t, or the same day if t is already a business day.

func (*TradingCalendar) NextDayOnClose

func (c *TradingCalendar) NextDayOnClose(t time.Time) TimeWindow

NextDayOnClose Returns the trading window for the closing hours of the next trading day after the provided time "t".

func (*TradingCalendar) NextDayOnOpen

func (c *TradingCalendar) NextDayOnOpen(t time.Time) TimeWindow

NextDayOnOpen Returns the trading window for the opening hours of the next trading day after the provided time "t".

type Watchlist

type Watchlist struct {
	Assets  []Asset
	Filters []Filter
	Ranking *Ranking
}

func NewWatchlist

func NewWatchlist(assets []Asset, filters []Filter, ranking *Ranking) *Watchlist

func (*Watchlist) AddAsset

func (w *Watchlist) AddAsset(a Asset)

func (*Watchlist) AddFilter

func (w *Watchlist) AddFilter(f Filter)

func (*Watchlist) AddRanking

func (w *Watchlist) AddRanking(r *Ranking)

func (*Watchlist) ApplyFilters

func (w *Watchlist) ApplyFilters(symbol string, bars *indicators.BarHistory) bool

func (*Watchlist) ApplyRanking

func (w *Watchlist) ApplyRanking(asset *Asset, bars *indicators.BarHistory)

func (*Watchlist) RankAssets

func (w *Watchlist) RankAssets(assets []Asset)

Jump to

Keyboard shortcuts

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