Skip to content

Commit

Permalink
Merge pull request #2 from dtoebe/fix-log
Browse files Browse the repository at this point in the history
change the logs to not be uppercase
  • Loading branch information
alpeb committed May 5, 2018
2 parents bef5098 + c58fe16 commit 55e2058
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions fin/bonds.go
Expand Up @@ -79,7 +79,7 @@ func TBillYield(settlement int64, maturity int64, price float64) (float64, error
}
dsm := float64(maturity-settlement) / float64(86400) // transform to days
if dsm > 360 {
return 0, errors.New("Maturity can't be more than one year after settlement")
return 0, errors.New("maturity can't be more than one year after settlement")
}
return (100 - price) * 360 / price / dsm, nil
}
Expand All @@ -95,11 +95,11 @@ func TBillYield(settlement int64, maturity int64, price float64) (float64, error
// Excel equivalent: TBILLPRICE
func TBillPrice(settlement int64, maturity int64, discount float64) (float64, error) {
if settlement >= maturity {
return 0, errors.New("Maturity must happen before settlement!")
return 0, errors.New("maturity must happen before settlement!")
}
dsm := float64(maturity-settlement) / float64(86400) // transform to days
if dsm > 360 {
return 0, errors.New("Maturity can't be more than one year after settlement")
return 0, errors.New("maturity can't be more than one year after settlement")
}
return 100 * (1 - discount*dsm/360), nil
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func TBillEquivalentYield(settlement int64, maturity int64, discount float64) (f
(mSettlement > 2 && isLeap(yMaturity))) {
return 2 * (math.Sqrt(1-discount*366/(discount*366-360)) - 1), nil
} else if dsm > 365 {
return 0, errors.New("Maturity can't be more than one year after settlement")
return 0, errors.New("maturity can't be more than one year after settlement")
}
return (-dsm + math.Sqrt(math.Pow(dsm, 2)-(2*dsm-365)*discount*dsm*365/(discount*dsm-360))) / (dsm - 365/2), nil
}
Expand Down
4 changes: 2 additions & 2 deletions fin/cashflow.go
Expand Up @@ -24,7 +24,7 @@ func NetPresentValue(rate float64, values []float64) float64 {
func InternalRateOfReturn(values []float64, guess float64) (float64, error) {
min, max := minMaxSlice(values)
if min*max >= 0 {
return 0, errors.New("The cash flow must contain at least one positive value and one negative value")
return 0, errors.New("the cash flow must contain at least one positive value and one negative value")
}

function := func(rate float64) float64 {
Expand Down Expand Up @@ -55,7 +55,7 @@ func dNetPresentValue(rate float64, values []float64) float64 {
func ModifiedInternalRateOfReturn(values []float64, financeRate float64, reinvestRate float64) (float64, error) {
min, max := minMaxSlice(values)
if min*max >= 0 {
return 0, errors.New("The cash flow must contain at least one positive value and one negative value")
return 0, errors.New("the cash flow must contain at least one positive value and one negative value")
}
positiveFlows := make([]float64, 0)
negativeFlows := make([]float64, 0)
Expand Down
2 changes: 1 addition & 1 deletion fin/newton.go
Expand Up @@ -17,7 +17,7 @@ func newton(guess float64, function func(float64) float64, derivative func(float
if math.Abs(x-guess) < Precision {
return x, nil
} else if numIt >= MaxIterations {
return 0, errors.New("Solution didn't converge")
return 0, errors.New("solution didn't converge")
} else {
return newton(x, function, derivative, numIt+1)
}
Expand Down
2 changes: 1 addition & 1 deletion fin/rates.go
Expand Up @@ -20,7 +20,7 @@ func EffectiveRate(nominal float64, numPeriods int) (float64, error) {
// Excel equivalent: NOMINAL
func NominalRate(effectiveRate float64, numPeriods int) (float64, error) {
if numPeriods < 0 {
return 0, errors.New("Number of compounding payments per year must be strictly positive")
return 0, errors.New("number of compounding payments per year must be strictly positive")
}
return float64(numPeriods) * (math.Pow(effectiveRate+1, 1/float64(numPeriods)) - 1), nil
}
24 changes: 12 additions & 12 deletions fin/tvm.go
Expand Up @@ -16,10 +16,10 @@ const (
// Excel equivalent: PV
func PresentValue(rate float64, numPeriods int, pmt float64, fv float64, paymentType int) (pv float64, err error) {
if numPeriods < 0 {
return 0, errors.New("Number of periods must be positive")
return 0, errors.New("number of periods must be positive")
}
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
if rate != 0 {
pv = (-pmt*(1+rate*float64(paymentType))*((math.Pow(1+rate, float64(numPeriods))-1)/rate) - fv) / math.Pow(1+rate, float64(numPeriods))
Expand All @@ -34,10 +34,10 @@ func PresentValue(rate float64, numPeriods int, pmt float64, fv float64, payment
// Excel equivalent: FV
func FutureValue(rate float64, numPeriods int, pmt float64, pv float64, paymentType int) (fv float64, err error) {
if numPeriods < 0 {
return 0, errors.New("Number of periods must be positive")
return 0, errors.New("number of periods must be positive")
}
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
if rate != 0 {
fv = -pv*math.Pow(1+rate, float64(numPeriods)) - pmt*(1+rate*float64(paymentType))*(math.Pow(1+rate, float64(numPeriods))-1)/rate
Expand All @@ -52,10 +52,10 @@ func FutureValue(rate float64, numPeriods int, pmt float64, pv float64, paymentT
// Excel equivalent: PMT
func Payment(rate float64, numPeriods int, pv float64, fv float64, paymentType int) (pmt float64, err error) {
if numPeriods < 0 {
return 0, errors.New("Number of periods must be positive")
return 0, errors.New("number of periods must be positive")
}
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
if rate != 0 {
pmt = (-fv - pv*math.Pow(1+rate, float64(numPeriods))) / (1 + rate*float64(paymentType)) / ((math.Pow(1+rate, float64(numPeriods)) - 1) / rate)
Expand All @@ -70,16 +70,16 @@ func Payment(rate float64, numPeriods int, pv float64, fv float64, paymentType i
// Excel equivalent: NPER
func Periods(rate float64, pmt float64, pv float64, fv float64, paymentType int) (numPeriods float64, err error) {
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
if rate != 0 {
if pmt == 0 && pv == 0 {
return 0, errors.New("Payment and Present Value can't be both zero when the rate is not zero")
return 0, errors.New("payment and present value can't be both zero when the rate is not zero")
}
numPeriods = math.Log((pmt*(1+rate*float64(paymentType))/rate-fv)/(pv+pmt*(1+rate*float64(paymentType))/rate)) / math.Log(1+rate)
} else {
if pmt == 0 {
return 0, errors.New("Rate and Payment can't be both zero")
return 0, errors.New("pate and payment can't be both zero")
}
numPeriods = (-pv - fv) / pmt
}
Expand All @@ -92,7 +92,7 @@ func Periods(rate float64, pmt float64, pv float64, fv float64, paymentType int)
// Excel equivalent: RATE
func Rate(numPeriods int, pmt float64, pv float64, fv float64, paymentType int, guess float64) (float64, error) {
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
function := func(rate float64) float64 {
return f(rate, numPeriods, pmt, pv, fv, paymentType)
Expand All @@ -119,7 +119,7 @@ func df(rate float64, numPeriods int, pmt float64, pv float64, fv float64, payme
// Excel equivalent: IMPT
func InterestPayment(rate float64, period int, numPeriods int, pv float64, fv float64, paymentType int) (float64, error) {
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
interest, _, err := interestAndPrincipal(rate, period, numPeriods, pv, fv, paymentType)
if err != nil {
Expand All @@ -133,7 +133,7 @@ func InterestPayment(rate float64, period int, numPeriods int, pv float64, fv fl
// Excel equivalent: PPMT
func PrincipalPayment(rate float64, period int, numPeriods int, pv float64, fv float64, paymentType int) (float64, error) {
if paymentType != PayEnd && paymentType != PayBegin {
return 0, errors.New("Payment type must be PayEnd or PayBegin")
return 0, errors.New("payment type must be pay-end or pay-begin")
}
_, principal, err := interestAndPrincipal(rate, period, numPeriods, pv, fv, paymentType)
if err != nil {
Expand Down

0 comments on commit 55e2058

Please sign in to comment.