Skip to content

Commit

Permalink
GoLand inspect issues fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Dec 24, 2024
1 parent cf5415f commit a0b8abe
Show file tree
Hide file tree
Showing 76 changed files with 264 additions and 240 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ indicator-sync

# Go workspace file
go.work

# GoLand project
.idea

12 changes: 6 additions & 6 deletions asset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ RegisterRepositoryBuilder registers the given builder.
func SnapshotsAsClosings(snapshots <-chan *Snapshot) <-chan float64
```

SnapshotsAsClosings extracts the close field from each snapshot in the provided channel and returns a new channel containing only those close values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsClosings extracts the close field from each snapshot in the provided channel and returns a new channel containing only those close values.The original snapshots channel can no longer be directly used afterward.

<a name="SnapshotsAsDates"></a>
## func [SnapshotsAsDates](<https://github.com/cinar/indicator/blob/master/asset/snapshot.go#L43>)
Expand All @@ -134,7 +134,7 @@ SnapshotsAsClosings extracts the close field from each snapshot in the provided
func SnapshotsAsDates(snapshots <-chan *Snapshot) <-chan time.Time
```

SnapshotsAsDates extracts the date field from each snapshot in the provided channel and returns a new channel containing only those date values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsDates extracts the date field from each snapshot in the provided channel and returns a new channel containing only those date values.The original snapshots channel can no longer be directly used afterward.

<a name="SnapshotsAsHighs"></a>
## func [SnapshotsAsHighs](<https://github.com/cinar/indicator/blob/master/asset/snapshot.go#L61>)
Expand All @@ -143,7 +143,7 @@ SnapshotsAsDates extracts the date field from each snapshot in the provided chan
func SnapshotsAsHighs(snapshots <-chan *Snapshot) <-chan float64
```

SnapshotsAsHighs extracts the high field from each snapshot in the provided channel and returns a new channel containing only those high values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsHighs extracts the high field from each snapshot in the provided channel and returns a new channel containing only those high values.The original snapshots channel can no longer be directly used afterward.

<a name="SnapshotsAsLows"></a>
## func [SnapshotsAsLows](<https://github.com/cinar/indicator/blob/master/asset/snapshot.go#L70>)
Expand All @@ -152,7 +152,7 @@ SnapshotsAsHighs extracts the high field from each snapshot in the provided chan
func SnapshotsAsLows(snapshots <-chan *Snapshot) <-chan float64
```

SnapshotsAsLows extracts the low field from each snapshot in the provided channel and returns a new channel containing only those low values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsLows extracts the low field from each snapshot in the provided channel and returns a new channel containing only those low values.The original snapshots channel can no longer be directly used afterward.

<a name="SnapshotsAsOpenings"></a>
## func [SnapshotsAsOpenings](<https://github.com/cinar/indicator/blob/master/asset/snapshot.go#L52>)
Expand All @@ -161,7 +161,7 @@ SnapshotsAsLows extracts the low field from each snapshot in the provided channe
func SnapshotsAsOpenings(snapshots <-chan *Snapshot) <-chan float64
```

SnapshotsAsOpenings extracts the open field from each snapshot in the provided channel and returns a new channel containing only those open values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsOpenings extracts the open field from each snapshot in the provided channel and returns a new channel containing only those open values.The original snapshots channel can no longer be directly used afterward.

<a name="SnapshotsAsVolumes"></a>
## func [SnapshotsAsVolumes](<https://github.com/cinar/indicator/blob/master/asset/snapshot.go#L88>)
Expand All @@ -170,7 +170,7 @@ SnapshotsAsOpenings extracts the open field from each snapshot in the provided c
func SnapshotsAsVolumes(snapshots <-chan *Snapshot) <-chan float64
```

SnapshotsAsVolumes extracts the volume field from each snapshot in the provided channel and returns a new channel containing only those volume values.The original snapshots channel can no longer be directly used afterwards.
SnapshotsAsVolumes extracts the volume field from each snapshot in the provided channel and returns a new channel containing only those volume values.The original snapshots channel can no longer be directly used afterward.

<a name="FileSystemRepository"></a>
## type [FileSystemRepository](<https://github.com/cinar/indicator/blob/master/asset/file_system_repository.go#L20-L23>)
Expand Down
3 changes: 1 addition & 2 deletions asset/file_system_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package asset_test

