Skip to content

Commit

Permalink
Rename Volume Weighted Price Strategy to Weighted Price Strategy. (#245)
Browse files Browse the repository at this point in the history
# Describe Request

Rename Volume Weighted Price Strategy to Weighted Price Strategy.

# Change Type

Lint fix.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Added a "Major Improvements" section in the documentation highlighting
enhancements in version 2, including improved code quality and
testability.
- Updated lists of indicators and strategies to reflect current
offerings, including a renamed strategy.

- **Bug Fixes**
- Corrected references for the "Volume Weighted Average Price Strategy"
to the new name "Weighted Average Price Strategy" across documentation
and code.

- **Documentation**
- Enhanced clarity and organization of the README, including sections on
repositories, backtesting, usage instructions, and contributing
guidelines.

- **Refactor**
- Renamed `VolumeWeightedAveragePriceStrategy` to
`WeightedAveragePriceStrategy`, updating all related references and
documentation accordingly.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
cinar authored Dec 23, 2024
1 parent ed62fc9 commit 6020bfe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The following list of strategies are currently supported by this package:
- [Force Index Strategy](strategy/volume/README.md#type-forceindexstrategy)
- [Money Flow Index Strategy](strategy/volume/README.md#type-moneyflowindexstrategy)
- [Negative Volume Index Strategy](strategy/volume/README.md#type-negativevolumeindexstrategy)
- [Volume Weighted Average Price Strategy](strategy/volume/README.md#type-volumeweightedaveragepricestrategy)
- [Weighted Average Price Strategy](strategy/volume/README.md#type-weightedaveragepricestrategy)

### 🧪 Compound Strategies

Expand Down
58 changes: 29 additions & 29 deletions strategy/volume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ The information provided on this project is strictly for informational purposes
- [func \(n \*NegativeVolumeIndexStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#NegativeVolumeIndexStrategy.Compute>)
- [func \(n \*NegativeVolumeIndexStrategy\) Name\(\) string](<#NegativeVolumeIndexStrategy.Name>)
- [func \(n \*NegativeVolumeIndexStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#NegativeVolumeIndexStrategy.Report>)
- [type VolumeWeightedAveragePriceStrategy](<#VolumeWeightedAveragePriceStrategy>)
- [func NewVolumeWeightedAveragePriceStrategy\(\) \*VolumeWeightedAveragePriceStrategy](<#NewVolumeWeightedAveragePriceStrategy>)
- [func NewVolumeWeightedAveragePriceStrategyWith\(period int\) \*VolumeWeightedAveragePriceStrategy](<#NewVolumeWeightedAveragePriceStrategyWith>)
- [func \(v \*VolumeWeightedAveragePriceStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#VolumeWeightedAveragePriceStrategy.Compute>)
- [func \(v \*VolumeWeightedAveragePriceStrategy\) Name\(\) string](<#VolumeWeightedAveragePriceStrategy.Name>)
- [func \(v \*VolumeWeightedAveragePriceStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#VolumeWeightedAveragePriceStrategy.Report>)
- [type WeightedAveragePriceStrategy](<#WeightedAveragePriceStrategy>)
- [func NewWeightedAveragePriceStrategy\(\) \*WeightedAveragePriceStrategy](<#NewWeightedAveragePriceStrategy>)
- [func NewWeightedAveragePriceStrategyWith\(period int\) \*WeightedAveragePriceStrategy](<#NewWeightedAveragePriceStrategyWith>)
- [func \(v \*WeightedAveragePriceStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#WeightedAveragePriceStrategy.Compute>)
- [func \(v \*WeightedAveragePriceStrategy\) Name\(\) string](<#WeightedAveragePriceStrategy.Name>)
- [func \(v \*WeightedAveragePriceStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#WeightedAveragePriceStrategy.Report>)


## Constants
Expand Down Expand Up @@ -390,59 +390,59 @@ func (n *NegativeVolumeIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.R

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

<a name="VolumeWeightedAveragePriceStrategy"></a>
## type [VolumeWeightedAveragePriceStrategy](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L19-L22>)
<a name="WeightedAveragePriceStrategy"></a>
## type [WeightedAveragePriceStrategy](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L19-L22>)

VolumeWeightedAveragePriceStrategy represents the configuration parameters for calculating the Volume Weighted Average Price strategy. Recommends a Buy action when the closing crosses below the VWAP, recommends a Sell action when the closing crosses above the VWAP, and recommends a Hold action otherwise.
WeightedAveragePriceStrategy represents the configuration parameters for calculating the Weighted Average Price strategy. Recommends a Buy action when the closing crosses below the VWAP, recommends a Sell action when the closing crosses above the VWAP, and recommends a Hold action otherwise.

```go
type VolumeWeightedAveragePriceStrategy struct {
// VolumeWeightedAveragePrice is the Volume Weighted Average Price indicator instance.
VolumeWeightedAveragePrice *volume.Vwap[float64]
type WeightedAveragePriceStrategy struct {
// WeightedAveragePrice is the Weighted Average Price indicator instance.
WeightedAveragePrice *volume.Vwap[float64]
}
```

<a name="NewVolumeWeightedAveragePriceStrategy"></a>
### func [NewVolumeWeightedAveragePriceStrategy](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L26>)
<a name="NewWeightedAveragePriceStrategy"></a>
### func [NewWeightedAveragePriceStrategy](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L26>)

```go
func NewVolumeWeightedAveragePriceStrategy() *VolumeWeightedAveragePriceStrategy
func NewWeightedAveragePriceStrategy() *WeightedAveragePriceStrategy
```

NewVolumeWeightedAveragePriceStrategy function initializes a new Volume Weighted Average Price strategy instance with the default parameters.
NewWeightedAveragePriceStrategy function initializes a new Weighted Average Price strategy instance with the default parameters.

<a name="NewVolumeWeightedAveragePriceStrategyWith"></a>
### func [NewVolumeWeightedAveragePriceStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L34>)
<a name="NewWeightedAveragePriceStrategyWith"></a>
### func [NewWeightedAveragePriceStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L34>)

```go
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy
func NewWeightedAveragePriceStrategyWith(period int) *WeightedAveragePriceStrategy
```

NewVolumeWeightedAveragePriceStrategyWith function initializes a new Volume Weighted Average Price strategy instance with the given parameters.
NewWeightedAveragePriceStrategyWith function initializes a new Weighted Average Price strategy instance with the given parameters.

<a name="VolumeWeightedAveragePriceStrategy.Compute"></a>
### func \(\*VolumeWeightedAveragePriceStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L46>)
<a name="WeightedAveragePriceStrategy.Compute"></a>
### func \(\*WeightedAveragePriceStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L46>)

```go
func (v *VolumeWeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
func (v *WeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
```

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

<a name="VolumeWeightedAveragePriceStrategy.Name"></a>
### func \(\*VolumeWeightedAveragePriceStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L41>)
<a name="WeightedAveragePriceStrategy.Name"></a>
### func \(\*WeightedAveragePriceStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L41>)

```go
func (v *VolumeWeightedAveragePriceStrategy) Name() string
func (v *WeightedAveragePriceStrategy) Name() string
```

Name returns the name of the strategy.

<a name="VolumeWeightedAveragePriceStrategy.Report"></a>
### func \(\*VolumeWeightedAveragePriceStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/volume/volume_weighted_average_price_strategy.go#L78>)
<a name="WeightedAveragePriceStrategy.Report"></a>
### func \(\*WeightedAveragePriceStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/volume/weighted_average_price_strategy.go#L78>)

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
Expand Down
2 changes: 1 addition & 1 deletion strategy/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ func AllStrategies() []strategy.Strategy {
NewForceIndexStrategy(),
NewMoneyFlowIndexStrategy(),
NewNegativeVolumeIndexStrategy(),
NewVolumeWeightedAveragePriceStrategy(),
NewWeightedAveragePriceStrategy(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ import (
"github.com/cinar/indicator/v2/volume"
)

// VolumeWeightedAveragePriceStrategy represents the configuration parameters for calculating the Volume Weighted
// WeightedAveragePriceStrategy represents the configuration parameters for calculating the Weighted
// Average Price strategy. Recommends a Buy action when the closing crosses below the VWAP, recommends a Sell
// action when the closing crosses above the VWAP, and recommends a Hold action otherwise.
type VolumeWeightedAveragePriceStrategy struct {
// VolumeWeightedAveragePrice is the Volume Weighted Average Price indicator instance.
VolumeWeightedAveragePrice *volume.Vwap[float64]
type WeightedAveragePriceStrategy struct {
// WeightedAveragePrice is the Weighted Average Price indicator instance.
WeightedAveragePrice *volume.Vwap[float64]
}

// NewVolumeWeightedAveragePriceStrategy function initializes a new Volume Weighted Average Price strategy
// NewWeightedAveragePriceStrategy function initializes a new Weighted Average Price strategy
// instance with the default parameters.
func NewVolumeWeightedAveragePriceStrategy() *VolumeWeightedAveragePriceStrategy {
return NewVolumeWeightedAveragePriceStrategyWith(
func NewWeightedAveragePriceStrategy() *WeightedAveragePriceStrategy {
return NewWeightedAveragePriceStrategyWith(
volume.DefaultVwapPeriod,
)
}

// NewVolumeWeightedAveragePriceStrategyWith function initializes a new Volume Weighted Average Price strategy
// NewWeightedAveragePriceStrategyWith function initializes a new Weighted Average Price strategy
// instance with the given parameters.
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy {
return &VolumeWeightedAveragePriceStrategy{
VolumeWeightedAveragePrice: volume.NewVwapWithPeriod[float64](period),
func NewWeightedAveragePriceStrategyWith(period int) *WeightedAveragePriceStrategy {
return &WeightedAveragePriceStrategy{
WeightedAveragePrice: volume.NewVwapWithPeriod[float64](period),
}
}

// Name returns the name of the strategy.
func (v *VolumeWeightedAveragePriceStrategy) Name() string {
return fmt.Sprintf("Volume Weighted Average Price Strategy (%d)", v.VolumeWeightedAveragePrice.IdlePeriod()+1)
func (v *WeightedAveragePriceStrategy) Name() string {
return fmt.Sprintf("Weighted Average Price Strategy (%d)", v.WeightedAveragePrice.IdlePeriod()+1)
}

// Compute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (v *VolumeWeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action {
func (v *WeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action {
snapshotsSplice := helper.Duplicate(snapshots, 2)

closingsSplice := helper.Duplicate(
Expand All @@ -53,8 +53,8 @@ func (v *VolumeWeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Sna

volumes := asset.SnapshotsAsVolumes(snapshotsSplice[1])

vwaps := v.VolumeWeightedAveragePrice.Compute(closingsSplice[1], volumes)
closingsSplice[0] = helper.Skip(closingsSplice[0], v.VolumeWeightedAveragePrice.IdlePeriod())
vwaps := v.WeightedAveragePrice.Compute(closingsSplice[1], volumes)
closingsSplice[0] = helper.Skip(closingsSplice[0], v.WeightedAveragePrice.IdlePeriod())

actions := helper.Operate(closingsSplice[0], vwaps, func(closing, vwap float64) strategy.Action {
if vwap > closing {
Expand All @@ -68,14 +68,14 @@ func (v *VolumeWeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Sna
return strategy.Hold
})

// Volume Weighted Average Price starts only after a full period.
actions = helper.Shift(actions, v.VolumeWeightedAveragePrice.IdlePeriod(), strategy.Hold)
// Weighted Average Price starts only after a full period.
actions = helper.Shift(actions, v.WeightedAveragePrice.IdlePeriod(), strategy.Hold)

return actions
}

// Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
func (v *VolumeWeightedAveragePriceStrategy) Report(c <-chan *asset.Snapshot) *helper.Report {
func (v *WeightedAveragePriceStrategy) Report(c <-chan *asset.Snapshot) *helper.Report {
//
// snapshots[0] -> dates
// snapshots[1] -> closings[0] -> closings
Expand All @@ -86,21 +86,21 @@ func (v *VolumeWeightedAveragePriceStrategy) Report(c <-chan *asset.Snapshot) *h
//
snapshots := helper.Duplicate(c, 4)

dates := helper.Skip(asset.SnapshotsAsDates(snapshots[0]), v.VolumeWeightedAveragePrice.IdlePeriod())
dates := helper.Skip(asset.SnapshotsAsDates(snapshots[0]), v.WeightedAveragePrice.IdlePeriod())

closingsSplice := helper.Duplicate(
asset.SnapshotsAsClosings(snapshots[1]),
2,
)
volumes := asset.SnapshotsAsVolumes(snapshots[2])

vwaps := v.VolumeWeightedAveragePrice.Compute(closingsSplice[0], volumes)
vwaps := v.WeightedAveragePrice.Compute(closingsSplice[0], volumes)

closingsSplice[1] = helper.Skip(closingsSplice[1], v.VolumeWeightedAveragePrice.IdlePeriod())
closingsSplice[1] = helper.Skip(closingsSplice[1], v.WeightedAveragePrice.IdlePeriod())

actions, outcomes := strategy.ComputeWithOutcome(v, snapshots[3])
actions = helper.Skip(actions, v.VolumeWeightedAveragePrice.IdlePeriod())
outcomes = helper.Skip(outcomes, v.VolumeWeightedAveragePrice.IdlePeriod())
actions = helper.Skip(actions, v.WeightedAveragePrice.IdlePeriod())
outcomes = helper.Skip(outcomes, v.WeightedAveragePrice.IdlePeriod())

annotations := strategy.ActionsToAnnotations(actions)
outcomes = helper.MultiplyBy(outcomes, 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestVolumeWeightedAveragePriceStrategy(t *testing.T) {

expected := helper.Map(results, func(r *strategy.Result) strategy.Action { return r.Action })

vwaps := volume.NewVolumeWeightedAveragePriceStrategy()
vwaps := volume.NewWeightedAveragePriceStrategy()
actual := vwaps.Compute(snapshots)

err = helper.CheckEquals(actual, expected)
Expand All @@ -42,7 +42,7 @@ func TestVolumeWeightedAveragePriceStrategyReport(t *testing.T) {
t.Fatal(err)
}

vwaps := volume.NewVolumeWeightedAveragePriceStrategy()
vwaps := volume.NewWeightedAveragePriceStrategy()
report := vwaps.Report(snapshots)

fileName := "volume_weighted_average_price_strategy.html"
Expand Down

0 comments on commit 6020bfe

Please sign in to comment.