fixing day of market results.

This commit is contained in:
Will Charczuk 2016-07-27 08:21:05 -07:00
parent 3bf31e45d3
commit ef1c38a641

View file

@ -33,7 +33,16 @@ func (mhr MarketHoursRange) GetMin() float64 {
// GetMax returns the max value. // GetMax returns the max value.
func (mhr MarketHoursRange) GetMax() float64 { func (mhr MarketHoursRange) GetMax() float64 {
return TimeToFloat64(mhr.Max) return TimeToFloat64(mhr.GetEffectiveMax())
}
// GetEffectiveMax gets either the close on the max, or the max itself.
func (mhr MarketHoursRange) GetEffectiveMax() time.Time {
maxClose := date.On(mhr.MarketClose, mhr.Max)
if maxClose.After(mhr.Max) {
return maxClose
}
return mhr.Max
} }
// SetMin sets the min value. // SetMin sets the min value.
@ -48,8 +57,8 @@ func (mhr *MarketHoursRange) SetMax(max float64) {
// GetDelta gets the delta. // GetDelta gets the delta.
func (mhr MarketHoursRange) GetDelta() float64 { func (mhr MarketHoursRange) GetDelta() float64 {
min := TimeToFloat64(mhr.Min) min := mhr.GetMin()
max := TimeToFloat64(mhr.Max) max := mhr.GetMax()
return max - min return max - min
} }
@ -109,7 +118,7 @@ func (mhr MarketHoursRange) String() string {
func (mhr MarketHoursRange) Translate(value float64) int { func (mhr MarketHoursRange) Translate(value float64) int {
valueTime := Float64ToTime(value) valueTime := Float64ToTime(value)
valueTimeEastern := valueTime.In(date.Eastern()) valueTimeEastern := valueTime.In(date.Eastern())
deltaSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.Max, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider) deltaSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.GetEffectiveMax(), mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTimeEastern, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider) valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTimeEastern, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain)) translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
return translated return translated