import (
"fmt"
"os"
"path"
"reflect"
"testing"
Expand Down Expand Up @@ -133,7 +132,7 @@ func TestFileSystemRepositoryAppend(t *testing.T) {
}

name := "test_file_system_repository_append"
defer os.Remove(path.Join(repositoryBase, fmt.Sprintf("%s.csv", name)))
defer helper.Remove(t, path.Join(repositoryBase, fmt.Sprintf("%s.csv", name)))

err = repository.Append(name, expected)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions asset/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Snapshot struct {

// SnapshotsAsDates extracts the date field from each snapshot in the provided
// channel and returns a new channel containing only those date values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsDates(snapshots <-chan *Snapshot) <-chan time.Time {
return helper.Map(snapshots, func(snapshot *Snapshot) time.Time {
return snapshot.Date
Expand All @@ -48,7 +48,7 @@ func SnapshotsAsDates(snapshots <-chan *Snapshot) <-chan time.Time {

// SnapshotsAsOpenings extracts the open field from each snapshot in the provided
// channel and returns a new channel containing only those open values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsOpenings(snapshots <-chan *Snapshot) <-chan float64 {
return helper.Map(snapshots, func(snapshot *Snapshot) float64 {
return snapshot.Open
Expand All @@ -57,7 +57,7 @@ func SnapshotsAsOpenings(snapshots <-chan *Snapshot) <-chan float64 {

// SnapshotsAsHighs extracts the high field from each snapshot in the provided
// channel and returns a new channel containing only those high values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsHighs(snapshots <-chan *Snapshot) <-chan float64 {
return helper.Map(snapshots, func(snapshot *Snapshot) float64 {
return snapshot.High
Expand All @@ -66,7 +66,7 @@ func SnapshotsAsHighs(snapshots <-chan *Snapshot) <-chan float64 {

// SnapshotsAsLows extracts the low field from each snapshot in the provided
// channel and returns a new channel containing only those low values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsLows(snapshots <-chan *Snapshot) <-chan float64 {
return helper.Map(snapshots, func(snapshot *Snapshot) float64 {
return snapshot.Low
Expand All @@ -75,7 +75,7 @@ func SnapshotsAsLows(snapshots <-chan *Snapshot) <-chan float64 {

// SnapshotsAsClosings extracts the close field from each snapshot in the provided
// channel and returns a new channel containing only those close values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsClosings(snapshots <-chan *Snapshot) <-chan float64 {
return helper.Map(snapshots, func(snapshot *Snapshot) float64 {
return snapshot.Close
Expand All @@ -84,7 +84,7 @@ func SnapshotsAsClosings(snapshots <-chan *Snapshot) <-chan float64 {

// SnapshotsAsVolumes extracts the volume field from each snapshot in the provided
// channel and returns a new channel containing only those volume values.The
// original snapshots channel can no longer be directly used afterwards.
// original snapshots channel can no longer be directly used afterward.
func SnapshotsAsVolumes(snapshots <-chan *Snapshot) <-chan float64 {
return helper.Map(snapshots, func(snapshot *Snapshot) float64 {
return snapshot.Volume
Expand Down
9 changes: 6 additions & 3 deletions asset/tiingo_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestTiingoRepositoryAssets(t *testing.T) {
repository := asset.NewTiingoRepository("1234")

_, err := repository.Assets()
if err != errors.ErrUnsupported {
if !errors.Is(err, errors.ErrUnsupported) {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -80,7 +80,10 @@ func TestTiingoRepositoryGetInvalid(t *testing.T) {
response := ""

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, response)
_, err := fmt.Fprint(w, response)
if err != nil {
t.Fatal(err)
}
}))

repository := asset.NewTiingoRepository("1234")
Expand Down Expand Up @@ -175,7 +178,7 @@ func TestTiingoRepositoryAppend(t *testing.T) {
repository := asset.NewTiingoRepository("1234")

err := repository.Append("A", nil)
if err != errors.ErrUnsupported {
if !errors.Is(err, errors.ErrUnsupported) {
t.Fatal(err)
}
}
27 changes: 14 additions & 13 deletions backtest/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package backtest_test

import (
"github.com/cinar/indicator/v2/helper"
"os"
"testing"

Expand All @@ -16,19 +17,19 @@ import (
func TestBacktest(t *testing.T) {
repository := asset.NewFileSystemRepository("testdata/repository")

outputDir, err := os.MkdirTemp("", "backtest")
outputDir, err := os.MkdirTemp("", "bt")
if err != nil {
t.Fatal(err)
}

defer os.RemoveAll(outputDir)
defer helper.RemoveAll(t, outputDir)

htmlReport := backtest.NewHTMLReport(outputDir)
backtest := backtest.NewBacktest(repository, htmlReport)
backtest.Names = append(backtest.Names, "brk-b")
backtest.Strategies = append(backtest.Strategies, trend.NewApoStrategy())
bt := backtest.NewBacktest(repository, htmlReport)
bt.Names = append(bt.Names, "brk-b")
bt.Strategies = append(bt.Strategies, trend.NewApoStrategy())

err = backtest.Run()
err = bt.Run()
if err != nil {
t.Fatal(err)
}
Expand All @@ -42,12 +43,12 @@ func TestBacktestAllAssetsAndStrategies(t *testing.T) {
t.Fatal(err)
}

defer os.RemoveAll(outputDir)
defer helper.RemoveAll(t, outputDir)

htmlReport := backtest.NewHTMLReport(outputDir)
backtest := backtest.NewBacktest(repository, htmlReport)
bt := backtest.NewBacktest(repository, htmlReport)

err = backtest.Run()
err = bt.Run()
if err != nil {
t.Fatal(err)
}
Expand All @@ -61,13 +62,13 @@ func TestBacktestNonExistingAsset(t *testing.T) {
t.Fatal(err)
}

defer os.RemoveAll(outputDir)
defer helper.RemoveAll(t, outputDir)

htmlReport := backtest.NewHTMLReport(outputDir)
backtest := backtest.NewBacktest(repository, htmlReport)
backtest.Names = append(backtest.Names, "non_existing")
bt := backtest.NewBacktest(repository, htmlReport)
bt.Names = append(bt.Names, "non_existing")

err = backtest.Run()
err = bt.Run()
if err != nil {
t.Fatal(err)
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/indicator-backtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main

import (
"flag"
"fmt"
"log"
"log/slog"
"os"

Expand All @@ -31,11 +31,12 @@ func main() {
var addSplits bool
var addAnds bool

fmt.Fprintln(os.Stderr, "Indicator Backtest")
fmt.Fprintln(os.Stderr, "Copyright (c) 2021-2024 Onur Cinar.")
fmt.Fprintln(os.Stderr, "The source code is provided under GNU AGPLv3 License.")
fmt.Fprintln(os.Stderr, "https://github.com/cinar/indicator")
fmt.Fprintln(os.Stderr)
stdErr := log.New(os.Stderr, "", 0)
stdErr.Println("Indicator Backtest")
stdErr.Println("Copyright (c) 2021-2024 Onur Cinar.")
stdErr.Println("The source code is provided under GNU AGPLv3 License.")
stdErr.Println("https://github.com/cinar/indicator")
stdErr.Println()

flag.StringVar(&repositoryName, "repository-name", "filesystem", "repository name")
flag.StringVar(&repositoryConfig, "repository-config", "", "repository config")
Expand Down
13 changes: 7 additions & 6 deletions cmd/indicator-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main

import (
"flag"
"fmt"
"log"
"log/slog"
"os"
"time"
Expand All @@ -24,11 +24,12 @@ func main() {
var workers int
var delay int

fmt.Fprintln(os.Stderr, "Indicator Sync")
fmt.Fprintln(os.Stderr, "Copyright (c) 2021-2024 Onur Cinar.")
fmt.Fprintln(os.Stderr, "The source code is provided under GNU AGPLv3 License.")
fmt.Fprintln(os.Stderr, "https://github.com/cinar/indicator")
fmt.Fprintln(os.Stderr)
stdErr := log.New(os.Stderr, "", 0)
stdErr.Println("Indicator Sync")
stdErr.Println("Copyright (c) 2021-2024 Onur Cinar.")
stdErr.Println("The source code is provided under GNU AGPLv3 License.")
stdErr.Println("https://github.com/cinar/indicator")
stdErr.Println()

flag.StringVar(&sourceName, "source-name", "tiingo", "source repository type")
flag.StringVar(&sourceConfig, "source-config", "", "source repository config")
Expand Down
22 changes: 21 additions & 1 deletion helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ The information provided on this project is strictly for informational purposes
- [func Pipe\[T any\]\(f \<\-chan T, t chan\<\- T\)](<#Pipe>)
- [func Pow\[T Number\]\(c \<\-chan T, y T\) \<\-chan T](<#Pow>)
- [func ReadFromCsvFile\[T any\]\(fileName string, hasHeader bool\) \(\<\-chan \*T, error\)](<#ReadFromCsvFile>)
- [func Remove\(t \*testing.T, name string\)](<#Remove>)
- [func RemoveAll\(t \*testing.T, path string\)](<#RemoveAll>)
- [func RoundDigit\[T Number\]\(n T, d int\) T](<#RoundDigit>)
- [func RoundDigits\[T Number\]\(c \<\-chan T, d int\) \<\-chan T](<#RoundDigits>)
- [func Seq\[T Number\]\(from, to, increment T\) \<\-chan T](<#Seq>)
Expand Down Expand Up @@ -791,6 +793,24 @@ func ReadFromCsvFile[T any](fileName string, hasHeader bool) (<-chan *T, error)

ReadFromCsvFile creates a CSV instance, parses CSV data from the provided filename, maps the data to corresponding struct fields, and delivers it through the channel.

<a name="Remove"></a>
## func [Remove](<https://github.com/cinar/indicator/blob/master/helper/remove.go#L13>)

```go
func Remove(t *testing.T, name string)
```

Remove removes the file with the given name.

<a name="RemoveAll"></a>
## func [RemoveAll](<https://github.com/cinar/indicator/blob/master/helper/remove.go#L21>)

```go
func RemoveAll(t *testing.T, path string)
```

RemoveAll removes the files with the given path.

<a name="RoundDigit"></a>
## func [RoundDigit](<https://github.com/cinar/indicator/blob/master/helper/round_digit.go#L15>)

Expand Down Expand Up @@ -1237,7 +1257,7 @@ type ReportColumn interface {
func NewAnnotationReportColumn(values <-chan string) ReportColumn
```

NewAnnotationReportColumn returns a new instance of a annotation column for a report.
NewAnnotationReportColumn returns a new instance of an annotation column for a report.

<a name="NewNumericReportColumn"></a>
### func [NewNumericReportColumn](<https://github.com/cinar/indicator/blob/master/helper/numeric_report_column.go#L17>)
Expand Down
2 changes: 1 addition & 1 deletion helper/annotation_report_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type annotationReportColumn struct {
values <-chan string
}

// NewAnnotationReportColumn returns a new instance of a annotation column for a report.
// NewAnnotationReportColumn returns a new instance of an annotation column for a report.
func NewAnnotationReportColumn(values <-chan string) ReportColumn {
return &annotationReportColumn{
values: values,
Expand Down
18 changes: 9 additions & 9 deletions helper/bst.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (b *Bst[T]) Min() T {
return T(0)
}

node, _ := minNode(b.root)
node, _ := getMinNode(b.root)
return node.value
}

Expand All @@ -87,7 +87,7 @@ func (b *Bst[T]) Max() T {
return T(0)
}

node, _ := maxNode(b.root)
node, _ := getMaxNode(b.root)
return node.value
}

Expand Down Expand Up @@ -118,13 +118,13 @@ func (b *Bst[T]) searchNode(value T) (*BstNode[T], *BstNode[T]) {
// and rebalances the tree.
func (b *Bst[T]) removeNode(node, parent *BstNode[T]) {
if node.left != nil && node.right != nil {
min, minParent := minNode(node.right)
minNode, minParent := getMinNode(node.right)
if minParent == nil {
minParent = node
}

b.removeNode(min, minParent)
node.value = min.value
b.removeNode(minNode, minParent)
node.value = minNode.value
} else {
var child *BstNode[T]

Expand All @@ -144,8 +144,8 @@ func (b *Bst[T]) removeNode(node, parent *BstNode[T]) {
}
}

// minNode functions returns the node with the minimum value and its parent node.
func minNode[T Number](root *BstNode[T]) (*BstNode[T], *BstNode[T]) {
// getMinNode functions returns the node with the minimum value and its parent node.
func getMinNode[T Number](root *BstNode[T]) (*BstNode[T], *BstNode[T]) {
var parent *BstNode[T]
node := root

Expand All @@ -157,8 +157,8 @@ func minNode[T Number](root *BstNode[T]) (*BstNode[T], *BstNode[T]) {
return node, parent
}

// maxNode functions returns the node with the maximum value and its parent node.
func maxNode[T Number](root *BstNode[T]) (*BstNode[T], *BstNode[T]) {
// getMaxNode functions returns the node with the maximum value and its parent node.
func getMaxNode[T Number](root *BstNode[T]) (*BstNode[T], *BstNode[T]) {
var parent *BstNode[T]
node := root

Expand Down
Loading

0 comments on commit a0b8abe

Please sign in to comment.