Documentation ¶
Index ¶
- Constants
- Variables
- func FilterDays(frequency dataframe.Frequency, dates []time.Time) []time.Time
- func LoadSecuritiesFromDB() error
- type ByDate
- type BySecurityMetric
- type CacheItem
- type Interval
- func (interval *Interval) Adjacent(other *Interval) bool
- func (interval *Interval) AdjacentLeft(other *Interval) bool
- func (interval *Interval) AdjacentRight(other *Interval) bool
- func (interval *Interval) Contains(other *Interval) bool
- func (interval *Interval) Contiguous(other *Interval) bool
- func (interval *Interval) MarshalZerologObject(e *zerolog.Event)
- func (interval *Interval) Overlaps(other *Interval) bool
- func (interval *Interval) Valid() error
- type Manager
- func (manager *Manager) GetLRU(key string) []byte
- func (manager *Manager) GetMetricOnOrBefore(security *Security, metric Metric, date time.Time) (float64, time.Time, error)
- func (manager *Manager) GetMetrics(securities []*Security, metrics []Metric, begin, end time.Time) (dataframe.Map, error)
- func (manager *Manager) PreloadMetrics(ctx context.Context, plan PortfolioPlan)
- func (manager *Manager) Reset()
- func (manager *Manager) SetLRU(key string, val []byte)
- func (manager *Manager) TradingDays(begin, end time.Time) *dataframe.DataFrame
- func (manager *Manager) TradingDaysAtFrequency(frequency dataframe.Frequency, begin, end time.Time) []time.Time
- type Metric
- type PortfolioPlan
- type PvDb
- func (p *PvDb) GetEOD(ctx context.Context, securities []*Security, metrics []Metric, ...) (dataframe.Map, error)
- func (p *PvDb) GetEODOnOrBefore(ctx context.Context, security *Security, metric Metric, date time.Time) (float64, time.Time, error)
- func (p *PvDb) TradingDays(ctx context.Context, begin time.Time, end time.Time) ([]time.Time, error)
- type Request
- func (req *Request) Between(a, b time.Time) (dataframe.Map, error)
- func (req *Request) Metrics(metrics ...Metric) *Request
- func (req *Request) On(a time.Time) (map[SecurityMetric]float64, error)
- func (req *Request) OnOrBefore(a time.Time) (float64, time.Time, error)
- func (req *Request) OnSingle(a time.Time) (float64, error)
- func (req *Request) Securities(securities ...*Security) *Request
- type Security
- type SecurityAllocation
- type SecurityMetric
- type SecurityMetricCache
- func (cache *SecurityMetricCache) Check(security *Security, metric Metric, begin, end time.Time) (bool, []*Interval)
- func (cache *SecurityMetricCache) Count() int
- func (cache *SecurityMetricCache) Get(security *Security, metric Metric, begin, end time.Time) (*dataframe.DataFrame, error)
- func (cache *SecurityMetricCache) GetPartial(security *Security, metric Metric, begin, end time.Time) *dataframe.DataFrame
- func (cache *SecurityMetricCache) ItemCount(security *Security, metric Metric) int
- func (cache *SecurityMetricCache) Items(security *Security, metric Metric) []*CacheItem
- func (cache *SecurityMetricCache) Set(security *Security, metric Metric, begin, end time.Time, ...) error
- func (cache *SecurityMetricCache) SetMatched(security *Security, metric Metric, begin, end time.Time, ...) error
- func (cache *SecurityMetricCache) SetWithLocalDates(security *Security, metric Metric, begin, end time.Time, ...) error
- func (cache *SecurityMetricCache) Size() int64
Constants ¶
const (
CashAsset = "$CASH"
)
Variables ¶
var ( ErrSingle = errors.New("cannot call *Single functions with multiple securities or metrics") ErrBeginAfterEnd = errors.New("invalid interval; begin after end date") ErrDataLargerThanCache = errors.New("data larger than cache size") ErrDateLengthDoesNotMatch = errors.New("length of date and values arrays must match when using local date index") ErrInvalidTimeRange = errors.New("start must be before end") ErrMultipleNotSupported = errors.New("on-or-before can only return a single metric for a single security") ErrNoData = errors.New("no data available") ErrSecurityNotFound = errors.New("security not found") ErrNoTradingDays = errors.New("no trading days available") ErrOutsideCoveredTime = errors.New("date range outside of covered time interval") ErrRangeDoesNotExist = errors.New("range does not exist in cache") ErrUnsupportedMetric = errors.New("unsupported metric") )
var ( CashSecurity = Security{ Ticker: CashAsset, CompositeFigi: CashAsset, } RiskFreeSecurity = Security{ CompositeFigi: "PVGG06TNP6J8", Ticker: "DGS3MO", } )
Functions ¶
func FilterDays ¶ added in v0.5.0
FilterDays takes an array of dates and filters it based on the requested frequency
func LoadSecuritiesFromDB ¶ added in v0.5.0
func LoadSecuritiesFromDB() error
Types ¶
type ByDate ¶ added in v0.5.0
type ByDate []pair
ByDate implements sort.Interface for []pair based on `last` the time field.
type BySecurityMetric ¶ added in v0.5.0
type BySecurityMetric []SecurityMetric
BySecurityMetric implements sort.Interface for []SecurityMetric
func (BySecurityMetric) Len ¶ added in v0.5.0
func (a BySecurityMetric) Len() int
func (BySecurityMetric) Less ¶ added in v0.5.0
func (a BySecurityMetric) Less(i, j int) bool
func (BySecurityMetric) Swap ¶ added in v0.5.0
func (a BySecurityMetric) Swap(i, j int)
type CacheItem ¶ added in v0.5.0
type CacheItem struct { Values []float64 Period *Interval CoveredPeriod *Interval // contains filtered or unexported fields }
func (*CacheItem) IsLocalDateIndex ¶ added in v0.5.0
IsLocalDateIndex returns true if a the CacheItem uses a local date index
func (*CacheItem) LocalDateIndex ¶ added in v0.5.0
LocalDateIndex returns the local date index
func (*CacheItem) MarshalZerologObject ¶ added in v0.5.0
type Interval ¶ added in v0.5.0
Intervals store a beginning and ending time period
func (*Interval) Adjacent ¶ added in v0.5.0
Adjacent checks if offset touches the beginning or ending of interval (daily resolution) NOTE: Adjaceny implies the two intervals DO NOT overlap
func (*Interval) AdjacentLeft ¶ added in v0.5.0
Adjacent checks if offset touches the beginning of interval (daily resolution) NOTE: Adjaceny implies the two intervals DO NOT overlap
func (*Interval) AdjacentRight ¶ added in v0.5.0
Adjacent checks if offset touches the ending of interval (daily resolution) NOTE: Adjaceny implies the two intervals DO NOT overlap
func (*Interval) Contains ¶ added in v0.5.0
Contains returns true if interval completely contains other
func (*Interval) Contiguous ¶ added in v0.5.0
Contiguous returns true if the other interval shares a common boarder with this interval this can mean they are adjacent or overlapping NOTE: contiguous implies that other is not a subset of interval
func (*Interval) MarshalZerologObject ¶ added in v0.5.0
MarshalZerologObject implement the log marshaller interface for zerolog
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func GetManagerInstance ¶ added in v0.5.0
func GetManagerInstance() *Manager
func (*Manager) GetMetricOnOrBefore ¶ added in v0.5.0
func (manager *Manager) GetMetricOnOrBefore(security *Security, metric Metric, date time.Time) (float64, time.Time, error)
GetMetricsOnOrBefore finds a single metric value on the requested date or the closest date available prior to the requested date
func (*Manager) GetMetrics ¶ added in v0.5.0
func (manager *Manager) GetMetrics(securities []*Security, metrics []Metric, begin, end time.Time) (dataframe.Map, error)
GetMetrics returns metrics for the requested securities over the specified time range
func (*Manager) PreloadMetrics ¶ added in v0.5.0
func (manager *Manager) PreloadMetrics(ctx context.Context, plan PortfolioPlan)
PreloadMetrics pre-emptively loads metrics into the data cache
func (*Manager) Reset ¶ added in v0.5.0
func (manager *Manager) Reset()
Reset restores the data manager to its initial state; clearing all cache - this is mostly used in testing
func (*Manager) TradingDays ¶
TradingDays returns a dataframe over the specified date period, all values in the dataframe are 0
type PortfolioPlan ¶ added in v0.5.0
type PortfolioPlan []*SecurityAllocation
func (PortfolioPlan) EndDate ¶ added in v0.5.0
func (pl PortfolioPlan) EndDate() time.Time
EndDate returns the ending date of the pie history
func (PortfolioPlan) Last ¶ added in v0.5.0
func (pl PortfolioPlan) Last() *SecurityAllocation
Last returns the last item in the PieHistory
func (PortfolioPlan) StartDate ¶ added in v0.5.0
func (pl PortfolioPlan) StartDate() time.Time
StartDate returns the starting date of the pie history
func (PortfolioPlan) Table ¶ added in v0.5.0
func (pl PortfolioPlan) Table()
Table prints an ASCII formated table to stdout
func (PortfolioPlan) Trim ¶ added in v0.5.0
func (pl PortfolioPlan) Trim(begin, end time.Time) PortfolioPlan
Trim the PieHistory to only cover the time period between begin and end (inclusive)
type PvDb ¶ added in v0.5.0
type PvDb struct { }
func (*PvDb) GetEOD ¶ added in v0.5.0
func (p *PvDb) GetEOD(ctx context.Context, securities []*Security, metrics []Metric, begin, end time.Time) (dataframe.Map, error)
GetEOD fetches EOD metrics from the database
func (*PvDb) GetEODOnOrBefore ¶ added in v0.5.0
func (p *PvDb) GetEODOnOrBefore(ctx context.Context, security *Security, metric Metric, date time.Time) (float64, time.Time, error)
GetEODOnOrBefore queries the database for the last value on or before the specified date. It returns the metric value and the date of the measurement as well as any errors that occur.
type Request ¶ added in v0.5.0
type Request struct {
// contains filtered or unexported fields
}
func NewDataRequest ¶ added in v0.5.0
NewDataRequest creates a new data request object for the requested securities. The frequency is defaulted to Monthly and the metric defaults to Adjusted Close
func (*Request) Between ¶ added in v0.5.0
Between queries the metric data store and returns a dataframe with metrics between the specified dates columns are named `CompositeFigi:MetricName`
func (*Request) OnOrBefore ¶ added in v0.5.0
func (*Request) OnSingle ¶ added in v0.5.0
OnSingle is a convenience function that returns the price for a single security and metric
func (*Request) Securities ¶ added in v0.5.0
type Security ¶ added in v0.5.0
Security represents a tradeable asset
func MustSecurityFromFigi ¶ added in v0.6.0
MustSecurityFromFigi loads a security from database using the Composite FIGI as the lookup key
func SecurityFromFigi ¶ added in v0.5.0
SecurityFromFigi loads a security from database using the Composite FIGI as the lookup key
func SecurityFromTicker ¶ added in v0.5.0
SecurityFromTicker loads a security from database using the ticker as the lookup key
func SecurityFromTickerList ¶ added in v0.5.0
SecurityFromTickerList loads securities from database using the ticker as the lookup key
type SecurityAllocation ¶ added in v0.5.0
type SecurityMetric ¶ added in v0.5.0
func NewSecurityMetricFromString ¶ added in v0.5.0
func NewSecurityMetricFromString(s string) SecurityMetric
func (SecurityMetric) String ¶ added in v0.5.0
func (sm SecurityMetric) String() string
String returns a string representation of the security metric
type SecurityMetricCache ¶ added in v0.5.0
type SecurityMetricCache struct {
// contains filtered or unexported fields
}
func NewSecurityMetricCache ¶ added in v0.5.0
func NewSecurityMetricCache(sz int64, periods []time.Time) *SecurityMetricCache
func (*SecurityMetricCache) Check ¶ added in v0.5.0
func (cache *SecurityMetricCache) Check(security *Security, metric Metric, begin, end time.Time) (bool, []*Interval)
Check returns if the requested range is in the cache. If the range is not completely covered by the cache returns false and a list of intervals covered by the cache that partially match the requested range.
func (*SecurityMetricCache) Count ¶ added in v0.5.0
func (cache *SecurityMetricCache) Count() int
Count returns the number of securities + metrics in the cache
func (*SecurityMetricCache) Get ¶ added in v0.5.0
func (cache *SecurityMetricCache) Get(security *Security, metric Metric, begin, end time.Time) (*dataframe.DataFrame, error)
Get returns the requested data over the range. If no data matches the hash key return ErrRangeDoesNotExist
func (*SecurityMetricCache) GetPartial ¶ added in v0.5.0
func (cache *SecurityMetricCache) GetPartial(security *Security, metric Metric, begin, end time.Time) *dataframe.DataFrame
GetPartial returns the requested data over the range. If the requested period only partially exists, return what is available.
func (*SecurityMetricCache) ItemCount ¶ added in v0.5.0
func (cache *SecurityMetricCache) ItemCount(security *Security, metric Metric) int
ItemCount returns the number of non-contiguous items in the cache for the given SecurityMetric
func (*SecurityMetricCache) Items ¶ added in v0.5.0
func (cache *SecurityMetricCache) Items(security *Security, metric Metric) []*CacheItem
Items returns the items in the cache for a given SecurityMetric. This method is only intended for testing.
func (*SecurityMetricCache) Set ¶ added in v0.5.0
func (cache *SecurityMetricCache) Set(security *Security, metric Metric, begin, end time.Time, df *dataframe.DataFrame) error
Set adds the data for the specified security and metric to the cache
func (*SecurityMetricCache) SetMatched ¶ added in v0.5.0
func (cache *SecurityMetricCache) SetMatched(security *Security, metric Metric, begin, end time.Time, df *dataframe.DataFrame) error
SetMatched adds the data for the specified security and metric to the cache assuming df's date frame matches cache.periods exactly
func (*SecurityMetricCache) SetWithLocalDates ¶ added in v0.5.0
func (cache *SecurityMetricCache) SetWithLocalDates(security *Security, metric Metric, begin, end time.Time, df *dataframe.DataFrame) error
Set adds the data for the specified security and metric to the cache
func (*SecurityMetricCache) Size ¶ added in v0.5.0
func (cache *SecurityMetricCache) Size() int64
Size returns the number of bytes currently stored in the SecurityMetricCache