From 59b54d0a58aeab30575cfa74736231b8f3d8b0e1 Mon Sep 17 00:00:00 2001 From: Onur Cinar Date: Wed, 16 Oct 2024 17:31:10 -0700 Subject: [PATCH] Apply fixes. --- strategy/volume/README.md | 6 +- .../volume/chaikin_money_flow_strategy.go | 10 +- .../testdata/chaikin_money_flow_strategy.csv | 286 +++++++++--------- 3 files changed, 151 insertions(+), 151 deletions(-) diff --git a/strategy/volume/README.md b/strategy/volume/README.md index 6d4ea7a..d61b5bb 100644 --- a/strategy/volume/README.md +++ b/strategy/volume/README.md @@ -66,7 +66,7 @@ AllStrategies returns a slice containing references to all available volume stra ## type [ChaikinMoneyFlowStrategy]() -ChaikinMoneyFlowStrategy represents the configuration parameters for calculating the Chaikin Money Flow strategy. Recommends a Sell action when it crosses above 0, and recommends a Buy action when it crosses below 0. +ChaikinMoneyFlowStrategy represents the configuration parameters for calculating the Chaikin Money Flow strategy. Recommends a Buy action when it crosses above 0, and recommends a Sell action when it crosses below 0. ```go type ChaikinMoneyFlowStrategy struct { @@ -82,7 +82,7 @@ type ChaikinMoneyFlowStrategy struct { func NewChaikinMoneyFlowStrategy() *ChaikinMoneyFlowStrategy ``` -NewChaikinMoneyFlowStrategy function initializes a new Money Flow Index strategy instance with the default parameters. +NewChaikinMoneyFlowStrategy function initializes a new Chaikin Money Flow strategy instance with the default parameters. ### func [NewChaikinMoneyFlowStrategyWith]() @@ -91,7 +91,7 @@ NewChaikinMoneyFlowStrategy function initializes a new Money Flow Index strategy func NewChaikinMoneyFlowStrategyWith(period int) *ChaikinMoneyFlowStrategy ``` -NewChaikinMoneyFlowStrategyWith function initializes a new Money Flow Index strategy instance with the given parameters. +NewChaikinMoneyFlowStrategyWith function initializes a new Chaikin Money Flow strategy instance with the given parameters. ### func \(\*ChaikinMoneyFlowStrategy\) [Compute]() diff --git a/strategy/volume/chaikin_money_flow_strategy.go b/strategy/volume/chaikin_money_flow_strategy.go index 18f308e..e48df18 100644 --- a/strategy/volume/chaikin_money_flow_strategy.go +++ b/strategy/volume/chaikin_money_flow_strategy.go @@ -14,13 +14,13 @@ import ( ) // ChaikinMoneyFlowStrategy represents the configuration parameters for calculating the Chaikin Money Flow strategy. -// Recommends a Sell action when it crosses above 0, and recommends a Buy action when it crosses below 0. +// Recommends a Buy action when it crosses above 0, and recommends a Sell action when it crosses below 0. type ChaikinMoneyFlowStrategy struct { // ChaikinMoneyFlow is the Chaikin Money Flow indicator instance. ChaikinMoneyFlow *volume.Cmf[float64] } -// NewChaikinMoneyFlowStrategy function initializes a new Money Flow Index strategy instance with the +// NewChaikinMoneyFlowStrategy function initializes a new Chaikin Money Flow strategy instance with the // default parameters. func NewChaikinMoneyFlowStrategy() *ChaikinMoneyFlowStrategy { return NewChaikinMoneyFlowStrategyWith( @@ -28,7 +28,7 @@ func NewChaikinMoneyFlowStrategy() *ChaikinMoneyFlowStrategy { ) } -// NewChaikinMoneyFlowStrategyWith function initializes a new Money Flow Index strategy instance with the +// NewChaikinMoneyFlowStrategyWith function initializes a new Chaikin Money Flow strategy instance with the // given parameters. func NewChaikinMoneyFlowStrategyWith(period int) *ChaikinMoneyFlowStrategy { return &ChaikinMoneyFlowStrategy{ @@ -53,11 +53,11 @@ func (c *ChaikinMoneyFlowStrategy) Compute(snapshots <-chan *asset.Snapshot) <-c cmfs := c.ChaikinMoneyFlow.Compute(highs, lows, closings, volumes) actions := helper.Map(cmfs, func(cmf float64) strategy.Action { - if cmf < 0 { + if cmf > 0 { return strategy.Buy } - if cmf > 0 { + if cmf < 0 { return strategy.Sell } diff --git a/strategy/volume/testdata/chaikin_money_flow_strategy.csv b/strategy/volume/testdata/chaikin_money_flow_strategy.csv index c2c15cd..5d76f77 100644 --- a/strategy/volume/testdata/chaikin_money_flow_strategy.csv +++ b/strategy/volume/testdata/chaikin_money_flow_strategy.csv @@ -18,105 +18,10 @@ Action 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 @@ -125,47 +30,90 @@ Action 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 @@ -177,19 +125,6 @@ Action -1 -1 -1 --1 --1 --1 -1 --1 -1 --1 -1 -1 --1 -1 --1 -1 1 1 1 @@ -200,6 +135,7 @@ Action 1 1 1 +-1 1 1 1 @@ -213,9 +149,14 @@ Action 1 1 1 +-1 1 1 +-1 +-1 +-1 1 +-1 1 1 1 @@ -225,6 +166,9 @@ Action 1 1 1 +-1 +-1 +-1 1 1 1 @@ -236,9 +180,14 @@ Action 1 1 1 +-1 1 +-1 1 +-1 +-1 1 +-1 1 -1 -1 @@ -250,3 +199,54 @@ Action -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