Skip to content

Commit

Permalink
Fixing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Dec 29, 2023
1 parent 6425038 commit 9704d06
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 30 deletions.
12 changes: 6 additions & 6 deletions asset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ The information provided on this project is strictly for informational purposes
- [type TiingoMeta](<#TiingoMeta>)
- [type TiingoRepository](<#TiingoRepository>)
- [func NewTiingoRepository\(apiKey string\) \*TiingoRepository](<#NewTiingoRepository>)
- [func \(r \*TiingoRepository\) Append\(\_ string, \_ \<\-chan \*Snapshot\) error](<#TiingoRepository.Append>)
- [func \(r \*TiingoRepository\) Assets\(\) \(\[\]string, error\)](<#TiingoRepository.Assets>)
- [func \(\*TiingoRepository\) Append\(\_ string, \_ \<\-chan \*Snapshot\) error](<#TiingoRepository.Append>)
- [func \(\*TiingoRepository\) Assets\(\) \(\[\]string, error\)](<#TiingoRepository.Assets>)
- [func \(r \*TiingoRepository\) Get\(name string\) \(\<\-chan \*Snapshot, error\)](<#TiingoRepository.Get>)
- [func \(r \*TiingoRepository\) GetSince\(name string, date time.Time\) \(\<\-chan \*Snapshot, error\)](<#TiingoRepository.GetSince>)
- [func \(r \*TiingoRepository\) LastDate\(name string\) \(time.Time, error\)](<#TiingoRepository.LastDate>)
Expand Down Expand Up @@ -423,10 +423,10 @@ func NewTiingoRepository(apiKey string) *TiingoRepository
NewTiingoRepository initializes a file system repository with the given API key.

<a name="TiingoRepository.Append"></a>
### func \(\*TiingoRepository\) [Append](<https://github.com/cinar/indicator/blob/v2/asset/tiingo_repository.go#L219>)
### func \(\*TiingoRepository\) [Append](<https://github.com/cinar/indicator/blob/v2/asset/tiingo_repository.go#L226>)

```go
func (r *TiingoRepository) Append(_ string, _ <-chan *Snapshot) error
func (*TiingoRepository) Append(_ string, _ <-chan *Snapshot) error
```

Append adds the given snapshows to the asset with the given name.
Expand All @@ -435,7 +435,7 @@ Append adds the given snapshows to the asset with the given name.
### func \(\*TiingoRepository\) [Assets](<https://github.com/cinar/indicator/blob/v2/asset/tiingo_repository.go#L122>)

```go
func (r *TiingoRepository) Assets() ([]string, error)
func (*TiingoRepository) Assets() ([]string, error)
```

Assets returns the names of all assets in the repository.
Expand All @@ -459,7 +459,7 @@ func (r *TiingoRepository) GetSince(name string, date time.Time) (<-chan *Snapsh
GetSince attempts to return a channel of snapshots for the asset with the given name since the given date.

<a name="TiingoRepository.LastDate"></a>
### func \(\*TiingoRepository\) [LastDate](<https://github.com/cinar/indicator/blob/v2/asset/tiingo_repository.go#L186>)
### func \(\*TiingoRepository\) [LastDate](<https://github.com/cinar/indicator/blob/v2/asset/tiingo_repository.go#L190>)

```go
func (r *TiingoRepository) LastDate(name string) (time.Time, error)
Expand Down
17 changes: 12 additions & 5 deletions asset/tiingo_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func NewTiingoRepository(apiKey string) *TiingoRepository {
}

// Assets returns the names of all assets in the repository.
func (r *TiingoRepository) Assets() ([]string, error) {
func (*TiingoRepository) Assets() ([]string, error) {
return nil, errors.ErrUnsupported
}

Expand Down Expand Up @@ -149,7 +149,6 @@ func (r *TiingoRepository) GetSince(name string, date time.Time) (<-chan *Snapsh
snapshots := make(chan *Snapshot)

go func() {
defer res.Body.Close()
defer close(snapshots)

decoder := json.NewDecoder(res.Body)
Expand Down Expand Up @@ -177,6 +176,11 @@ func (r *TiingoRepository) GetSince(name string, date time.Time) (<-chan *Snapsh
log.Printf("GetSince failed with %v", err)
return
}

err = res.Body.Close()
if err != nil {
log.Print(err)
}
}()

return snapshots, nil
Expand All @@ -198,13 +202,16 @@ func (r *TiingoRepository) LastDate(name string) (time.Time, error) {
return lastDate, err
}

defer res.Body.Close()

body, err := io.ReadAll(res.Body)
if err != nil {
return lastDate, err
}

err = res.Body.Close()
if err != nil {
return lastDate, err
}

var meta TiingoMeta

err = json.Unmarshal(body, &meta)
Expand All @@ -216,6 +223,6 @@ func (r *TiingoRepository) LastDate(name string) (time.Time, error) {
}

// Append adds the given snapshows to the asset with the given name.
func (r *TiingoRepository) Append(_ string, _ <-chan *Snapshot) error {
func (*TiingoRepository) Append(_ string, _ <-chan *Snapshot) error {
return errors.ErrUnsupported
}
20 changes: 10 additions & 10 deletions strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ The information provided on this project is strictly for informational purposes
- [type ApoStrategy](<#ApoStrategy>)
- [func NewApoStrategy\(\) \*ApoStrategy](<#NewApoStrategy>)
- [func \(a \*ApoStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan Action](<#ApoStrategy.Compute>)
- [func \(a \*ApoStrategy\) Name\(\) string](<#ApoStrategy.Name>)
- [func \(\*ApoStrategy\) Name\(\) string](<#ApoStrategy.Name>)
- [func \(a \*ApoStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#ApoStrategy.Report>)
- [type AroonStrategy](<#AroonStrategy>)
- [func NewAroonStrategy\(\) \*AroonStrategy](<#NewAroonStrategy>)
- [func \(a \*AroonStrategy\) Compute\(c \<\-chan \*asset.Snapshot\) \<\-chan Action](<#AroonStrategy.Compute>)
- [func \(a \*AroonStrategy\) Name\(\) string](<#AroonStrategy.Name>)
- [func \(\*AroonStrategy\) Name\(\) string](<#AroonStrategy.Name>)
- [func \(a \*AroonStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#AroonStrategy.Report>)
- [type Backtest](<#Backtest>)
- [func NewBacktest\(repository asset.Repository, outputDir string\) \*Backtest](<#NewBacktest>)
Expand All @@ -53,8 +53,8 @@ The information provided on this project is strictly for informational purposes
- [func \(b \*BopStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#BopStrategy.Report>)
- [type BuyAndHoldStrategy](<#BuyAndHoldStrategy>)
- [func NewBuyAndHoldStrategy\(\) \*BuyAndHoldStrategy](<#NewBuyAndHoldStrategy>)
- [func \(b \*BuyAndHoldStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan Action](<#BuyAndHoldStrategy.Compute>)
- [func \(b \*BuyAndHoldStrategy\) Name\(\) string](<#BuyAndHoldStrategy.Name>)
- [func \(\*BuyAndHoldStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan Action](<#BuyAndHoldStrategy.Compute>)
- [func \(\*BuyAndHoldStrategy\) Name\(\) string](<#BuyAndHoldStrategy.Name>)
- [func \(b \*BuyAndHoldStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#BuyAndHoldStrategy.Report>)
- [type DemaStrategy](<#DemaStrategy>)
- [func NewDemaStrategy\(\) \*DemaStrategy](<#NewDemaStrategy>)
Expand All @@ -74,7 +74,7 @@ The information provided on this project is strictly for informational purposes
- [type QstickStrategy](<#QstickStrategy>)
- [func NewQstickStrategy\(\) \*QstickStrategy](<#NewQstickStrategy>)
- [func \(q \*QstickStrategy\) Compute\(c \<\-chan \*asset.Snapshot\) \<\-chan Action](<#QstickStrategy.Compute>)
- [func \(q \*QstickStrategy\) Name\(\) string](<#QstickStrategy.Name>)
- [func \(\*QstickStrategy\) Name\(\) string](<#QstickStrategy.Name>)
- [func \(q \*QstickStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#QstickStrategy.Report>)
- [type Result](<#Result>)
- [type Strategy](<#Strategy>)
Expand Down Expand Up @@ -252,7 +252,7 @@ Compute processes the provided asset snapshots and generates a stream of actiona
### func \(\*ApoStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/apo_strategy.go#L31>)

```go
func (a *ApoStrategy) Name() string
func (*ApoStrategy) Name() string
```

Name returns the name of the strategy.
Expand Down Expand Up @@ -302,7 +302,7 @@ Compute processes the provided asset snapshots and generates a stream of actiona
### func \(\*AroonStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/aroon_strategy.go#L35>)

```go
func (a *AroonStrategy) Name() string
func (*AroonStrategy) Name() string
```

Name returns the name of the strategy.
Expand Down Expand Up @@ -429,7 +429,7 @@ NewBuyAndHoldStrategy function initializes a new buy and hold strategy instance.
### func \(\*BuyAndHoldStrategy\) [Compute](<https://github.com/cinar/indicator/blob/v2/strategy/buy_and_hold_strategy.go#L32>)

```go
func (b *BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
func (*BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action
```

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.
Expand All @@ -438,7 +438,7 @@ Compute processes the provided asset snapshots and generates a stream of actiona
### func \(\*BuyAndHoldStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/buy_and_hold_strategy.go#L26>)

```go
func (b *BuyAndHoldStrategy) Name() string
func (*BuyAndHoldStrategy) Name() string
```

Name returns the name of the strategy.
Expand Down Expand Up @@ -646,7 +646,7 @@ Compute processes the provided asset snapshots and generates a stream of actiona
### func \(\*QstickStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/qstick_strategy.go#L35>)

```go
func (q *QstickStrategy) Name() string
func (*QstickStrategy) Name() string
```

Name returns the name of the strategy.
Expand Down
2 changes: 1 addition & 1 deletion strategy/apo_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewApoStrategy() *ApoStrategy {
}

// Name returns the name of the strategy.
func (a *ApoStrategy) Name() string {
func (*ApoStrategy) Name() string {
return "Apo Strategy"
}

Expand Down
2 changes: 1 addition & 1 deletion strategy/aroon_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewAroonStrategy() *AroonStrategy {
}

// Name returns the name of the strategy.
func (a *AroonStrategy) Name() string {
func (*AroonStrategy) Name() string {
return "Aroon Strategy"
}

Expand Down
2 changes: 1 addition & 1 deletion strategy/backtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (b *Backtest) Run() error {
}

// allStrategies returns a slice containing references to all available strategies.
func (b *Backtest) allStrategies() []Strategy {
func (*Backtest) allStrategies() []Strategy {
return []Strategy{
NewApoStrategy(),
NewAroonStrategy(),
Expand Down
4 changes: 2 additions & 2 deletions strategy/buy_and_hold_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func NewBuyAndHoldStrategy() *BuyAndHoldStrategy {
}

// Name returns the name of the strategy.
func (b *BuyAndHoldStrategy) Name() string {
func (*BuyAndHoldStrategy) Name() string {
return "Buy and Hold Strategy"
}

// Compute processes the provided asset snapshots and generates a
// stream of actionable recommendations.
func (b *BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action {
func (*BuyAndHoldStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan Action {
closings := asset.SnapshotsAsClosings(snapshots)
actions := make(chan Action, cap(snapshots))

Expand Down
2 changes: 1 addition & 1 deletion strategy/qstick_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewQstickStrategy() *QstickStrategy {
}

// Name returns the name of the strategy.
func (q *QstickStrategy) Name() string {
func (*QstickStrategy) Name() string {
return "Qstick Strategy"
}

Expand Down
4 changes: 2 additions & 2 deletions trend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The information provided on this project is strictly for informational purposes
- [func \(t \*Trima\[T\]\) IdlePeriod\(\) int](<#Trima[T].IdlePeriod>)
- [type TypicalPrice](<#TypicalPrice>)
- [func NewTypicalPrice\[T helper.Number\]\(\) \*TypicalPrice\[T\]](<#NewTypicalPrice>)
- [func \(t \*TypicalPrice\[T\]\) Compute\(high, low, closing \<\-chan T\) \<\-chan T](<#TypicalPrice[T].Compute>)
- [func \(\*TypicalPrice\[T\]\) Compute\(high, low, closing \<\-chan T\) \<\-chan T](<#TypicalPrice[T].Compute>)
- [type Vwma](<#Vwma>)
- [func NewVwma\[T helper.Number\]\(\) \*Vwma\[T\]](<#NewVwma>)
- [func \(v \*Vwma\[T\]\) Compute\(closing, volume \<\-chan T\) \<\-chan T](<#Vwma[T].Compute>)
Expand Down Expand Up @@ -849,7 +849,7 @@ NewTypicalPrice function initializes a new Typical Price instance with the defau
### func \(\*TypicalPrice\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/v2/trend/typical_price.go#L25>)

```go
func (t *TypicalPrice[T]) Compute(high, low, closing <-chan T) <-chan T
func (*TypicalPrice[T]) Compute(high, low, closing <-chan T) <-chan T
```

Compute function takes a channel of numbers and computes the Typical Price and the signal line.
Expand Down
2 changes: 1 addition & 1 deletion trend/typical_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewTypicalPrice[T helper.Number]() *TypicalPrice[T] {
}

// Compute function takes a channel of numbers and computes the Typical Price and the signal line.
func (t *TypicalPrice[T]) Compute(high, low, closing <-chan T) <-chan T {
func (*TypicalPrice[T]) Compute(high, low, closing <-chan T) <-chan T {
return helper.DivideBy(
helper.Add(
helper.Add(high, low),
Expand Down

0 comments on commit 9704d06

Please sign in to comment.