Skip to content

Commit

Permalink
TRIMA, VWMA, Typical Price.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Dec 29, 2023
1 parent ad31b06 commit 6425038
Show file tree
Hide file tree
Showing 20 changed files with 2,474 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ The following list of indicators are currently supported by this package:
- [Simple Moving Average (SMA)](trend/README.md#type-sma)
- [Since Change](helper/README.md#func-since)
- [Triple Exponential Moving Average (TEMA)](trend/README.md#type-tema)
- Triangular Moving Average (TRIMA)
- [Triangular Moving Average (TRIMA)](trend/README.md#type-trima)
- Triple Exponential Average (TRIX)
- Typical Price
- Volume Weighted Moving Average (VWMA)
- [Typical Price](trend/README.md#type-typicalprice)
- [Volume Weighted Moving Average (VWMA)](trend/README.md#type-vwma)
- Vortex Indicator

### Momentum Indicators
Expand Down Expand Up @@ -109,7 +109,8 @@ The following list of strategies are currently supported by this package:
- [Random Index (KDJ) Strategy](strategy/README.md#type-kdjstrategy)
- [Moving Average Convergence Divergence (MACD) Strategy](strategy/README.md#type-macdstrategy)
- [Qstick Strategy](strategy/README.md#type-qstickstrategy)
- Volume Weighted Moving Average (VWMA) Strategy
- [Triangular Moving Average (TRIMA) Strategy](strategy/README.md#type-trimastrategy)
- [Volume Weighted Moving Average (VWMA) Strategy](strategy/README.md#type-vwmastrategy)

### Momentum Strategies

Expand Down
137 changes: 137 additions & 0 deletions strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ The information provided on this project is strictly for informational purposes
- [func \(q \*QstickStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#QstickStrategy.Report>)
- [type Result](<#Result>)
- [type Strategy](<#Strategy>)
- [type TrimaStrategy](<#TrimaStrategy>)
- [func NewTrimaStrategy\(\) \*TrimaStrategy](<#NewTrimaStrategy>)
- [func \(t \*TrimaStrategy\) Compute\(c \<\-chan \*asset.Snapshot\) \<\-chan Action](<#TrimaStrategy.Compute>)
- [func \(\*TrimaStrategy\) Name\(\) string](<#TrimaStrategy.Name>)
- [func \(t \*TrimaStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#TrimaStrategy.Report>)
- [type VwmaStrategy](<#VwmaStrategy>)
- [func NewVwmaStrategy\(\) \*VwmaStrategy](<#NewVwmaStrategy>)
- [func \(v \*VwmaStrategy\) Compute\(c \<\-chan \*asset.Snapshot\) \<\-chan Action](<#VwmaStrategy.Compute>)
- [func \(\*VwmaStrategy\) Name\(\) string](<#VwmaStrategy.Name>)
- [func \(v \*VwmaStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#VwmaStrategy.Report>)


## Constants
Expand All @@ -94,6 +104,27 @@ const (
)
```

<a name="DefaultTrimaStrategyShortPeriod"></a>

```go
const (
// DefaultTrimaStrategyShortPeriod is the first TRIMA period.
DefaultTrimaStrategyShortPeriod = 20

// DefaultTrimaStrategyLongPeriod is the second TRIMA period.
DefaultTrimaStrategyLongPeriod = 50
)
```

<a name="DefaultVwmaStrategyPeriod"></a>

```go
const (
// DefaultVwmaStrategyPeriod is the default VWMA period.
DefaultVwmaStrategyPeriod = 20
)
```

<a name="ActionsToAnnotations"></a>
## func [ActionsToAnnotations](<https://github.com/cinar/indicator/blob/v2/strategy/action.go#L46>)

Expand Down Expand Up @@ -661,4 +692,110 @@ type Strategy interface {
}
```

<a name="TrimaStrategy"></a>
## type [TrimaStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/trima_strategy.go#L24-L32>)

TrimaStrategy represents the configuration parameters for calculating the TRIMA strategy. A bullish cross occurs when the short TRIMA moves above the long TRIMA. A bearish cross occurs when the short TRIMA moves below the long TRIME.

```go
type TrimaStrategy struct {
Strategy

// Trima1 represents the configuration parameters for calculating the short TRIMA.
Short *trend.Trima[float64]

// Trima2 represents the configuration parameters for calculating the long TRIMA.
Long *trend.Trima[float64]
}
```

<a name="NewTrimaStrategy"></a>
### func [NewTrimaStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/trima_strategy.go#L36>)

```go
func NewTrimaStrategy() *TrimaStrategy
```

NewTrimaStrategy function initializes a new TRIMA strategy instance with the default parameters.

<a name="TrimaStrategy.Compute"></a>
### func \(\*TrimaStrategy\) [Compute](<https://github.com/cinar/indicator/blob/v2/strategy/trima_strategy.go#L55>)

```go
func (t *TrimaStrategy) Compute(c <-chan *asset.Snapshot) <-chan Action
```

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="TrimaStrategy.Name"></a>
### func \(\*TrimaStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/trima_strategy.go#L49>)

```go
func (*TrimaStrategy) Name() string
```

Name returns the name of the strategy.

<a name="TrimaStrategy.Report"></a>
### func \(\*TrimaStrategy\) [Report](<https://github.com/cinar/indicator/blob/v2/strategy/trima_strategy.go#L83>)

```go
func (t *TrimaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
```

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

<a name="VwmaStrategy"></a>
## type [VwmaStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/vwma_strategy.go#L21-L29>)

VwmaStrategy represents the configuration parameters for calculating the VWMA strategy. The VwmaStrategy function uses SMA and VWMA indicators to provide a BUY action when VWMA is above SMA, and a SELL signal when VWMA is below SMA, a HOLD otherwse.

```go
type VwmaStrategy struct {
Strategy

// VWMA indicator.
Vwma *trend.Vwma[float64]

// SMA indicator.
Sma *trend.Sma[float64]
}
```

<a name="NewVwmaStrategy"></a>
### func [NewVwmaStrategy](<https://github.com/cinar/indicator/blob/v2/strategy/vwma_strategy.go#L32>)

```go
func NewVwmaStrategy() *VwmaStrategy
```

NewVwmaStrategy function initializes a new VWMA strategy instance with the default parameters.

<a name="VwmaStrategy.Compute"></a>
### func \(\*VwmaStrategy\) [Compute](<https://github.com/cinar/indicator/blob/v2/strategy/vwma_strategy.go#L50>)

```go
func (v *VwmaStrategy) Compute(c <-chan *asset.Snapshot) <-chan Action
```

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

<a name="VwmaStrategy.Name"></a>
### func \(\*VwmaStrategy\) [Name](<https://github.com/cinar/indicator/blob/v2/strategy/vwma_strategy.go#L45>)

```go
func (*VwmaStrategy) Name() string
```

Name returns the name of the strategy.

<a name="VwmaStrategy.Report"></a>
### func \(\*VwmaStrategy\) [Report](<https://github.com/cinar/indicator/blob/v2/strategy/vwma_strategy.go#L73>)

```go
func (v *VwmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
```

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
2 changes: 2 additions & 0 deletions strategy/backtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func (b *Backtest) allStrategies() []Strategy {
NewKdjStrategy(),
NewMacdStrategy(),
NewQstickStrategy(),
NewTrimaStrategy(),
NewVwmaStrategy(),
}
}

Expand Down
Loading

0 comments on commit 6425038

Please sign in to comment.