Skip to content

Commit

Permalink
Volume Weighted Average Price Strategy added. (#239)
Browse files Browse the repository at this point in the history
# Describe Request

Volume Weighted Average Price Strategy added.

# Change Type

New strategy.



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

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced the `VolumeWeightedAveragePriceStrategy`, allowing users to
make trading decisions based on the Volume Weighted Average Price
(VWAP).
- Enhanced documentation with updated installation and usage
instructions, including dedicated test data in CSV format.
- Added backtesting functionality for evaluating strategy performance
against defined asset sets.

- **Bug Fixes**
- Corrected the link format for the Volume Weighted Average Price
Strategy.

- **Documentation**
- Comprehensive updates to the README, reflecting version 2 enhancements
and clarifying licensing information.

- **Tests**
- Implemented unit tests for the new VWAP strategy to ensure accuracy in
computations and reporting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
cinar authored Oct 19, 2024
1 parent 0ea963f commit 4e64211
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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
- [Volume Weighted Average Price Strategy](strategy/volume/README.md#type-volumeweightedaveragepricestrategy)

### 🧪 Compound Strategies

Expand Down
63 changes: 63 additions & 0 deletions strategy/volume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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>)


## Constants
Expand Down Expand Up @@ -321,4 +327,61 @@ 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>)

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.

```go
type VolumeWeightedAveragePriceStrategy struct {
// VolumeWeightedAveragePrice is the Volume Weighted Average Price indicator instance.
VolumeWeightedAveragePrice *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>)

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

NewVolumeWeightedAveragePriceStrategy function initializes a new Volume 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>)

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

NewVolumeWeightedAveragePriceStrategyWith function initializes a new Volume 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>)

```go
func (v *VolumeWeightedAveragePriceStrategy) 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>)

```go
func (v *VolumeWeightedAveragePriceStrategy) 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>)

```go
func (v *VolumeWeightedAveragePriceStrategy) 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>)
252 changes: 252 additions & 0 deletions strategy/volume/testdata/volume_weighted_average_price_strategy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
Action
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
-1
1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1
1
1
1
1
-1
1
1
-1
1
1
1
-1
-1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1
1
-1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
-1
-1
1
1
1
1
1
-1
-1
-1
-1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 change: 1 addition & 0 deletions strategy/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ func AllStrategies() []strategy.Strategy {
NewForceIndexStrategy(),
NewMoneyFlowIndexStrategy(),
NewNegativeVolumeIndexStrategy(),
NewVolumeWeightedAveragePriceStrategy(),
}
}
Loading

0 comments on commit 4e64211

Please sign in to comment.