Skip to content
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

Smoothed Moving Average (SMMA) Strategy added. #249

Merged
merged 1 commit into from
Dec 24, 2024
Merged

Conversation

cinar
Copy link
Owner

@cinar cinar commented Dec 24, 2024

Describe Request

Smoothed Moving Average (SMMA) Strategy added.

Change Type

New Strategy.

Summary by CodeRabbit

  • New Features

    • Introduced the Smoothed Moving Average (SMMA) Strategy to the Indicator Go module.
    • Added associated methods for the SMMA strategy, enhancing trend analysis capabilities.
  • Bug Fixes

    • Updated documentation to reflect new function signatures and improve clarity.
  • Tests

    • Established a testing framework for the SMMA strategy, validating computation and reporting functionalities.

Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces the Smoothed Moving Average (SMMA) Strategy to the Indicator Go module. The changes include adding a new strategy type SmmaStrategy in the strategy/trend package, updating the README files to document the new strategy, and integrating the SMMA strategy into the list of available trend strategies. The implementation provides methods for computing trading actions and generating reports based on SMMA calculations.

Changes

File Change Summary
README.md Added entry for SMMA Strategy in the list of strategies
strategy/trend/README.md Documented new SmmaStrategy type and its methods
strategy/trend/smma_strategy.go New file implementing SMMA strategy with methods for computation and reporting
strategy/trend/smma_strategy_test.go Added test cases for SMMA strategy computation and reporting
strategy/trend/trend.go Included NewSmmaStrategy() in AllStrategies function
trend/README.md Updated function signature documentation

Sequence Diagram

sequenceDiagram
    participant Asset as Asset Snapshots
    participant SMMA as SMMA Strategy
    participant Compute as Compute Method
    participant Action as Action Channel

    Asset->>SMMA: Provide snapshots
    SMMA->>Compute: Process snapshots
    Compute->>Compute: Calculate short and long SMMA
    Compute->>Action: Generate trading actions
    Action-->>SMMA: Return Buy/Sell/Hold recommendations
Loading

Possibly related PRs

  • Added support for SMMA. #247: Adds support for the Smoothed Moving Average (SMMA) as a new indicator, directly related to this strategy implementation

Poem

🐰 A rabbit's tale of SMMA's might,
Trends dancing left and dancing right,
Smoothed averages, short and long,
Guiding traders where they belong,
A strategy that hops with glee! 📈🐇

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 97.46835% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.59%. Comparing base (ee386c8) to head (ffb352d).

Files with missing lines Patch % Lines
strategy/trend/smma_strategy.go 98.71% 1 Missing ⚠️
strategy/trend/trend.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #249      +/-   ##
==========================================
+ Coverage   93.54%   93.59%   +0.05%     
==========================================
  Files         173      174       +1     
  Lines        6101     6180      +79     
==========================================
+ Hits         5707     5784      +77     
- Misses        335      337       +2     
  Partials       59       59              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cinar cinar merged commit cf5415f into master Dec 24, 2024
5 of 6 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
strategy/trend/smma_strategy.go (2)

24-27: Correct spelling of "Smoothed" in the documentation.

There is a minor spelling inconsistency: "Smooted" vs. "Smoothed." Correcting this ensures clarity.

-// Smooted Moving Averge (SMMA) strategy. A short-term SMMA crossing above
+// Smoothed Moving Average (SMMA) strategy. A short-term SMMA crossing above

125-130: Column naming consistency.

Using “MACD” and “Signal” columns might be a leftover from another strategy. Here they should be more descriptive of SMMA values, e.g. “Short SMMA” and “Long SMMA,” to avoid confusion.

-report.AddColumn(helper.NewNumericReportColumn("MACD", shortSmmas), 1)
-report.AddColumn(helper.NewNumericReportColumn("Signal", longSmmas), 1)
+report.AddColumn(helper.NewNumericReportColumn("Short SMMA", shortSmmas), 1)
+report.AddColumn(helper.NewNumericReportColumn("Long SMMA", longSmmas), 1)
strategy/trend/README.md (1)

793-854: Fix typos in SMMA strategy documentation

There are spelling errors in the documentation:

  • "Smooted Moving Averge" should be "Smoothed Moving Average"
-    // short-term Smooted Moving Averge (SMMA).
+    // short-term Smoothed Moving Average (SMMA).
-    // long-term Smooted Moving Averge (SMMA).
+    // long-term Smoothed Moving Average (SMMA).
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee386c8 and ffb352d.

⛔ Files ignored due to path filters (1)
  • strategy/trend/testdata/smma_strategy.csv is excluded by !**/*.csv
📒 Files selected for processing (6)
  • README.md (1 hunks)
  • strategy/trend/README.md (3 hunks)
  • strategy/trend/smma_strategy.go (1 hunks)
  • strategy/trend/smma_strategy_test.go (1 hunks)
  • strategy/trend/trend.go (1 hunks)
  • trend/README.md (4 hunks)
🔇 Additional comments (5)
strategy/trend/trend.go (1)

36-36: Great addition to the list of trend strategies.

This integrates the Smoothed Moving Average (SMMA) strategy into the existing AllStrategies function. Everything looks good here.

strategy/trend/smma_strategy_test.go (1)

39-56: Effective reporting test coverage.

• The creation of the HTML file and subsequent cleanup with defer os.Remove(fileName) is neat.
• Ensure test outputs are included in .gitignore so that temporary files do not clutter the repo.

README.md (1)

125-125: Accurate insertion of SMMA strategy reference.

The new bullet for “Smoothed Moving Average (SMMA) Strategy” fits well among other trend strategies.

strategy/trend/README.md (1)

88-93: LGTM: Index updated correctly with SMMA strategy

The SmmaStrategy type and its methods are properly documented in the index section, following the existing pattern and style.

trend/README.md (1)

Line range hint 1478-1505: LGTM: SMMA implementation is well-documented

The Smma type documentation and implementation:

  • Provides clear formula explanation
  • Includes usage examples
  • Follows project conventions for function signatures
  • Maintains consistency with other moving average implementations

Comment on lines +17 to +37
func TestSmmaStrategy(t *testing.T) {
snapshots, err := helper.ReadFromCsvFile[asset.Snapshot]("testdata/brk-b.csv", true)
if err != nil {
t.Fatal(err)
}

results, err := helper.ReadFromCsvFile[strategy.Result]("testdata/smma_strategy.csv", true)
if err != nil {
t.Fatal(err)
}

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

smma := trend.NewSmmaStrategy()
actual := smma.Compute(snapshots)

err = helper.CheckEquals(actual, expected)
if err != nil {
t.Fatal(err)
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Test data files are present but paths need to be updated

The test is using incorrect relative paths. The actual files are located at:

  • "strategy/trend/testdata/brk-b.csv" instead of "testdata/brk-b.csv"
  • "strategy/trend/testdata/smma_strategy.csv" instead of "testdata/smma_strategy.csv"

The test needs to be updated to use the correct paths relative to the test file location.

🔗 Analysis chain

Solid test coverage for SMMA strategy computation.

• The CSV-based testing approach provides strong validation.
• Good use of helper functions for reading input and verifying outputs.
• Consider verifying that “testdata/smma_strategy.csv” is present and correctly named in the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify existence of smma_strategy.csv and brk-b.csv in testdata directory
fd smma_strategy.csv --exact-depth 2 --search-path testdata
fd brk-b.csv --exact-depth 2 --search-path testdata

Length of output: 307


Script:

#!/bin/bash
# Let's first find where the test file is located to determine the correct path
fd smma_strategy_test.go

# Then search for CSV files in the repository
fd -e csv

Length of output: 3922

@cinar cinar deleted the smma-strategy branch December 24, 2024 04:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants