-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volume Weighted Average Price Strategy added. #239
Conversation
WalkthroughThe pull request introduces significant updates to the Indicator Go module, particularly in the README.md and the volume strategy implementations. The README now details version 2 features, including a complete codebase rewrite for improved test coverage, enhanced data handling via Go channels, and the introduction of a new Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #239 +/- ##
==========================================
+ Coverage 93.41% 93.46% +0.04%
==========================================
Files 170 171 +1
Lines 5922 5997 +75
==========================================
+ Hits 5532 5605 +73
- Misses 331 333 +2
Partials 59 59 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (5)
strategy/volume/volume_weighted_average_price_strategy_test.go (1)
17-37
: LGTM with suggestion: Well-structured test for VolumeWeightedAveragePriceStrategy.The test function is well-structured and follows good practices for Go unit tests. It properly handles errors and uses helper functions for reading CSV files and comparing results.
Suggestion for improvement:
Consider adding more specific error messages to the
t.Fatal
calls. This will make debugging easier if the test fails. For example:if err != nil { t.Fatalf("Failed to read snapshots from CSV: %v", err) }README.md (1)
145-145
: VWAP Strategy added successfully, minor formatting suggestionThe addition of the Volume Weighted Average Price Strategy aligns perfectly with the PR objectives. Great job on including this new strategy!
However, there's a minor formatting inconsistency:
Consider replacing the hard tab at the beginning of the line with spaces to maintain consistency with the rest of the file. This will improve readability and adhere to common Markdown formatting practices.
🧰 Tools
🪛 Markdownlint
145-145: Column: 2
Hard tabs(MD010, no-hard-tabs)
strategy/volume/README.md (1)
330-340
: Minor improvement for consistencyThe documentation for VolumeWeightedAveragePriceStrategy is well-written and follows the existing style. However, for consistency with other strategy descriptions, consider adding "It" at the beginning of the recommendation sentences.
Here's a suggested revision:
-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. +VolumeWeightedAveragePriceStrategy represents the configuration parameters for calculating the Volume Weighted Average Price strategy. It 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.strategy/volume/volume_weighted_average_price_strategy.go (2)
16-18
: Clarify the strategy description in the commentsConsider rephrasing the strategy description for better clarity. For example:
"VolumeWeightedAveragePriceStrategy represents the configuration parameters for calculating the Volume Weighted Average Price strategy. It recommends a Buy action when the closing price crosses below the VWAP, a Sell action when the closing price crosses above the VWAP, and a Hold action otherwise."
59-69
: Handle equal values explicitly in action determinationCurrently, when
vwap
equalsclosing
, the strategy returnsHold
by default. For clarity, consider handling this case explicitly in the code.Apply this diff:
actions := helper.Operate(closingsSplice[0], vwaps, func(closing, vwap float64) strategy.Action { if vwap > closing { return strategy.Buy } else if vwap < closing { return strategy.Sell + } else { + return strategy.Hold } - } - return strategy.Hold })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
strategy/volume/testdata/volume_weighted_average_price_strategy.csv
is excluded by!**/*.csv
📒 Files selected for processing (5)
- README.md (1 hunks)
- strategy/volume/README.md (2 hunks)
- strategy/volume/volume.go (1 hunks)
- strategy/volume/volume_weighted_average_price_strategy.go (1 hunks)
- strategy/volume/volume_weighted_average_price_strategy_test.go (1 hunks)
🧰 Additional context used
🪛 Markdownlint
README.md
145-145: Column: 2
Hard tabs(MD010, no-hard-tabs)
🔇 Additional comments (11)
strategy/volume/volume.go (1)
32-32
: LGTM! New VWAP strategy successfully added.The addition of
NewVolumeWeightedAveragePriceStrategy()
to theAllStrategies()
function aligns well with the PR objectives of introducing a new Volume Weighted Average Price (VWAP) strategy. This change is consistent with the existing code structure and follows the pattern established for other volume strategies.A few points to consider:
- Ensure that the
NewVolumeWeightedAveragePriceStrategy()
function is implemented in this package.- Update any relevant documentation or README files to reflect this new strategy.
- Add unit tests for this new strategy if not already done.
To verify the implementation and documentation:
✅ Verification successful
Verification Successful
The implementation of
NewVolumeWeightedAveragePriceStrategy()
is present in the codebase. The README documentation has been updated accordingly, and relevant unit tests have been added to ensure the strategy functions as expected.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the implementation of NewVolumeWeightedAveragePriceStrategy ast-grep --lang go --pattern 'func NewVolumeWeightedAveragePriceStrategy() $_' # Check for updates in README or documentation rg -i "volume weighted average price|vwap" README.md # Look for new test files or functions fd -e go test_.*volume.*weighted.*average.*price rg -t go "func Test.*VolumeWeightedAveragePrice"Length of output: 1142
strategy/volume/volume_weighted_average_price_strategy_test.go (3)
1-5
: LGTM: Proper file header and package declaration.The file header includes appropriate copyright and license information. The package declaration follows Go conventions for test files.
7-15
: LGTM: Appropriate import statements.The import statements include all necessary packages for the tests, both from the standard library and the project's custom packages. The use of versioned imports (v2) is consistent with the project structure.
1-55
: Overall assessment: Well-implemented test file with room for minor improvements.This test file for the VolumeWeightedAveragePriceStrategy is well-structured and covers the main functionality of the strategy. It follows good Go testing practices and uses appropriate helper functions.
The suggested improvements, if implemented, would enhance error reporting, test coverage, and test isolation. These changes would make the tests more robust and easier to maintain in the long run.
Great job on implementing these tests! They will help ensure the reliability of the VolumeWeightedAveragePriceStrategy as the project evolves.
README.md (2)
Line range hint
1-290
: Excellent documentation structure and content!The README is well-organized and provides comprehensive information about the Indicator Go module. It effectively communicates the new features and improvements in version 2, aligning well with the PR objectives. The clear sections for indicators, strategies, repositories, backtesting, usage, contributing, and licensing make it easy for users to navigate and understand the module's capabilities.
🧰 Tools
🪛 Markdownlint
147-147: Expected: setext; Actual: atx
Heading style(MD003, heading-style)
142-142: Column: 2
Hard tabs(MD010, no-hard-tabs)
143-143: Column: 2
Hard tabs(MD010, no-hard-tabs)
144-144: Column: 2
Hard tabs(MD010, no-hard-tabs)
145-145: Column: 2
Hard tabs(MD010, no-hard-tabs)
Line range hint
1-290
: Excellent README update, minor formatting adjustment neededThe README has been comprehensively updated to reflect the new features and improvements in version 2 of the Indicator Go module. The addition of the Volume Weighted Average Price Strategy is well-documented and aligns perfectly with the PR objectives.
The overall structure and content of the README are excellent, providing clear and valuable information for users and potential contributors. The only improvement needed is a minor formatting adjustment on line 145 to replace the hard tab with spaces for consistency.
Great job on this update! Once the minor formatting issue is addressed, this README will serve as an excellent introduction and reference for the Indicator Go module.
🧰 Tools
🪛 Markdownlint
147-147: Expected: setext; Actual: atx
Heading style(MD003, heading-style)
142-142: Column: 2
Hard tabs(MD010, no-hard-tabs)
143-143: Column: 2
Hard tabs(MD010, no-hard-tabs)
144-144: Column: 2
Hard tabs(MD010, no-hard-tabs)
145-145: Column: 2
Hard tabs(MD010, no-hard-tabs)
strategy/volume/README.md (3)
53-58
: LGTM: VolumeWeightedAveragePriceStrategy added to indexThe new VolumeWeightedAveragePriceStrategy has been correctly added to the index, following the existing pattern and providing appropriate links to its sections.
342-385
: LGTM: Method documentation for VolumeWeightedAveragePriceStrategyThe method documentation for VolumeWeightedAveragePriceStrategy is well-written and consistent with the existing documentation style. It provides clear explanations for each method, including NewVolumeWeightedAveragePriceStrategy, NewVolumeWeightedAveragePriceStrategyWith, Compute, Name, and Report.
Line range hint
53-385
: Summary: VolumeWeightedAveragePriceStrategy documentationThe addition of the VolumeWeightedAveragePriceStrategy to the README.md file is well-executed. The new strategy is properly indexed, and its documentation follows the established pattern for other strategies in the volume package. The explanations are clear and concise, providing users with a good understanding of the strategy's purpose and behavior.
A minor suggestion was made to improve consistency in the main description, but overall, the documentation is of high quality and integrates seamlessly with the existing content.
strategy/volume/volume_weighted_average_price_strategy.go (2)
24-30
: Ensure the default period is appropriateIn the
NewVolumeWeightedAveragePriceStrategy
function, confirm thatvolume.DefaultVwapPeriod
is the desired default period for this strategy. If a different default is more appropriate for your use case, consider updating it.
77-118
: Confirm the synchronization of channels in theReport
methodThe
Report
method involves multiple channel duplications and skips. Ensure that all channels are properly synchronized to prevent any potential deadlocks or synchronization issues.
func TestVolumeWeightedAveragePriceStrategyReport(t *testing.T) { | ||
snapshots, err := helper.ReadFromCsvFile[asset.Snapshot]("testdata/brk-b.csv", true) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
vwaps := volume.NewVolumeWeightedAveragePriceStrategy() | ||
report := vwaps.Report(snapshots) | ||
|
||
fileName := "volume_weighted_average_price_strategy.html" | ||
defer os.Remove(fileName) | ||
|
||
err = report.WriteToFile(fileName) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
LGTM with suggestions: Good test for VolumeWeightedAveragePriceStrategy report generation.
The test function is well-structured and follows good practices for Go unit tests. It properly handles errors and uses defer
for file cleanup.
Suggestions for improvement:
-
Consider adding more specific error messages to the
t.Fatal
calls, as suggested in the previous comment. -
The test currently only checks if the report can be written without errors. Consider adding some basic validation of the generated HTML file contents. For example:
content, err := os.ReadFile(fileName)
if err != nil {
t.Fatalf("Failed to read generated report: %v", err)
}
if !strings.Contains(string(content), "Volume Weighted Average Price Strategy") {
t.Error("Generated report does not contain expected content")
}
- To improve test isolation and avoid potential conflicts in parallel test execution, consider using
t.TempDir()
to create a temporary directory for the output file:
tempDir := t.TempDir()
fileName := filepath.Join(tempDir, "volume_weighted_average_price_strategy.html")
This approach eliminates the need for manual cleanup with defer os.Remove(fileName)
.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hard tab with spaces (Markdownlint: MD010)
To address the Markdownlint warning and improve consistency:
Replace the hard tab at the beginning of line 145 with spaces. This will resolve the MD010 (no-hard-tabs) warning and ensure consistent formatting throughout the document.
🧰 Tools
🪛 Markdownlint
145-145: Column: 2
Hard tabs(MD010, no-hard-tabs)
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy { | ||
return &VolumeWeightedAveragePriceStrategy{ | ||
VolumeWeightedAveragePrice: volume.NewVwapWithPeriod[float64](period), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation for the period
parameter
In the NewVolumeWeightedAveragePriceStrategyWith
function, consider adding validation to ensure that the period
parameter is a positive integer. This helps prevent potential runtime errors due to invalid input.
Apply this diff to add validation:
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy {
+ if period <= 0 {
+ panic("period must be a positive integer")
+ }
return &VolumeWeightedAveragePriceStrategy{
VolumeWeightedAveragePrice: volume.NewVwapWithPeriod[float64](period),
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy { | |
return &VolumeWeightedAveragePriceStrategy{ | |
VolumeWeightedAveragePrice: volume.NewVwapWithPeriod[float64](period), | |
} | |
} | |
func NewVolumeWeightedAveragePriceStrategyWith(period int) *VolumeWeightedAveragePriceStrategy { | |
if period <= 0 { | |
panic("period must be a positive integer") | |
} | |
return &VolumeWeightedAveragePriceStrategy{ | |
VolumeWeightedAveragePrice: volume.NewVwapWithPeriod[float64](period), | |
} | |
} |
Describe Request
Volume Weighted Average Price Strategy added.
Change Type
New strategy.
Summary by CodeRabbit
Release Notes
New Features
VolumeWeightedAveragePriceStrategy
, allowing users to make trading decisions based on the Volume Weighted Average Price (VWAP).Bug Fixes
Documentation
Tests