tweaks to make ticks not be terrible
This commit is contained in:
parent
7b5bb6e952
commit
c3a066aecd
24 changed files with 480 additions and 271 deletions
71
sequence.go
71
sequence.go
|
|
@ -45,6 +45,19 @@ func (s sequence) Random(samples int, scale float64) []float64 {
|
|||
return values
|
||||
}
|
||||
|
||||
// Random generates a fixed length sequence of random values with a given average, above and below that average by (-scale, scale)
|
||||
func (s sequence) RandomWithAverage(samples int, average, scale float64) []float64 {
|
||||
rnd := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
values := make([]float64, samples)
|
||||
|
||||
for x := 0; x < samples; x++ {
|
||||
jitter := scale - (rnd.Float64() * (2 * scale))
|
||||
values[x] = average + jitter
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
||||
// Days generates a sequence of timestamps by day, from -days to today.
|
||||
func (s sequence) Days(days int) []time.Time {
|
||||
var values []time.Time
|
||||
|
|
@ -53,3 +66,61 @@ func (s sequence) Days(days int) []time.Time {
|
|||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (s sequence) MarketHours(from, to time.Time, marketOpen, marketClose time.Time, isHoliday HolidayProvider) []time.Time {
|
||||
var times []time.Time
|
||||
cursor := Date.On(marketOpen, from)
|
||||
toClose := Date.On(marketClose, to)
|
||||
for cursor.Before(toClose) || cursor.Equal(toClose) {
|
||||
todayOpen := Date.On(marketOpen, cursor)
|
||||
todayClose := Date.On(marketClose, cursor)
|
||||
isValidTradingDay := !isHoliday(cursor) && Date.IsWeekDay(cursor.Weekday())
|
||||
|
||||
if (cursor.Equal(todayOpen) || cursor.After(todayOpen)) && (cursor.Equal(todayClose) || cursor.Before(todayClose)) && isValidTradingDay {
|
||||
times = append(times, cursor)
|
||||
}
|
||||
if cursor.After(todayClose) {
|
||||
cursor = Date.NextMarketOpen(cursor, marketOpen, isHoliday)
|
||||
} else {
|
||||
cursor = Date.NextHour(cursor)
|
||||
}
|
||||
}
|
||||
return times
|
||||
}
|
||||
|
||||
func (s sequence) MarketHourQuarters(from, to time.Time, marketOpen, marketClose time.Time, isHoliday HolidayProvider) []time.Time {
|
||||
var times []time.Time
|
||||
cursor := Date.On(marketOpen, from)
|
||||
toClose := Date.On(marketClose, to)
|
||||
for cursor.Before(toClose) || cursor.Equal(toClose) {
|
||||
|
||||
isValidTradingDay := !isHoliday(cursor) && Date.IsWeekDay(cursor.Weekday())
|
||||
|
||||
if isValidTradingDay {
|
||||
todayOpen := Date.On(marketOpen, cursor)
|
||||
todayNoon := Date.NoonOn(cursor)
|
||||
today2pm := Date.On(Date.ClockTime(2, 0, 0, 0, cursor.Location()), cursor)
|
||||
todayClose := Date.On(marketClose, cursor)
|
||||
times = append(times, todayOpen, todayNoon, today2pm, todayClose)
|
||||
}
|
||||
|
||||
cursor = Date.NextDay(cursor)
|
||||
}
|
||||
return times
|
||||
}
|
||||
|
||||
func (s sequence) MarketDayCloses(from, to time.Time, marketOpen, marketClose time.Time, isHoliday HolidayProvider) []time.Time {
|
||||
var times []time.Time
|
||||
cursor := Date.On(marketOpen, from)
|
||||
toClose := Date.On(marketClose, to)
|
||||
for cursor.Before(toClose) || cursor.Equal(toClose) {
|
||||
isValidTradingDay := !isHoliday(cursor) && Date.IsWeekDay(cursor.Weekday())
|
||||
if isValidTradingDay {
|
||||
todayClose := Date.On(marketClose, cursor)
|
||||
times = append(times, todayClose)
|
||||
}
|
||||
|
||||
cursor = Date.NextDay(cursor)
|
||||
}
|
||||
return times
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue