From cee747af1d2018b56c6b9a12d85d11c6348a845d Mon Sep 17 00:00:00 2001 From: Onur Cinar Date: Sun, 1 Mar 2026 10:55:52 -0800 Subject: [PATCH] Revert "Implement Ichimoku Cloud Strategy #336 (#348)" This reverts commit aff23daa800e3007ae915f24632c538950fabbc0. --- README.md | 409 +++++++++++++++++- strategy/momentum/README.md | 53 --- strategy/momentum/ichimoku_cloud_strategy.go | 107 ----- .../momentum/ichimoku_cloud_strategy_test.go | 55 --- strategy/momentum/momentum.go | 1 - .../testdata/ichimoku_cloud_strategy.csv | 252 ----------- 6 files changed, 404 insertions(+), 473 deletions(-) delete mode 100644 strategy/momentum/ichimoku_cloud_strategy.go delete mode 100644 strategy/momentum/ichimoku_cloud_strategy_test.go delete mode 100644 strategy/momentum/testdata/ichimoku_cloud_strategy.csv diff --git a/README.md b/README.md index 31337832..c8973d4d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,412 @@ - +[![GoDoc](https://godoc.org/github.com/cinar/indicator/v2?status.svg)](https://godoc.org/github.com/cinar/indicator/v2) [![License](https://img.shields.io/badge/License-AGPLv3-blue.svg)](https://opensource.org/licenses/AGPLv3) [![Go Report Card](https://goreportcard.com/badge/github.com/cinar/indicator/v2)](https://goreportcard.com/report/github.com/cinar/indicator/v2) ![Go CI](https://github.com/cinar/indicator/actions/workflows/ci.yml/badge.svg) [![codecov](https://codecov.io/gh/cinar/indicator/graph/badge.svg?token=MB7L69UAWM)](https://codecov.io/gh/cinar/indicator) [![GHCR Version](https://img.shields.io/github/v/tag/cinar/indicator?label=ghcr&sort=semver&logo=github)](https://github.com/cinar/indicator/pkgs/container/indicator) -# indicator +

+ +

+ +Indicator Go +============ + +Indicator is a Golang module that provides a rich set of technical analysis indicators, strategies, and a framework for backtesting. + +### Major improvements in v2: + +- **Enhanced Code Quality:** A complete rewrite was undertaken to achieve and maintain at least 90% code coverage. +- **Improved Testability:** Each indicator and strategy have dedicated test data in CSV format for easier validation. +- **Streamlined Data Handling:** The library was rewritten to operate on data streams (Go channels) for both inputs and outputs. If you prefer using slices, helper functions like [helper.SliceToChan](helper/README.md#func-slicetochan) and [helper.ChanToSlice](helper/README.md#func-chantoslice) are available. Alternatively, you can still use the [v1 version](https://github.com/cinar/indicator/tree/v1). +- **Configurable Indicators and Strategies:** All indicators and strategies were designed to be fully configurable with no preset values. +- **Generics Support:** The library leverages Golang generics to support various numeric data formats. +- **MCP Support:** MCP (Multi-Client Protocol Server) support is integrated into the library, facilitating its use with various AI tools. + +I also have a TypeScript version of this module now at [Indicator TS](https://github.com/cinar/indicatorts). + +๐Ÿ‘† Indicators Provided +---------------------- + +The following list of indicators are currently supported by this package: + +### ๐Ÿ“ˆ Trend Indicators + +- [Absolute Price Oscillator (APO)](trend/README.md#type-apo) +- [Aroon Indicator](trend/README.md#type-aroon) +- [Balance of Power (BoP)](trend/README.md#type-bop) +- [Chande Forecast Oscillator (CFO)](trend/README.md#cfo) +- [Commodity Channel Index (CCI)](trend/README.md#type-cci) +- [Envelope](trend/README.md#type-envelope) +- [Hull Moving Average (HMA)](trend/README.md#type-hma) +- [Detrended Price Oscillator (DPO)](trend/README.md#type-dpo) +- [Double Exponential Moving Average (DEMA)](trend/README.md#type-dema) +- [Exponential Moving Average (EMA)](trend/README.md#type-ema) +- [Kaufman's Adaptive Moving Average (KAMA)](trend/README.md#type-kama) +- [Know Sure Thing (KST)](trend/README.md#type-kst) +- [Mass Index (MI)](trend/README.md#type-massindex) +- [McGinley Dynamic](trend/README.md#type-mcginleydynamic) +- [Moving Average Convergence Divergence (MACD)](trend/README.md#type-macd) +- [Moving Least Square (MLS)](trend/README.md#type-mls) +- [Moving Linear Regression (MLR)](trend/README.md#type-mlr) +- [Moving Max](trend/README.md#type-movingmax) +- [Moving Min](trend/README.md#type-movingmin) +- [Moving Sum](trend/README.md#type-movingsum) +- Parabolic SAR +- [Random Index (KDJ)](trend/README.md#type-kdj) +- [Stochastic](trend/README.md#type-stochastic) +- [Slow Stochastic](trend/README.md#type-slowstochastic) +- [Schaff Trend Cycle (STC)](trend/README.md#type-stc) +- [Rolling Moving Average (RMA)](trend/README.md#type-rma) +- [Simple Moving Average (SMA)](trend/README.md#type-sma) +- [Since Change](helper/README.md#func-since) +- [Smoothed Moving Average (SMMA)](trend/README.md#type-smma) +- [Triple Exponential Moving Average (TEMA)](trend/README.md#type-tema) +- [Triangular Moving Average (TRIMA)](trend/README.md#type-trima) +- [Triple Exponential Average (TRIX)](trend/README.md#type-trix) +- [True Strength Index (TSI)](trend/README.md#type-tsi) +- [Tillson T3](trend/README.md#T3) +- [Typical Price](trend/README.md#type-typicalprice) +- [Volume Weighted Moving Average (VWMA)](trend/README.md#type-vwma) +- Vortex Indicator +- [Weighted Close](trend/README.md#type-weightedclose) +- [Weighted Moving Average (WMA)](trend/README.md#type-wma) + +### ๐Ÿš€ Momentum Indicators + +- [Awesome Oscillator](momentum/README.md#type-awesomeoscillator) +- [Chaikin Oscillator](momentum/README.md#type-chaikinoscillator) +- [Connors RSI](momentum/README.md#type-connorsrsi) +- [Coppock Curve](momentum/README.md#type-coppockcurve) +- [Elder-Ray Index](momentum/README.md#ElderRay) +- [Fisher Transform](momentum/README.md#Fisher) +- [Ichimoku Cloud](momentum/README.md#type-ichimokucloud) +- [Percentage Price Oscillator (PPO)](momentum/README.md#type-ppo) +- [Percentage Volume Oscillator (PVO)](momentum/README.md#type-pvo) +- [Martin Pring's Special K](momentum/README.md#PringsSpecialK) +- [Relative Strength Index (RSI)](momentum/README.md#type-rsi) +- [Relative Vigor Index (RVI)](momentum/README.md#Rvi) +- [Qstick](momentum/README.md#type-qstick) +- [Stochastic Oscillator](momentum/README.md#type-stochasticoscillator) +- [Stochastic RSI](momentum/README.md#type-stochasticrsi) +- [TD Sequential](momentum/README.md#type-tdsequential) +- [Williams R](momentum/README.md#type-williamsr) + +### ๐ŸŽข Volatility Indicators + +- [%B](volatility/README.md#type-percentb) +- [Acceleration Bands](volatility/README.md#type-accelerationbands) +- [Actual True Range (ATR)](volatility/README.md#type-atr) +- [Bollinger Band Width](volatility/README.md#type-bollingerbandwidth) +- [Bollinger Bands](volatility/README.md#type-bollingerbands) +- [Chandelier Exit](volatility/README.md#type-chandelierexit) +- [Choppiness Index (CHOP)](volatility/README.md#type-chop) +- [Donchian Channel (DC)](volatility/README.md#type-donchianchannel) +- [Keltner Channel (KC)](volatility/README.md#type-keltnerchannel) +- [Moving Standard Deviation (Std)](volatility/README.md#type-movingstd) +- [Projection Oscillator (PO)](volatility/README.md#type-po) +- [Super Trend](volatility/README.md#type-supertrend) +- [Ulcer Index (UI)](volatility/README.md#type-ulcerindex) + +### ๐Ÿ“ข Volume Indicators + +- [Accumulation/Distribution (A/D)](volume/README.md#type-ad) +- [Chaikin Money Flow (CMF)](volume/README.md#type-cmf) +- [Ease of Movement (EMV)](volume/README.md#type-emv) +- [Force Index (FI)](volume/README.md#type-fi) +- [Klinger Volume Oscillator (KVO)](volume/README.md#type-kvo) +- [Money Flow Index (MFI)](volume/README.md#type-mfi) +- [Money Flow Multiplier (MFM)](volume/README.md#type-mfm) +- [Money Flow Volume (MFV)](volume/README.md#type-mfv) +- [Negative Volume Index (NVI)](volume/README.md#type-nvi) +- [On-Balance Volume (OBV)](volume/README.md#type-obv) +- [Volume Price Trend (VPT)](volume/README.md#type-vpt) +- [Volume Weighted Average Price (VWAP)](volume/README.md#type-vwap) + +### ๐Ÿ’ฐ Asset Valuation +- [Future Value (FV)](valuation/README.md#Fv) +- [Net Present Value (NPV)](valuation/README.md#Npv) +- [Present Value (PV)](valuation/README.md#Pv) + +๐Ÿง  Strategies Provided +---------------------- + +The following list of strategies are currently supported by this package: + +### โš– Base Strategies + +- [Buy and Hold Strategy](strategy/README.md#type-buyandholdstrategy) + +### ๐Ÿ“ˆ Trend Strategies + +- [Alligator Strategy](strategy/trend/README.md#type-alligatorstrategy) +- [Absolute Price Oscillator (APO) Strategy](strategy/trend/README.md#type-apostrategy) +- [Aroon Strategy](strategy/trend/README.md#type-aroonstrategy) +- [Balance of Power (BoP) Strategy](strategy/trend/README.md#type-bopstrategy) +- [Chande Forecast Oscillator Strategy](strategy/trend/README.md#cfostrategy) +- [Commodity Channel Index (CCI) Strategy](strategy/trend/README.md#type-ccistrategy) +- [Double Exponential Moving Average (DEMA) Strategy](strategy/trend/README.md#type-demastrategy) +- [Envelope Strategy](strategy/trend/README.md#type-envelope) +- [Golden Cross Strategy](strategy/trend/README.md#type-goldencrossstrategy) +- [Kaufman's Adaptive Moving Average (KAMA) Strategy](strategy/trend/README.md#type-kamastrategy) +- [Moving Average Convergence Divergence (MACD) Strategy](strategy/trend/README.md#type-macdstrategy) +- [Qstick Strategy](strategy/trend/README.md#type-qstickstrategy) +- [Random Index (KDJ) Strategy](strategy/trend/README.md#type-kdjstrategy) +- [Smoothed Moving Average (SMMA) Strategy](strategy/trend/README.md#type-smmastrategy) +- [Triangular Moving Average (TRIMA) Strategy](strategy/trend/README.md#type-trimastrategy) +- [Triple Exponential Average (TRIX) Strategy](strategy/trend/README.md#type-trixstrategy) +- [Triple Moving Average Crossover Strategy](strategy/trend/README.md#type-triplemovingaveragecrossoverstrategy) +- [True Strength Index (TSI) Strategy](strategy/trend/README.md#type-tsistrategy) +- [Volume Weighted Moving Average (VWMA) Strategy](strategy/trend/README.md#type-vwmastrategy) +- [Weighted Close Strategy](strategy/trend/README.md#type-weightedclosestrategy) + +### ๐Ÿš€ Momentum Strategies + +- [Awesome Oscillator Strategy](strategy/momentum/README.md#type-awesomeoscillatorstrategy) +- [RSI Strategy](strategy/momentum/README.md#type-rsistrategy) +- [Stochastic RSI Strategy](strategy/momentum/README.md#type-stochasticrsistrategy) +- Williams R Strategy + +### ๐ŸŽข Volatility Strategies + +- [Bollinger Bands Strategy](strategy/volatility/README.md#type-bollingerbandsstrategy) +- Projection Oscillator Strategy + +### ๐Ÿ“ข Volume Strategies + +- [Chaikin Money Flow Strategy](strategy/volume/README.md#type-chaikinmoneyflowstrategy) +- [Ease of Movement Strategy](strategy/volume/README.md#type-easeofmovementstrategy) +- [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) +- [Weighted Average Price Strategy](strategy/volume/README.md#type-weightedaveragepricestrategy) + +### ๐Ÿงช Compound Strategies + +Compound strategies merge multiple strategies to produce integrated recommendations. They combine individual strategies' recommendations using various decision-making logic. + +- [All Strategy](strategy/README.md#type-allstrategy) +- [Majority Strategy](strategy/README.md#type-majoritystrategy) +- [MACD-RSI Strategy](strategy/compound/README.md#type-macdrsistrategy) +- [Or Strategy](strategy/README.md#type-orstrategy) +- [Split Strategy](strategy/README.md#type-splitstrategy) + +### ๐ŸŽ Decorator Strategies + +Decorator strategies offer a way to alter the recommendations of other strategies. + +- [Inverse Strategy](strategy/decorator/README.md#type-inversestrategy) +- [No Loss Strategy](strategy/decorator/README.md#type-nolossstrategy) +- [Stop Loss Strategy](strategy/decorator/README.md#type-stoplossstrategy) + +๐Ÿ—ƒ Repositories +-------------- + +Repository serves as a centralized storage and retrieval location for [asset snapshots](asset/README.md#type-snapshot). + +The following [repository implementations](asset/README.md#type-repository) are provided. + +- [File System Repository](asset/README.md#type-filesystemrepository) +- [In Memory Repository](asset/README.md#type-inmemoryrepository) +- [Tiingo Repository](asset/README.md#type-tiingorepository) +- [Alpaca Markets Repository](https://github.com/cinar/indicatoralpaca) + +The [Sync function]() facilitates the synchronization of assets between designated source and target repositories by employing multi-worker concurrency for enhanced efficiency. This function serves the purpose of procuring the most recent snapshots from remote repositories and seamlessly transferring them to local repositories, such as file system repositories. + +The `indicator-sync` command line tool also offers the capability of synchronizing data between the Tiingo Repository and the File System Repository. To illustrate its usage, consider the following example command: + +```bash +$ indicator-sync \ + -source-name tiingo \ + -source-config $TIINGO_KEY \ + -target-name filesystem \ + -target-config /home/user/assets \ + -days 30 +``` + +This command effectively retrieves the most recent snapshots for assets residing within the `/home/user/assets` directory from the Tiingo Repository. In the event that the local asset file is devoid of content, it automatically extends its reach to synchronize 30 days' worth of snapshots, ensuring a comprehensive and up-to-date repository. + +โณ Backtesting +-------------- + +The [Backtest functionality](strategy/README.md#type-backtest), using the [Outcome](strategy/README.md#func-outcome), rigorously evaluates the potential performance of the specified strategies applied to a defined set of assets. It generates comprehensive visual representations for each strategy-asset pairing. ```go -import "github.com/cinar/indicator/v2" +backtest := strategy.NewBacktest(repository, outputDir) +backtest.Names = append(backtest.Names, "brk-b") +backtest.Strategies = append(backtest.Strategies, trend.NewApoStrategy()) + +err = backtest.Run() +if err != nil { + t.Fatal(err) +} +``` + +The `indicator-backtest` command line tool empowers users to conduct comprehensive backtesting of assets residing within a specified repository. This capability encompasses the application of all currently recognized strategies, culminating in the generation of detailed reports within a designated output directory. + +```bash +$ indicator-backtest \ + -source-name filesystem \ + -source-config /home/user/assets \ + -output /home/user/reports \ + -workers 1 ``` -## Index +โ˜๏ธ MCP Server +-------------- +The [MCP Server](mcp/README.md) (Multi-Client Protocol Server) provides a robust and scalable solution for serving trading strategies to multiple clients. It enables real-time strategy execution and data processing, making it ideal for applications requiring high-throughput and low-latency interactions with trading algorithms. +๐Ÿณ Docker +--------- -Generated by [gomarkdoc]() +The easiest way to get started is using our Docker image. It handles everything - syncing market data from Tiingo and generating backtest reports - in a single command. + +### Quick Start + +```bash +# Get your free Tiingo API key at: https://www.tiingo.com/ + +# Run backtest for specific assets +docker run -it --rm \ + -v $(pwd)/output:/app/output \ + ghcr.io/cinar/indicator:latest \ + --api-key YOUR_TIINGO_API_KEY \ + --days 365 \ + --assets aapl msft googl + +# View results (macOS) +open output/index.html + +# View results (Linux) +xdg-open output/index.html +``` + +### Options + +| Flag | Description | Default | +|------|-------------|---------| +| `--api-key` | Tiingo API key (required) | - | +| `--days` | Days of historical data to fetch | 365 | +| `--last` | Days to backtest | 365 | +| `--assets` | Space-separated ticker symbols (default: all) | all | +| `--output` | Output directory for reports | /app/output | + +### Examples + +```bash +# Backtest all available assets for 1 year +docker run -it --rm \ + -v $(pwd)/reports:/app/output \ + ghcr.io/cinar/indicator:latest \ + --api-key YOUR_TIINGO_API_KEY + +# Backtest specific stocks for last 6 months, test last 30 days +docker run -it --rm \ + -v $(pwd)/reports:/app/output \ + ghcr.io/cinar/indicator:latest \ + --api-key YOUR_TIINGO_API_KEY \ + --days 180 \ + --last 30 \ + --assets aapl msft googl amzn + +# Custom output directory +docker run -it --rm \ + -v /path/to/my/reports:/app/output \ + ghcr.io/cinar/indicator:latest \ + --api-key YOUR_TIINGO_API_KEY \ + --output /app/output +``` + +### Build Locally + +```bash +docker build -t indicator . +docker run -it --rm -v $(pwd)/output:/app/output indicator --api-key YOUR_KEY +``` + +Usage +----- + +Install package. + +```bash +go get github.com/cinar/indicator/v2 +``` + +Import indicator. + +```Golang +import ( + "github.com/cinar/indicator/v2" +) +``` + +๐ŸŒ Ecosystem +------------ + +Indicator Go is part of a broader ecosystem of technical analysis tools: + +- [Indicator TS](https://github.com/cinar/indicatorts) - TypeScript/JavaScript implementation of the same indicators and strategies +- [Indicator Alpaca](https://github.com/cinar/indicatoralpaca) - Alpaca Markets integration for live trading +- [MCP Server](mcp/README.md) - Model Context Protocol server for AI integration + +๐Ÿ’– Our Sponsors +--------------- + +Indicator is a community-supported project. The following companies, organizations, and individuals help make our work possible. Become [a sponsor](https://github.com/sponsors/cinar) and help us continue to grow! + +![Our Sponsors](./sponsors.svg) + +Contributing to the Project +--------------------------- + +Anyone can contribute to Indicator library. Please make sure to read our [Contributor Covenant Code of Conduct](./CODE_OF_CONDUCT.md) guide first. Follow the [How to Contribute to Indicator](./CONTRIBUTING.md) to contribute. Signining a [Contributor Agreement](./CLA.md) is also required to contribute to the project. + +Disclaimer +---------- + +The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. + +License +------- + +The `v2.x.x` and above are dual-licensed under GNU AGPLv3 License and a commercial license. For free use and modifications of the code, you can use the AGPLv3 license. If you require commercial license with different terms, please contact me. + +``` +Copyright (c) 2021-2026 Onur Cinar. +The source code is provided under GNU AGPLv3 License. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +``` + +The version `v1.x.x` is provided under MIT License. + +``` +Copyright (c) 2021-2026 Onur Cinar. +The source code is provided under MIT License. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/strategy/momentum/README.md b/strategy/momentum/README.md index 5db30354..dc89b62e 100644 --- a/strategy/momentum/README.md +++ b/strategy/momentum/README.md @@ -31,11 +31,6 @@ The information provided on this project is strictly for informational purposes - [func \(a \*AwesomeOscillatorStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#AwesomeOscillatorStrategy.Compute>) - [func \(\*AwesomeOscillatorStrategy\) Name\(\) string](<#AwesomeOscillatorStrategy.Name>) - [func \(a \*AwesomeOscillatorStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#AwesomeOscillatorStrategy.Report>) -- [type IchimokuCloudStrategy](<#IchimokuCloudStrategy>) - - [func NewIchimokuCloudStrategy\(\) \*IchimokuCloudStrategy](<#NewIchimokuCloudStrategy>) - - [func \(i \*IchimokuCloudStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#IchimokuCloudStrategy.Compute>) - - [func \(\*IchimokuCloudStrategy\) Name\(\) string](<#IchimokuCloudStrategy.Name>) - - [func \(i \*IchimokuCloudStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#IchimokuCloudStrategy.Report>) - [type RsiStrategy](<#RsiStrategy>) - [func NewRsiStrategy\(\) \*RsiStrategy](<#NewRsiStrategy>) - [func NewRsiStrategyWith\(buyAt, sellAt float64\) \*RsiStrategy](<#NewRsiStrategyWith>) @@ -164,54 +159,6 @@ func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Rep Report processes the provided asset snapshots and generates a report annotated with the recommended actions. - -## type [IchimokuCloudStrategy]() - -IchimokuCloudStrategy represents the configuration parameters for calculating the Ichimoku Cloud strategy. - -```go -type IchimokuCloudStrategy struct { - // IchimokuCloud represents the configuration parameters for calculating the Ichimoku Cloud. - IchimokuCloud *momentum.IchimokuCloud[float64] -} -``` - - -### func [NewIchimokuCloudStrategy]() - -```go -func NewIchimokuCloudStrategy() *IchimokuCloudStrategy -``` - -NewIchimokuCloudStrategy function initializes a new Ichimoku Cloud strategy with the default parameters. - - -### func \(\*IchimokuCloudStrategy\) [Compute]() - -```go -func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action -``` - -Compute processes the provided asset snapshots and generates a stream of actionable recommendations. - - -### func \(\*IchimokuCloudStrategy\) [Name]() - -```go -func (*IchimokuCloudStrategy) Name() string -``` - -Name returns the name of the strategy. - - -### func \(\*IchimokuCloudStrategy\) [Report]() - -```go -func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.Report -``` - -Report processes the provided asset snapshots and generates a report annotated with the recommended actions. - ## type [RsiStrategy]() diff --git a/strategy/momentum/ichimoku_cloud_strategy.go b/strategy/momentum/ichimoku_cloud_strategy.go deleted file mode 100644 index 152d0ed7..00000000 --- a/strategy/momentum/ichimoku_cloud_strategy.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2021-2026 Onur Cinar. -// The source code is provided under GNU AGPLv3 License. -// https://github.com/cinar/indicator - -package momentum - -import ( - "github.com/cinar/indicator/v2/asset" - "github.com/cinar/indicator/v2/helper" - "github.com/cinar/indicator/v2/momentum" - "github.com/cinar/indicator/v2/strategy" -) - -// IchimokuCloudStrategy represents the configuration parameters for calculating the Ichimoku Cloud strategy. -type IchimokuCloudStrategy struct { - // IchimokuCloud represents the configuration parameters for calculating the Ichimoku Cloud. - IchimokuCloud *momentum.IchimokuCloud[float64] -} - -// NewIchimokuCloudStrategy function initializes a new Ichimoku Cloud strategy with the default parameters. -func NewIchimokuCloudStrategy() *IchimokuCloudStrategy { - return &IchimokuCloudStrategy{ - IchimokuCloud: momentum.NewIchimokuCloud[float64](), - } -} - -// Name returns the name of the strategy. -func (*IchimokuCloudStrategy) Name() string { - return "Ichimoku Cloud Strategy" -} - -// Compute processes the provided asset snapshots and generates a stream of actionable recommendations. -func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action { - snapshotsSplice := helper.Duplicate(snapshots, 3) - - highs := asset.SnapshotsAsHighs(snapshotsSplice[0]) - lows := asset.SnapshotsAsLows(snapshotsSplice[1]) - closings := asset.SnapshotsAsClosings(snapshotsSplice[2]) - - closingsSplice := helper.Duplicate(closings, 2) - - cl, bl, lsa, lsb, ll := i.IchimokuCloud.Compute(highs, lows, closingsSplice[0]) - - // Lagging line is not used in the core logic, drain it to prevent blocking - go helper.Drain(ll) - - actions := helper.Operate5( - helper.Skip(closingsSplice[1], i.IchimokuCloud.IdlePeriod()), - cl, - bl, - lsa, - lsb, - func(c, conversion, base, spanA, spanB float64) strategy.Action { - if c > spanA && c > spanB && conversion > base && spanA > spanB { - return strategy.Buy - } - - if c < spanA && c < spanB && conversion < base && spanA < spanB { - return strategy.Sell - } - - return strategy.Hold - }, - ) - - // Shift the actions to account for the idle period - return helper.Shift(actions, i.IchimokuCloud.IdlePeriod(), strategy.Hold) -} - -// Report processes the provided asset snapshots and generates a report annotated with the recommended actions. -func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.Report { - snapshots := helper.Duplicate(c, 6) - - dates := asset.SnapshotsAsDates(snapshots[0]) - closings := asset.SnapshotsAsClosings(snapshots[2]) - highs := asset.SnapshotsAsHighs(snapshots[3]) - lows := asset.SnapshotsAsLows(snapshots[4]) - closingsForCloud := asset.SnapshotsAsClosings(snapshots[5]) - - cl, bl, lsa, lsb, ll := i.IchimokuCloud.Compute(highs, lows, closingsForCloud) - - // Lagging line is not used in the report right now, drain it. - go helper.Drain(ll) - - clShifted := helper.Shift(cl, i.IchimokuCloud.IdlePeriod(), 0) - blShifted := helper.Shift(bl, i.IchimokuCloud.IdlePeriod(), 0) - lsaShifted := helper.Shift(lsa, i.IchimokuCloud.IdlePeriod(), 0) - lsbShifted := helper.Shift(lsb, i.IchimokuCloud.IdlePeriod(), 0) - - actions, outcomes := strategy.ComputeWithOutcome(i, snapshots[1]) - annotations := strategy.ActionsToAnnotations(actions) - outcomes = helper.MultiplyBy(outcomes, 100) - - report := helper.NewReport(i.Name(), dates) - report.AddChart() - - report.AddColumn(helper.NewNumericReportColumn("Close", closings)) - report.AddColumn(helper.NewNumericReportColumn("Conversion Line", clShifted)) - report.AddColumn(helper.NewNumericReportColumn("Base Line", blShifted)) - report.AddColumn(helper.NewNumericReportColumn("Leading Span A", lsaShifted)) - report.AddColumn(helper.NewNumericReportColumn("Leading Span B", lsbShifted)) - report.AddColumn(helper.NewAnnotationReportColumn(annotations), 0, 1) - - report.AddColumn(helper.NewNumericReportColumn("Outcome", outcomes), 1) - - return report -} diff --git a/strategy/momentum/ichimoku_cloud_strategy_test.go b/strategy/momentum/ichimoku_cloud_strategy_test.go deleted file mode 100644 index e00cdb2d..00000000 --- a/strategy/momentum/ichimoku_cloud_strategy_test.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2021-2026 Onur Cinar. -// The source code is provided under GNU AGPLv3 License. -// https://github.com/cinar/indicator - -package momentum_test - -import ( - "testing" - - "github.com/cinar/indicator/v2/asset" - "github.com/cinar/indicator/v2/helper" - "github.com/cinar/indicator/v2/strategy" - "github.com/cinar/indicator/v2/strategy/momentum" -) - -func TestIchimokuCloudStrategy(t *testing.T) { - snapshots, err := helper.ReadFromCsvFile[asset.Snapshot]("testdata/brk-b.csv") - if err != nil { - t.Fatal(err) - } - - results, err := helper.ReadFromCsvFile[strategy.Result]("testdata/ichimoku_cloud_strategy.csv") - if err != nil { - t.Fatal(err) - } - - expected := helper.Map(results, func(r *strategy.Result) strategy.Action { return r.Action }) - - ic := momentum.NewIchimokuCloudStrategy() - actual := ic.Compute(snapshots) - - err = helper.CheckEquals(actual, expected) - if err != nil { - t.Fatal(err) - } -} - -func TestIchimokuCloudStrategyReport(t *testing.T) { - snapshots, err := helper.ReadFromCsvFile[asset.Snapshot]("testdata/brk-b.csv") - if err != nil { - t.Fatal(err) - } - - ic := momentum.NewIchimokuCloudStrategy() - - report := ic.Report(snapshots) - - fileName := "ichimoku_cloud_strategy.html" - defer helper.Remove(t, fileName) - - err = report.WriteToFile(fileName) - if err != nil { - t.Fatal(err) - } -} \ No newline at end of file diff --git a/strategy/momentum/momentum.go b/strategy/momentum/momentum.go index 8a17e7bf..c53a559d 100644 --- a/strategy/momentum/momentum.go +++ b/strategy/momentum/momentum.go @@ -24,7 +24,6 @@ import "github.com/cinar/indicator/v2/strategy" func AllStrategies() []strategy.Strategy { return []strategy.Strategy{ NewAwesomeOscillatorStrategy(), - NewIchimokuCloudStrategy(), NewRsiStrategy(), NewStochasticRsiStrategy(), NewTripleRsiStrategy(), diff --git a/strategy/momentum/testdata/ichimoku_cloud_strategy.csv b/strategy/momentum/testdata/ichimoku_cloud_strategy.csv deleted file mode 100644 index 45ab317c..00000000 --- a/strategy/momentum/testdata/ichimoku_cloud_strategy.csv +++ /dev/null @@ -1,252 +0,0 @@ -Action -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 --1 --1 --1 --1 --1 --1 --1 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 --1 --1 -0 --1 --1 --1 --1 -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 -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 -0 -0 -0 -0 -0 -0 -1 -1 -0 -0 -0 -1 -0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -1 -1 -1