├── .gitignore
├── LICENSE
├── src
├── .project
├── .settings
│ └── org.eclipse.cdt.codan.core.prefs
├── PatternRecognitionLib.pro
├── chartSegment
│ ├── ANDSegmentConstraint.cpp
│ ├── ANDSegmentConstraint.h
│ ├── ChartSegment.cpp
│ ├── ChartSegment.h
│ ├── SegmentConstraint.h
│ ├── SegmentValsCloseToLinearEq.cpp
│ ├── SegmentValsCloseToLinearEq.h
│ ├── SlopeWithinRangeConstraint.cpp
│ └── SlopeWithinRangeConstraint.h
├── chartSegmentList
│ ├── AnySegmentListValidConstraint.cpp
│ ├── AnySegmentListValidConstraint.h
│ ├── SegmentListConstraint.cpp
│ ├── SegmentListConstraint.h
│ ├── SlopeIncreasesConstraint.cpp
│ └── SlopeIncreasesConstraint.h
├── date
│ ├── DateValue.cpp
│ ├── DateValue.h
│ ├── TimeHelper.cpp
│ └── TimeHelper.h
├── log
│ └── DebugLog.h
├── math
│ ├── DoubleRange.cpp
│ ├── DoubleRange.h
│ ├── LinearEquation.cpp
│ ├── LinearEquation.h
│ ├── MathHelper.cpp
│ ├── MathHelper.h
│ ├── UnsignedIntRange.cpp
│ ├── UnsignedIntRange.h
│ ├── ValueComparator.h
│ ├── XYCoord.cpp
│ └── XYCoord.h
├── patternMatch
│ ├── AscendingTrianglePatternMatch.cpp
│ ├── AscendingTrianglePatternMatch.h
│ ├── CupPatternMatch.cpp
│ ├── CupPatternMatch.h
│ ├── CupWithHandlePatternMatch.cpp
│ ├── CupWithHandlePatternMatch.h
│ ├── CupWithoutHandlePatternMatch.cpp
│ ├── CupWithoutHandlePatternMatch.h
│ ├── DescendingTrianglePatternMatch.cpp
│ ├── DescendingTrianglePatternMatch.h
│ ├── DoubleBottomPatternMatch.cpp
│ ├── DoubleBottomPatternMatch.h
│ ├── FallingWedgePatternMatch.cpp
│ ├── FallingWedgePatternMatch.h
│ ├── PatternMatch.cpp
│ ├── PatternMatch.h
│ ├── PatternMatchBreakoutInfo.cpp
│ ├── PatternMatchBreakoutInfo.h
│ ├── PatternMatchVisitor.cpp
│ ├── PatternMatchVisitor.h
│ ├── RectanglePatternMatch.cpp
│ ├── RectanglePatternMatch.h
│ ├── RisingWedgePatternMatch.cpp
│ ├── RisingWedgePatternMatch.h
│ ├── SymetricTrianglePatternMatch.cpp
│ ├── SymetricTrianglePatternMatch.h
│ ├── TrianglePatternMatch.cpp
│ ├── TrianglePatternMatch.h
│ ├── VPatternMatch.cpp
│ ├── VPatternMatch.h
│ ├── WedgePatternMatch.cpp
│ └── WedgePatternMatch.h
├── patternMatchFilter
│ ├── PatternMatchFilter.cpp
│ ├── PatternMatchFilter.h
│ ├── PatternMatchFindPredicate.cpp
│ ├── PatternMatchFindPredicate.h
│ ├── PatternMatchSortFunctor.cpp
│ ├── PatternMatchSortFunctor.h
│ ├── PatternMatchUniqueFunctor.cpp
│ └── PatternMatchUniqueFunctor.h
├── patternMatchValidator
│ ├── ANDPatternMatchValidator.cpp
│ ├── ANDPatternMatchValidator.h
│ ├── AnyPatternMatchValidator.cpp
│ ├── AnyPatternMatchValidator.h
│ ├── BreakoutAboveFirstHighValidatorFactory.cpp
│ ├── BreakoutAboveFirstHighValidatorFactory.h
│ ├── CloseWithinPercentOfDepthFromFirstHighValidator.cpp
│ ├── CloseWithinPercentOfDepthFromFirstHighValidator.h
│ ├── CompositePatternMatchValidatorFactory.cpp
│ ├── CompositePatternMatchValidatorFactory.h
│ ├── EndWithinPercentOfStart.cpp
│ ├── EndWithinPercentOfStart.h
│ ├── HigherLowPatternMatchValidatorFactory.cpp
│ ├── HigherLowPatternMatchValidatorFactory.h
│ ├── HighestHighLessThanFirstHigh.cpp
│ ├── HighestHighLessThanFirstHigh.h
│ ├── LastValueAbovePointValue.cpp
│ ├── LastValueAbovePointValue.h
│ ├── LowerHighPatternMatchValidatorFactory.cpp
│ ├── LowerHighPatternMatchValidatorFactory.h
│ ├── LowestLowGreaterThanLastLow.cpp
│ ├── LowestLowGreaterThanLastLow.h
│ ├── ORPatternMatchValidator.cpp
│ ├── ORPatternMatchValidator.h
│ ├── PatternLengthAtLeast.cpp
│ ├── PatternLengthAtLeast.h
│ ├── PatternLengthLessThanEqual.cpp
│ ├── PatternLengthLessThanEqual.h
│ ├── PatternMatchValidator.cpp
│ ├── PatternMatchValidator.h
│ ├── PatternMatchValidatorCreationHelper.cpp
│ ├── PatternMatchValidatorCreationHelper.h
│ ├── PatternMatchValidatorFactory.cpp
│ ├── PatternMatchValidatorFactory.h
│ ├── PatternMatchValueRef.cpp
│ ├── PatternMatchValueRef.h
│ ├── PatternSegmentValsCloseToLinearEq.cpp
│ ├── PatternSegmentValsCloseToLinearEq.h
│ ├── PatternSlopeWithinRange.cpp
│ ├── PatternSlopeWithinRange.h
│ ├── PercentIntersectingPatternLineValidator.cpp
│ ├── PercentIntersectingPatternLineValidator.h
│ ├── PrevPatternDepthThreshold.cpp
│ ├── PrevPatternDepthThreshold.h
│ ├── PrevPatternValueCompareValidatorFactory.cpp
│ ├── PrevPatternValueCompareValidatorFactory.h
│ ├── PrevPatternValueRatioValidatorFactory.cpp
│ ├── PrevPatternValueRatioValidatorFactory.h
│ ├── RecoverPercentOfDepth.cpp
│ ├── RecoverPercentOfDepth.h
│ ├── SecondPeriodValuePivotsLower.cpp
│ ├── SecondPeriodValuePivotsLower.h
│ ├── StaticPatternMatchValidatorFactory.cpp
│ ├── StaticPatternMatchValidatorFactory.h
│ ├── ValueComparisonMatchValidator.cpp
│ ├── ValueComparisonMatchValidator.h
│ ├── ValuesCloseToTrendLineValidatorMathComment.pdf
│ ├── ValuesCloseToTrendlineValidator.cpp
│ └── ValuesCloseToTrendlineValidator.h
├── patternScan
│ ├── AscendingBasePullbackScanner.cpp
│ ├── AscendingBasePullbackScanner.h
│ ├── AscendingBaseScanner.cpp
│ ├── AscendingBaseScanner.h
│ ├── AscendingTriangleScanner.cpp
│ ├── AscendingTriangleScanner.h
│ ├── CupScanner.cpp
│ ├── CupScanner.h
│ ├── CupWithHandleScanner.cpp
│ ├── CupWithHandleScanner.h
│ ├── CupWithoutHandleScanner.cpp
│ ├── CupWithoutHandleScanner.h
│ ├── DescendingTriangleScanner.cpp
│ ├── DescendingTriangleScanner.h
│ ├── DoubleBottomScanner.cpp
│ ├── DoubleBottomScanner.h
│ ├── FallingWedgeScanner.cpp
│ ├── FallingWedgeScanner.h
│ ├── InvertedVScanner.cpp
│ ├── InvertedVScanner.h
│ ├── MultiPatternScanner.cpp
│ ├── MultiPatternScanner.h
│ ├── PatternScanner.h
│ ├── PatternScannerEngine.cpp
│ ├── PatternScannerEngine.h
│ ├── PivotHighScanner.cpp
│ ├── PivotHighScanner.h
│ ├── PivotLowScanner.cpp
│ ├── PivotLowScanner.h
│ ├── RectangleScanner.cpp
│ ├── RectangleScanner.h
│ ├── RisingWedgeScanner.cpp
│ ├── RisingWedgeScanner.h
│ ├── ScannerHelper.cpp
│ ├── ScannerHelper.h
│ ├── SingleSegmentPatternScannerEngine.cpp
│ ├── SingleSegmentPatternScannerEngine.h
│ ├── SymetricTriangleScanner.cpp
│ ├── SymetricTriangleScanner.h
│ ├── TrendLineScanner.cpp
│ ├── TrendLineScanner.h
│ ├── TriangleScanner.cpp
│ ├── TriangleScanner.h
│ ├── VScanner.cpp
│ ├── VScanner.h
│ ├── WedgeMatchValidationInfo.cpp
│ ├── WedgeMatchValidationInfo.h
│ ├── WedgeScanner.cpp
│ ├── WedgeScanner.h
│ ├── WedgeScannerEngine.cpp
│ └── WedgeScannerEngine.h
├── patternShape
│ ├── PatternShape.cpp
│ ├── PatternShape.h
│ ├── PatternShapeCurveGenerator.cpp
│ ├── PatternShapeCurveGenerator.h
│ ├── PatternShapeGenerator.cpp
│ ├── PatternShapeGenerator.h
│ ├── PatternShapePoint.cpp
│ └── PatternShapePoint.h
└── quoteData
│ ├── PerValCltnSlidingWindow.cpp
│ ├── PerValCltnSlidingWindow.h
│ ├── PeriodVal.cpp
│ ├── PeriodVal.h
│ ├── PeriodValSegment.cpp
│ ├── PeriodValSegment.h
│ ├── PeriodValueRef.cpp
│ └── PeriodValueRef.h
└── test
├── .project
├── .settings
└── org.eclipse.ltk.core.refactoring.prefs
├── README.md
├── RunTests.cpp
├── TestHelper.cpp
├── TestHelper.h
├── TestPatternRecognitionLib.pro
├── TestPerValRange.cpp
├── TestPerValRange.h
├── math
├── LinearEquation.cpp
└── XYCoord.cpp
├── patternMatch
├── PatternMatch.cpp
└── PatternMatchValidator.cpp
├── patternMatchFilter
└── PatternMatchFilter.cpp
├── patternScan
├── AAPL_Daily_2013.csv
├── AMBA_Daily_2014.csv
├── AscendingBase.cpp
├── CELG_20140501_20140813_Daily.png
├── CELG_20140501_20140814_Daily.csv
├── CMG_Daily.csv
├── CupWithHandle.cpp
├── CupWithoutHandle.cpp
├── DoubleBottom.cpp
├── GBX_Daily.csv
├── GBX_Daily_2014.csv
├── GLD_Weekly_2013_2014.csv
├── GMCR_Daily_2014.csv
├── MultiPatternScan.cpp
├── PivotScanner.cpp
├── QCOR_DoubleBottom_Weekly.csv
├── QCOR_DoubleBottom_Weekly.png
├── SAVE_Cup_Weekly_20130722_20131028.csv
├── SAVE_Cup_Weekly_20130722_20131028.png
├── SAVE_Weekly_2013.csv
├── SAVE_Weekly_2013.png
├── TrendLine.cpp
├── TriangleScanners.cpp
├── VScanner.cpp
├── VZ_SymTriangle_2013_2014_Weekly.png
├── VZ_SymTriangle_Weekly_2013_2014.csv
├── VZ_Weekly_Nov2013_May2014.csv
└── WedgeScanners.cpp
├── patternShape
├── PatternShape.cpp
└── QCOR_2013_2014_Weekly.csv
└── quoteData
├── CorruptDate.csv
├── CorruptVal.csv
├── GoogleFormatAAPL-Short.csv
├── GoogleFormatAAPL.csv
├── GoogleFormatCELG.csv
├── MalformedHeader.csv
├── MalformedHeaderNoCloseField.csv
├── MissingField.csv
├── MissingHeader.csv
├── PeriodVal.cpp
├── PeriodValSegment.cpp
├── eodDataFormat_AAPL_20140101_20141117.csv
├── yLoaderFormatAAPL.csv
└── yahooFormatAAPL.csv
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Specific binaries
3 | PatternRecognitionLibTest
4 |
5 | *.o
6 | *.a
7 |
8 | # Locally stored "Eclipse launch configurations"
9 | *.launch
10 |
11 | # CDT-specific
12 | .cproject
13 |
14 | # PDT-specific
15 | .buildpath
16 |
17 | # Qt Creator project and build files
18 | *.pro.user
19 | src/build-*
20 | test/build-*
21 | build-*
22 |
23 | *.pro.user.*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Steve Roehling
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PatternRecognitionLib
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/chartSegment/ANDSegmentConstraint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ANDSegmentContraint.cpp
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 |
11 |
12 | ANDSegmentConstraint::ANDSegmentConstraint(const SegmentConstraintList &constraints)
13 | : constraints_(constraints)
14 | {
15 | }
16 |
17 | bool ANDSegmentConstraint::validSegment(const ChartSegment &segment)
18 | {
19 | for(SegmentConstraintList::const_iterator conIter = constraints_.begin();
20 | conIter != constraints_.end(); conIter++)
21 | {
22 | if(!((*conIter)->validSegment(segment)))
23 | {
24 | return false;
25 | }
26 | }
27 | return true;
28 | }
29 |
30 | ANDSegmentConstraint::~ANDSegmentConstraint() {
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/chartSegment/ANDSegmentConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ANDSegmentContraint.h
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ANDSEGMENTCONSTRAINT_H_
9 | #define ANDSEGMENTCONSTRAINT_H_
10 |
11 | #include
12 |
13 | // SegmentContraint where validSegment() performs a boolean
14 | // AND on all the other contraints in the given
15 | // SegmentConstraintList.
16 | class ANDSegmentConstraint: public SegmentConstraint {
17 | private:
18 | SegmentConstraintList constraints_;
19 | public:
20 | ANDSegmentConstraint(const SegmentConstraintList &constraints);
21 | virtual bool validSegment(const ChartSegment &segment);
22 | virtual ~ANDSegmentConstraint();
23 | };
24 |
25 | #endif /* ANDSEGMENTCONSTRAINT_H_ */
26 |
--------------------------------------------------------------------------------
/src/chartSegment/ChartSegment.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ChartSegment.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef CHARTSEGMENT_H_
9 | #define CHARTSEGMENT_H_
10 |
11 | #include
12 |
13 | #include "PeriodValSegment.h"
14 | #include "LinearEquation.h"
15 |
16 | // TODO Change name to TrendLine or similar - This class is used as more of a trend line
17 | // than "Chart Segment".
18 | class ChartSegment {
19 | private:
20 | PeriodValSegmentPtr segmentVals_;
21 | LinearEquationPtr segmentEq_;
22 | PeriodValueRefPtr perValRef_;
23 |
24 | double absRelPercentVal(double comparisonVal, double baseVal) const;
25 | public:
26 | ChartSegment(const PeriodValSegmentPtr &segmentVals);
27 |
28 | ChartSegment(const PeriodValCltnPtr &perValCltn,
29 | const PeriodValCltn::iterator &startPt,
30 | const PeriodValCltn::iterator &endPt,
31 | const PeriodValueRefPtr &endPtValueRef);
32 |
33 | const PeriodVal &lastPeriodVal() const;
34 | const PeriodValCltn::iterator lastValIter() const;
35 |
36 | const PeriodVal &firstPeriodVal() const;
37 | const PeriodValCltn::iterator &firstValIter() const;
38 |
39 | double maxRelPercentVsLinearEq() const;
40 | unsigned int numPeriods() const;
41 | const PeriodValSegmentPtr &perValSegment() const { return segmentVals_; }
42 | const LinearEquationPtr &segmentEq() const { return segmentEq_; }
43 |
44 | double slope() const;
45 |
46 | // Relative to the first value, how much the price is changing per year?
47 | // This CAGR serves as a "normalized" slope calculation which can be useful for trendline
48 | // slope validation. These values are per calendar year, not trading days/weeks.
49 | // Using %change in price is considered a more normalized slope calculation,
50 | // since the regular slope() function returns a slope dependent upon whatever the
51 | // price range is for the given data set.
52 | double percentChangePerYear() const;
53 |
54 | friend std::ostream& operator<<(std::ostream& os, const ChartSegment& chartSeg);
55 |
56 |
57 | virtual ~ChartSegment();
58 | };
59 |
60 | typedef boost::shared_ptr ChartSegmentPtr;
61 | typedef std::vector ChartSegmentList;
62 |
63 | #endif /* CHARTSEGMENT_H_ */
64 |
--------------------------------------------------------------------------------
/src/chartSegment/SegmentConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SegmentConstraint.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SEGMENTCONSTRAINT_H_
9 | #define SEGMENTCONSTRAINT_H_
10 |
11 | #include
12 | #include "ChartSegment.h"
13 |
14 | class SegmentConstraint {
15 | public:
16 | virtual bool validSegment(const ChartSegment &segment) = 0;
17 | virtual ~SegmentConstraint() {}
18 | };
19 |
20 | typedef boost::shared_ptr SegmentConstraintPtr;
21 | typedef std::list SegmentConstraintList;
22 |
23 | #endif /* SEGMENTCONSTRAINT_H_ */
24 |
--------------------------------------------------------------------------------
/src/chartSegment/SegmentValsCloseToLinearEq.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SegmentValsCloseToLinearEq.cpp
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "SegmentValsCloseToLinearEq.h"
9 |
10 | SegmentValsCloseToLinearEq::SegmentValsCloseToLinearEq(double maxDeltaPercVsEquation)
11 | : maxDeltaPercVsEquation_(maxDeltaPercVsEquation)
12 | {
13 | assert(maxDeltaPercVsEquation > 0.0);
14 | }
15 |
16 | bool SegmentValsCloseToLinearEq::validSegment(const ChartSegment &segment)
17 | {
18 | if(segment.maxRelPercentVsLinearEq() <= maxDeltaPercVsEquation_)
19 | {
20 | return true;
21 | }
22 | else
23 | {
24 | return false;
25 | }
26 | }
27 |
28 | SegmentValsCloseToLinearEq::~SegmentValsCloseToLinearEq() {
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/chartSegment/SegmentValsCloseToLinearEq.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SegmentValsCloseToLinearEq.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SEGMENTVALSCLOSETOLINEAREQ_H_
9 | #define SEGMENTVALSCLOSETOLINEAREQ_H_
10 |
11 | #include "SegmentConstraint.h"
12 |
13 | class SegmentValsCloseToLinearEq: public SegmentConstraint {
14 | private:
15 | double maxDeltaPercVsEquation_;
16 | public:
17 | SegmentValsCloseToLinearEq(double maxDeltaPercVsEquation);
18 |
19 | bool validSegment(const ChartSegment &segment);
20 |
21 | virtual ~SegmentValsCloseToLinearEq();
22 | };
23 |
24 | #endif /* SEGMENTVALSCLOSETOLINEAREQ_H_ */
25 |
--------------------------------------------------------------------------------
/src/chartSegment/SlopeWithinRangeConstraint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SlopeWithinRangeConstraint.cpp
3 | *
4 | * Created on: Jun 17, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | SlopeWithinRangeConstraint::SlopeWithinRangeConstraint(const DoubleRange &slopeRange)
11 | : slopeRange_(slopeRange)
12 | {
13 | }
14 |
15 | bool SlopeWithinRangeConstraint::validSegment(const ChartSegment &segment)
16 | {
17 | if((segment.slope() >= slopeRange_.minVal()) && (segment.slope() <= slopeRange_.maxVal()))
18 | {
19 | return true;
20 | }
21 | else
22 | {
23 | return false;
24 | }
25 | }
26 |
27 | SlopeWithinRangeConstraint::~SlopeWithinRangeConstraint() {
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/src/chartSegment/SlopeWithinRangeConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SlopeWithinRangeConstraint.h
3 | *
4 | * Created on: Jun 17, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SLOPEWITHINRANGECONSTRAINT_H_
9 | #define SLOPEWITHINRANGECONSTRAINT_H_
10 |
11 | #include
12 | #include "DoubleRange.h"
13 |
14 | class SlopeWithinRangeConstraint: public SegmentConstraint {
15 | private:
16 | DoubleRange slopeRange_;
17 | public:
18 | SlopeWithinRangeConstraint(const DoubleRange &slopeRange);
19 |
20 | bool validSegment(const ChartSegment &segment);
21 |
22 | virtual ~SlopeWithinRangeConstraint();
23 | };
24 |
25 | #endif /* SLOPEWITHINRANGECONSTRAINT_H_ */
26 |
--------------------------------------------------------------------------------
/src/chartSegmentList/AnySegmentListValidConstraint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * AnySegmentListValidConstraint.cpp
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | AnySegmentListValidConstraint::AnySegmentListValidConstraint() {
11 | }
12 |
13 | bool AnySegmentListValidConstraint::validSegments(const ChartSegmentList &)
14 | {
15 | return true;
16 | }
17 |
18 | AnySegmentListValidConstraint::~AnySegmentListValidConstraint() {
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/chartSegmentList/AnySegmentListValidConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AnySegmentListValidConstraint.h
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ANYSEGMENTLISTVALIDCONSTRAINT_H_
9 | #define ANYSEGMENTLISTVALIDCONSTRAINT_H_
10 |
11 | #include
12 |
13 | // SegmentListConstraint for testing - validSegments() always
14 | // returns true.
15 | class AnySegmentListValidConstraint: public SegmentListConstraint {
16 | public:
17 | AnySegmentListValidConstraint();
18 | virtual bool validSegments(const ChartSegmentList &segments);
19 | virtual ~AnySegmentListValidConstraint();
20 | };
21 |
22 | #endif /* ANYSEGMENTLISTVALIDCONSTRAINT_H_ */
23 |
--------------------------------------------------------------------------------
/src/chartSegmentList/SegmentListConstraint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SegmentListConstraint.cpp
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "SegmentListConstraint.h"
9 |
10 | SegmentListConstraint::SegmentListConstraint() {
11 | }
12 |
13 | SegmentListConstraint::~SegmentListConstraint() {
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/src/chartSegmentList/SegmentListConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SegmentListConstraint.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SEGMENTLISTCONSTRAINT_H_
9 | #define SEGMENTLISTCONSTRAINT_H_
10 |
11 | #include
12 | #include "ChartSegment.h"
13 |
14 | class SegmentListConstraint {
15 | public:
16 | SegmentListConstraint();
17 |
18 | virtual bool validSegments(const ChartSegmentList &segments) = 0;
19 |
20 | virtual ~SegmentListConstraint();
21 | };
22 |
23 | typedef boost::shared_ptr SegmentListConstraintPtr;
24 |
25 | #endif /* SEGMENTLISTCONSTRAINT_H_ */
26 |
--------------------------------------------------------------------------------
/src/chartSegmentList/SlopeIncreasesConstraint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SlopeIncreasesConstraint.cpp
3 | *
4 | * Created on: Jun 12, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "MathHelper.h"
10 |
11 | SlopeIncreasesConstraint::SlopeIncreasesConstraint() {
12 | }
13 |
14 |
15 | bool SlopeIncreasesConstraint::validSegments(const ChartSegmentList &segments)
16 | {
17 | double lastSlope = MathHelper::minDouble();
18 | for(ChartSegmentList::const_iterator segIter = segments.begin();
19 | segIter != segments.end(); segIter++)
20 | {
21 | double currSlope = (*segIter)->slope();
22 | if(currSlope < lastSlope)
23 | {
24 | return false;
25 | }
26 | lastSlope = currSlope;
27 | }
28 | return true;
29 | }
30 |
31 |
32 | SlopeIncreasesConstraint::~SlopeIncreasesConstraint() {
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/chartSegmentList/SlopeIncreasesConstraint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SlopeIncreasesConstraint.h
3 | *
4 | * Created on: Jun 12, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SLOPEINCREASESCONSTRAINT_H_
9 | #define SLOPEINCREASESCONSTRAINT_H_
10 |
11 | #include "SegmentListConstraint.h"
12 |
13 | class SlopeIncreasesConstraint: public SegmentListConstraint {
14 | public:
15 | SlopeIncreasesConstraint();
16 |
17 | virtual bool validSegments(const ChartSegmentList &segments);
18 |
19 | virtual ~SlopeIncreasesConstraint();
20 | };
21 |
22 | #endif /* SLOPEINCREASESCONSTRAINT_H_ */
23 |
--------------------------------------------------------------------------------
/src/date/DateValue.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * DateValue.cpp
3 | *
4 | * Created on: Jun 6, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "DateValue.h"
9 |
10 | DateValue::DateValue(const boost::gregorian::date &date, double value)
11 | : date_(date), value_(value)
12 | {
13 | }
14 |
15 | double DateValue::value()
16 | {
17 | return value_;
18 | }
19 |
20 | const boost::gregorian::date &DateValue::date()
21 | {
22 | return date_;
23 | }
24 |
25 |
26 | DateValue::~DateValue() {
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/date/DateValue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DateValue.h
3 | *
4 | * Created on: Jun 6, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef DATEVALUE_H_
9 | #define DATEVALUE_H_
10 |
11 | #include
12 |
13 | class DateValue {
14 | private:
15 | boost::gregorian::date date_;
16 | double value_;
17 | public:
18 | DateValue(const boost::gregorian::date &date, double value);
19 |
20 | double value();
21 | const boost::gregorian::date &date();
22 |
23 | virtual ~DateValue();
24 | };
25 |
26 | #endif /* DATEVALUE_H_ */
27 |
--------------------------------------------------------------------------------
/src/date/TimeHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DateHelper.h
3 | *
4 | * Created on: Jul 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef TIMEHELPER_H_
9 | #define TIMEHELPER_H_
10 |
11 | #include
12 | #include "DoubleRange.h"
13 |
14 | namespace timeHelper {
15 |
16 | std::string formatDate(const boost::posix_time::ptime &dateToFormat);
17 |
18 | boost::posix_time::ptime parseDateFromString(const std::string &dateStr);
19 | bool findDateInString(const std::string &dateStr, boost::posix_time::ptime &foundDate);
20 |
21 | double timeDifferenceMsec(const boost::posix_time::ptime &startTime, const boost::posix_time::ptime &endTime);
22 | bool timeDifferenceValid(const DoubleRange &validTimeDifferences,
23 | const boost::posix_time::ptime &startTime, const boost::posix_time::ptime &endTime);
24 |
25 | double msecToDays(double msecs);
26 |
27 | } // namespace timeHelper
28 |
29 | #endif /* DATEHELPER_H_ */
30 |
--------------------------------------------------------------------------------
/src/log/DebugLog.h:
--------------------------------------------------------------------------------
1 | #ifndef DEBUGLOG_H
2 | #define DEBUGLOG_H
3 |
4 | #ifndef NDEBUG
5 | #define DEBUG_MSG(msg) std::cerr << msg << std::endl;
6 | #else
7 | #define DEBUG_MSG(msg)
8 | #endif
9 |
10 | #endif // DEBUGLOG_H
11 |
--------------------------------------------------------------------------------
/src/math/DoubleRange.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * DoubleRange.cpp
3 | *
4 | * Created on: Jul 8, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include
10 |
11 | DoubleRange::DoubleRange(double minVal, double maxVal)
12 | : minVal_(minVal),
13 | maxVal_(maxVal)
14 | {
15 | assert(maxVal >= minVal);
16 | }
17 |
18 | double DoubleRange::percentWithinRange(double val) const
19 | {
20 | assert(val >= minVal_);
21 | assert(val <= maxVal_);
22 |
23 | if(maxVal_==minVal_) { return 1.0; }
24 |
25 | double range = maxVal_-minVal_;
26 |
27 | return (val-minVal_)/range;
28 | }
29 |
30 | double DoubleRange::percentMidpointVal(double percMid) const
31 | {
32 | assert(percMid >=0.0);
33 | assert(percMid <= 1.0);
34 |
35 | double deltaVal = maxVal_-minVal_;
36 |
37 | return minVal_ + percMid * deltaVal;
38 | }
39 |
40 | std::ostream& operator<<(std::ostream& os, const DoubleRange& range)
41 | {
42 | os << "DoubleRange("
43 | << "min=" << range.minVal_
44 | << ",max=" << range.maxVal_
45 | << ")";
46 | return os;
47 | }
48 |
--------------------------------------------------------------------------------
/src/math/DoubleRange.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DoubleRange.h
3 | *
4 | * Created on: Jul 8, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef DOUBLERANGE_H_
9 | #define DOUBLERANGE_H_
10 |
11 | #include
12 |
13 | class DoubleRange {
14 | private:
15 | double minVal_;
16 | double maxVal_;
17 | public:
18 | DoubleRange(double minVal, double maxVal);
19 |
20 | double minVal() const { return minVal_; }
21 | double maxVal() const { return maxVal_; }
22 |
23 | bool positiveVals() const { return (minVal() >= 0.0) && (maxVal() >=0.0); }
24 | bool valueWithinRange(double val) const { return (val >= minVal()) && (val <= maxVal()); }
25 |
26 | double percentWithinRange(double val) const;
27 |
28 | double percentMidpointVal(double percMid) const;
29 |
30 | friend std::ostream& operator<<(std::ostream& os, const DoubleRange& range);
31 |
32 | virtual ~DoubleRange() {}
33 | };
34 |
35 | #endif /* DOUBLERANGE_H_ */
36 |
--------------------------------------------------------------------------------
/src/math/LinearEquation.cpp:
--------------------------------------------------------------------------------
1 | #include "LinearEquation.h"
2 |
3 |
4 | LinearEquation::LinearEquation(double m, double b)
5 | : m_(m), b_(b)
6 | {
7 | }
8 |
9 | LinearEquation::LinearEquation(const XYCoord &startPt, const XYCoord &endPt)
10 | {
11 | double changeX = endPt.x()-startPt.x();
12 | double changeY = endPt.y()-startPt.y();
13 | assert(changeX != 0.0);
14 |
15 | m_ = changeY/changeX;
16 |
17 | // y = mx + b
18 | // b = y - mx
19 | b_ = endPt.y()-(m_*endPt.x());
20 | }
21 |
22 | double LinearEquation::slope() const
23 | {
24 | return m_;
25 | }
26 |
27 | double LinearEquation::yVal(double x) const
28 | {
29 | return m_ * x + b_;
30 | }
31 |
32 | XYCoord LinearEquation::intercept(const LinearEquation &otherEquation) const
33 | {
34 | assert(slope() != otherEquation.slope()); // equations never intersect
35 |
36 | // Start with 2 equations
37 | // y1 = m1 * x1 + b1
38 | // y2 = m2 * x2 + b2
39 | //
40 | // At the point of intersection, we know that y1 = y2
41 | // and x1 = x2
42 | //
43 | // Therefore (at the point of intersection)
44 | //
45 | // m1 * x + b1 = m2 * x * b2
46 | // or:
47 | // x = (b2-b1)/(m1-m2)
48 |
49 | double intersectX = (otherEquation.b() - this->b())/(this->slope()-otherEquation.slope());
50 | double intersectY = this->yVal(intersectX);
51 |
52 | return XYCoord(intersectX, intersectY);
53 |
54 | }
55 |
56 | bool LinearEquation::aboveLine(const XYCoord &coord) const
57 | {
58 | double lineYVal = this->yVal(coord.x());
59 | return (coord.y() >= lineYVal)?true:false;
60 | }
61 |
62 | bool LinearEquation::belowLine(const XYCoord &coord) const
63 | {
64 | double lineYVal = this->yVal(coord.x());
65 | return (coord.y() <= lineYVal)?true:false;
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/src/math/LinearEquation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LinearEquation.h
3 | *
4 | * Created on: Jun 6, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef LINEAREQUATION_H_
9 | #define LINEAREQUATION_H_
10 |
11 | #include
12 | #include "XYCoord.h"
13 |
14 | class LinearEquation {
15 |
16 | private:
17 | double m_;
18 | double b_;
19 | public:
20 | LinearEquation(double m, double b);
21 | LinearEquation(const XYCoord &startPt, const XYCoord &endPt);
22 |
23 | // Point at which this equation intercepts another. Don't use
24 | // this method if both equations have the same slope (and thus never intersect).
25 | XYCoord intercept(const LinearEquation &otherEquation) const;
26 |
27 | // Tests if the given XYCoord is above or below the line drawn by this equation.
28 | bool aboveLine(const XYCoord &coord) const;
29 | bool belowLine(const XYCoord &coord) const;
30 |
31 | double slope() const;
32 | double yVal(double x) const;
33 | double b() const { return b_; }
34 | };
35 |
36 | typedef boost::shared_ptr LinearEquationPtr;
37 |
38 | #endif /* LINEAREQUATION_H_ */
39 |
--------------------------------------------------------------------------------
/src/math/MathHelper.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * MathHelper.cpp
3 | *
4 | * Created on: Jun 27, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | MathHelper::MathHelper() {
14 | }
15 |
16 | double MathHelper::maxDouble()
17 | {
18 | return std::numeric_limits::max();
19 |
20 | }
21 |
22 | double MathHelper::minDouble()
23 | {
24 | return -1.0 * std::numeric_limits::max();
25 | }
26 |
27 | double MathHelper::relativePercentVal(double comparisonVal, double baseVal)
28 | {
29 | return (comparisonVal/baseVal - 1.0) * 100.0;
30 | }
31 |
32 | double MathHelper::absRelPercentVal(double comparisonVal, double baseVal)
33 | {
34 | double relPerc = MathHelper::relativePercentVal(comparisonVal,baseVal);
35 | if(relPerc < 0.0)
36 | {
37 | relPerc *= -1.0;
38 | }
39 | return relPerc;
40 | }
41 |
42 | bool MathHelper::valuesClose(double val1, double val2, double tolerance)
43 | {
44 | assert(tolerance >= 0.0);
45 | double delta = abs(val1-val2);
46 | if(delta <= tolerance)
47 | {
48 | return true;
49 | }
50 | else
51 | {
52 | return false;
53 | }
54 | }
55 |
56 |
57 |
58 | MathHelper::~MathHelper() {
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/src/math/MathHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * MathHelper.h
3 | *
4 | * Created on: Jun 27, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef MATHHELPER_H_
9 | #define MATHHELPER_H_
10 |
11 | class MathHelper {
12 | public:
13 | MathHelper();
14 |
15 | static double maxDouble();
16 | static double minDouble();
17 | static double relativePercentVal(double comparisonVal, double baseVal);
18 | static double absRelPercentVal(double comparisonVal, double baseVal);
19 | static bool valuesClose(double val1, double val2, double tolerance);
20 |
21 | virtual ~MathHelper();
22 | };
23 |
24 | #endif /* MATHHELPER_H_ */
25 |
--------------------------------------------------------------------------------
/src/math/UnsignedIntRange.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * UnsignedIntRange.cpp
3 | *
4 | * Created on: Jul 31, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include
10 |
11 | UnsignedIntRange::UnsignedIntRange(unsigned int minVal, unsigned int maxVal)
12 | : minVal_(minVal), maxVal_(maxVal)
13 | {
14 | assert(maxVal>=minVal);
15 | }
16 |
--------------------------------------------------------------------------------
/src/math/UnsignedIntRange.h:
--------------------------------------------------------------------------------
1 | /*
2 | * UnsignedIntRange.h
3 | *
4 | * Created on: Jul 31, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef UNSIGNEDINTRANGE_H_
9 | #define UNSIGNEDINTRANGE_H_
10 |
11 | class UnsignedIntRange {
12 | private:
13 | unsigned int minVal_;
14 | unsigned int maxVal_;
15 | public:
16 | UnsignedIntRange(unsigned int minVal, unsigned int maxVal);
17 |
18 | bool valueWithinRange(unsigned int val) const { return (val >= minVal_) && (val <= maxVal_); }
19 |
20 | unsigned int maxVal() const { return maxVal_; }
21 | unsigned int minVal() const { return minVal_; }
22 |
23 | virtual ~UnsignedIntRange() {}
24 | };
25 |
26 | #endif /* UNSIGNEDINTRANGE_H_ */
27 |
--------------------------------------------------------------------------------
/src/math/ValueComparator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ValueComparator.h
3 | *
4 | * Created on: Jul 7, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef VALUECOMPARATOR_H_
9 | #define VALUECOMPARATOR_H_
10 |
11 | #include
12 |
13 |
14 | class ValueComparator {
15 | public:
16 | ValueComparator() {}
17 |
18 | virtual bool compare(double lhs, double rhs) const = 0;
19 |
20 | virtual ~ValueComparator() {}
21 | };
22 |
23 | typedef boost::shared_ptr ValueComparatorPtr;
24 |
25 | class EqualValueComparator: public ValueComparator {
26 | bool compare(double lhs, double rhs) const { return lhs==rhs; }
27 | };
28 |
29 | class LessThanValueComparator: public ValueComparator {
30 | bool compare(double lhs, double rhs) const { return lhsrhs; }
41 | };
42 |
43 | class GreaterThanEqualValueComparator: public ValueComparator {
44 | private:
45 | double tolerance_;
46 | public:
47 | GreaterThanEqualValueComparator(double tolerance) :tolerance_(tolerance) {}
48 | GreaterThanEqualValueComparator(): tolerance_(0.0) {}
49 |
50 | bool compare(double lhs, double rhs) const { return (lhs+tolerance_)>=rhs; }
51 | };
52 |
53 |
54 | #endif /* VALUECOMPARATOR_H_ */
55 |
--------------------------------------------------------------------------------
/src/math/XYCoord.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * XYCoord.cpp
3 | *
4 | * Created on: Jun 6, 2014
5 | * Author: sroehling
6 | */
7 |
8 |
9 | #include "XYCoord.h"
10 |
11 | XYCoord::XYCoord(double x, double y)
12 | : x_(x), y_(y)
13 | {
14 |
15 | }
16 |
17 | double XYCoord::x() const
18 | {
19 | return x_;
20 | }
21 |
22 | double XYCoord::y() const
23 | {
24 | return y_;
25 | }
26 |
27 |
28 | std::ostream& operator<<(std::ostream& os, const XYCoord& coord)
29 | {
30 | os << "XYCoord("
31 | << "x="<
12 | #include
13 |
14 | class XYCoord {
15 | private:
16 | double x_;
17 | double y_;
18 |
19 | public:
20 | XYCoord(double x, double y);
21 |
22 | double x() const;
23 | double y() const;
24 |
25 | friend std::ostream& operator<<(std::ostream& os, const XYCoord& coord);
26 |
27 | };
28 |
29 | typedef std::vector XYCoordVector;
30 |
31 |
32 | #endif /* XYCOORD_H_ */
33 |
--------------------------------------------------------------------------------
/src/patternMatch/AscendingTrianglePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "AscendingTrianglePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | AscendingTrianglePatternMatch::AscendingTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
5 | const ChartSegmentPtr &upperTrendLine,
6 | const ChartSegmentPtr &lowerTrendLine)
7 | : TrianglePatternMatch(wedgeSegment,upperTrendLine,lowerTrendLine)
8 | {
9 |
10 | }
11 |
12 | void AscendingTrianglePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
13 | {
14 | TrianglePatternMatch::acceptVisitor(visitor);
15 | visitor.visitAscendingTrianglePatternMatch(*this);
16 | }
17 |
--------------------------------------------------------------------------------
/src/patternMatch/AscendingTrianglePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef ASCENDINGTRIANGLEPATTERNMATCH_H
2 | #define ASCENDINGTRIANGLEPATTERNMATCH_H
3 |
4 | #include "TrianglePatternMatch.h"
5 |
6 | class AscendingTrianglePatternMatch : public TrianglePatternMatch
7 | {
8 | public:
9 | AscendingTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
10 | const ChartSegmentPtr &upperTrendLine,
11 | const ChartSegmentPtr &lowerTrendLine);
12 |
13 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
14 |
15 | virtual std::string matchType() const { return "Ascending Triangle"; }
16 | };
17 |
18 | #endif // ASCENDINGTRIANGLEPATTERNMATCH_H
19 |
--------------------------------------------------------------------------------
/src/patternMatch/CupPatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "CupPatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | CupPatternMatch::CupPatternMatch(const PatternMatchPtr &downTrend, const PatternMatchPtr &cupBottom,
5 | const PatternMatchPtr &upTrend)
6 | : PatternMatch(downTrend->appendMatch(*cupBottom)->appendMatch(*upTrend)->segments()),
7 | downTrend_(downTrend),
8 | cupBottom_(cupBottom),
9 | upTrend_(upTrend)
10 | {
11 | }
12 |
13 |
14 | void CupPatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
15 | {
16 | downTrend_->acceptVisitor(visitor);
17 | cupBottom_->acceptVisitor(visitor);
18 | upTrend_->acceptVisitor(visitor);
19 | visitor.visitCupPatternMatch(*this);
20 | }
21 |
--------------------------------------------------------------------------------
/src/patternMatch/CupPatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef CUPPATTERNMATCH_H
2 | #define CUPPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 |
6 | class CupPatternMatch : public PatternMatch
7 | {
8 | private:
9 | PatternMatchPtr downTrend_;
10 | PatternMatchPtr cupBottom_;
11 | PatternMatchPtr upTrend_;
12 | public:
13 | CupPatternMatch(const PatternMatchPtr &downTrend, const PatternMatchPtr &cupBottom,
14 | const PatternMatchPtr &upTrend);
15 |
16 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
17 |
18 | const PatternMatchPtr &downTrend() const { return downTrend_; }
19 | const PatternMatchPtr &cupBottom() const { return cupBottom_; }
20 | const PatternMatchPtr &upTrend() const { return upTrend_; }
21 |
22 | virtual std::string matchType() const { return "Cup"; }
23 |
24 | };
25 |
26 | #endif // CUPPATTERNMATCH_H
27 |
--------------------------------------------------------------------------------
/src/patternMatch/CupWithHandlePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "CupWithHandlePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 |
5 | CupWithHandlePatternMatch::CupWithHandlePatternMatch(const PatternMatchPtr &cup, const PatternMatchPtr &handle)
6 | : PatternMatch(cup->appendMatch(*handle)->segments()),
7 | cup_(cup),
8 | handle_(handle)
9 | {
10 | PatternMatch::initBreakoutAboveFirstHighBreakoutInfo(handle);
11 | }
12 |
13 |
14 | void CupWithHandlePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
15 | {
16 | cup_->acceptVisitor(visitor);
17 |
18 | visitor.visitCupWithHandleHandleStart(*this);
19 |
20 | handle_->acceptVisitor(visitor);
21 |
22 | visitor.visitCupWithHandlePatternMatch(*this);
23 | }
24 |
--------------------------------------------------------------------------------
/src/patternMatch/CupWithHandlePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef CUPWITHHANDLEPATTERNMATCH_H
2 | #define CUPWITHHANDLEPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 |
6 | class CupWithHandlePatternMatch : public PatternMatch
7 | {
8 | private:
9 | PatternMatchPtr cup_;
10 | PatternMatchPtr handle_;
11 | public:
12 | CupWithHandlePatternMatch(const PatternMatchPtr &cup, const PatternMatchPtr &handle);
13 |
14 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
15 |
16 | virtual std::string matchType() const { return "Cup with Handle"; }
17 |
18 | };
19 |
20 | #endif // CUPWITHHANDLEPATTERNMATCH_H
21 |
--------------------------------------------------------------------------------
/src/patternMatch/CupWithoutHandlePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "CupWithoutHandlePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | CupWithoutHandlePatternMatch::CupWithoutHandlePatternMatch(const PatternMatchPtr &cup)
5 | : PatternMatch(cup->segments()),
6 | cup_(cup)
7 | {
8 | PatternMatch::initBreakoutAboveFirstHighBreakoutInfo(cup);
9 | }
10 |
11 | void CupWithoutHandlePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
12 | {
13 | visitor.visitCupWithoutHandleStart(*this);
14 | cup_->acceptVisitor(visitor);
15 | visitor.visitCupWithoutHandlePatternMatch(*this);
16 | }
17 |
--------------------------------------------------------------------------------
/src/patternMatch/CupWithoutHandlePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef CUPWITHOUTHANDLEPATTERNMATCH_H
2 | #define CUPWITHOUTHANDLEPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 |
6 | class CupWithoutHandlePatternMatch : public PatternMatch
7 | {
8 | private:
9 | PatternMatchPtr cup_;
10 | public:
11 | CupWithoutHandlePatternMatch(const PatternMatchPtr &cup);
12 |
13 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
14 |
15 | virtual std::string matchType() const { return "Cup without Handle"; }
16 |
17 | };
18 |
19 |
20 | #endif // CUPWITHOUTHANDLEPATTERNMATCH_H
21 |
--------------------------------------------------------------------------------
/src/patternMatch/DescendingTrianglePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "DescendingTrianglePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | DescendingTrianglePatternMatch::DescendingTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
5 | const ChartSegmentPtr &upperTrendLine,
6 | const ChartSegmentPtr &lowerTrendLine)
7 | : TrianglePatternMatch(wedgeSegment,upperTrendLine,lowerTrendLine)
8 | {
9 |
10 | }
11 |
12 | void DescendingTrianglePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
13 | {
14 | TrianglePatternMatch::acceptVisitor(visitor);
15 | visitor.visitDescendingTrianglePatternMatch(*this);
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/patternMatch/DescendingTrianglePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef DESCENDINGTRIANGLEPATTERNMATCH_H
2 | #define DESCENDINGTRIANGLEPATTERNMATCH_H
3 |
4 | #include "TrianglePatternMatch.h"
5 |
6 | class DescendingTrianglePatternMatch : public TrianglePatternMatch
7 | {
8 | public:
9 | DescendingTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
10 | const ChartSegmentPtr &upperTrendLine,
11 | const ChartSegmentPtr &lowerTrendLine);
12 |
13 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
14 |
15 | virtual std::string matchType() const { return "Descending Triangle"; }
16 | };
17 |
18 | #endif // DESCENDINGTRIANGLEPATTERNMATCH_H
19 |
--------------------------------------------------------------------------------
/src/patternMatch/DoubleBottomPatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "DoubleBottomPatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 | #include "PatternMatchBreakoutInfo.h"
4 |
5 | DoubleBottomPatternMatch::DoubleBottomPatternMatch(const PatternMatchPtr &lhsV, const PatternMatchPtr &rhsV)
6 | : PatternMatch(lhsV->appendMatch(*rhsV)->segments()),
7 | lhsV_(lhsV),rhsV_(rhsV)
8 | {
9 | PatternMatch::initBreakoutAboveFirstHighBreakoutInfo(rhsV);
10 | }
11 |
12 |
13 | void DoubleBottomPatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
14 | {
15 | lhsV_->acceptVisitor(visitor);
16 | visitor.visitDoubleBottomMiddle(*this);
17 | rhsV_->acceptVisitor(visitor);
18 | visitor.visitDoubleBottomPatternMatch(*this);
19 | }
20 |
--------------------------------------------------------------------------------
/src/patternMatch/DoubleBottomPatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef DOUBLEBOTTOMPATTERNMATCH_H
2 | #define DOUBLEBOTTOMPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 |
6 | class DoubleBottomPatternMatch : public PatternMatch
7 | {
8 | private:
9 | PatternMatchPtr lhsV_;
10 | PatternMatchPtr rhsV_;
11 | public:
12 | DoubleBottomPatternMatch(const PatternMatchPtr &lhsV, const PatternMatchPtr &rhsV);
13 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
14 |
15 | virtual std::string matchType() const { return "Double Bottom"; }
16 |
17 | };
18 |
19 | #endif // DOUBLEBOTTOMPATTERNMATCH_H
20 |
--------------------------------------------------------------------------------
/src/patternMatch/FallingWedgePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "FallingWedgePatternMatch.h"
2 |
3 | FallingWedgePatternMatch::FallingWedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo)
4 | : WedgePatternMatch(wedgeMatchInfo)
5 | {
6 | }
7 |
--------------------------------------------------------------------------------
/src/patternMatch/FallingWedgePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef FALLINGWEDGEPATTERNMATCH_H
2 | #define FALLINGWEDGEPATTERNMATCH_H
3 |
4 | #include "WedgePatternMatch.h"
5 |
6 | class FallingWedgePatternMatch : public WedgePatternMatch
7 | {
8 | public:
9 | FallingWedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo);
10 |
11 | virtual std::string matchType() const { return "Falling Wedge"; }
12 | };
13 |
14 | #endif // FALLINGWEDGEPATTERNMATCH_H
15 |
--------------------------------------------------------------------------------
/src/patternMatch/PatternMatchBreakoutInfo.cpp:
--------------------------------------------------------------------------------
1 | #include "PatternMatchBreakoutInfo.h"
2 | #include
3 |
4 | PatternMatchBreakoutInfo::PatternMatchBreakoutInfo(double pseudoXVal, double breakoutPrice)
5 | : periodValPseudoXVal_(pseudoXVal), breakoutPrice_(breakoutPrice)
6 | {
7 | assert(pseudoXVal >= 0.0);
8 | assert(breakoutPrice >= 0.0);
9 | }
10 |
--------------------------------------------------------------------------------
/src/patternMatch/PatternMatchBreakoutInfo.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNMATCHBREAKOUTINFO_H
2 | #define PATTERNMATCHBREAKOUTINFO_H
3 |
4 | #include
5 | #include "XYCoord.h"
6 |
7 | class PatternMatchBreakoutInfo
8 | {
9 | private:
10 | double periodValPseudoXVal_;
11 | double breakoutPrice_;
12 | public:
13 | PatternMatchBreakoutInfo(double pseudoXVal, double breakoutPrice);
14 |
15 | double breakoutPrice() const { return breakoutPrice_; }
16 | double pseudoXVal() const { return periodValPseudoXVal_; }
17 |
18 | XYCoord xyCoord() const { return XYCoord(periodValPseudoXVal_,breakoutPrice_); }
19 |
20 | virtual ~PatternMatchBreakoutInfo() {}
21 | };
22 |
23 | typedef boost::shared_ptr PatternMatchBreakoutInfoPtr;
24 |
25 | #endif // PATTERNMATCHBREAKOUTINFO_H
26 |
--------------------------------------------------------------------------------
/src/patternMatch/PatternMatchVisitor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchVisitor.cpp
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | PatternMatchVisitor::PatternMatchVisitor() {
11 | }
12 |
13 | PatternMatchVisitor::~PatternMatchVisitor() {
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/src/patternMatch/PatternMatchVisitor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchVisitor.h
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHVISITOR_H_
9 | #define PATTERNMATCHVISITOR_H_
10 |
11 | class SymetricTrianglePatternMatch;
12 | class DescendingTrianglePatternMatch;
13 | class VPatternMatch;
14 | class DoubleBottomPatternMatch;
15 | class CupPatternMatch;
16 | class TrianglePatternMatch;
17 | class AscendingTrianglePatternMatch;
18 | class CupWithHandlePatternMatch;
19 | class CupWithoutHandlePatternMatch;
20 | class RectanglePatternMatch;
21 | class WedgePatternMatch;
22 |
23 | class PatternMatchVisitor {
24 | public:
25 | PatternMatchVisitor();
26 |
27 | virtual void visitTrianglePatternMatch(TrianglePatternMatch&) {}
28 |
29 | // Triangles
30 | virtual void visitSymetricWedgePatternMatch(SymetricTrianglePatternMatch &) {}
31 | virtual void visitDescendingTrianglePatternMatch(DescendingTrianglePatternMatch &) {}
32 | virtual void visitAscendingTrianglePatternMatch(AscendingTrianglePatternMatch &) {}
33 |
34 | virtual void visitWedgePatternMatch(WedgePatternMatch &) {}
35 |
36 | virtual void visitRectanglePatternMatch(RectanglePatternMatch &) {}
37 |
38 | virtual void visitVPatternMatch(VPatternMatch &) {}
39 |
40 | virtual void visitDoubleBottomMiddle(DoubleBottomPatternMatch &) {}
41 | virtual void visitDoubleBottomPatternMatch(DoubleBottomPatternMatch &) {}
42 |
43 | virtual void visitCupPatternMatch(CupPatternMatch &) {}
44 |
45 | virtual void visitCupWithHandlePatternMatch(CupWithHandlePatternMatch &) {}
46 | virtual void visitCupWithHandleHandleStart(CupWithHandlePatternMatch &) {}
47 |
48 | virtual void visitCupWithoutHandleStart(CupWithoutHandlePatternMatch &) {}
49 | virtual void visitCupWithoutHandlePatternMatch(CupWithoutHandlePatternMatch &) {}
50 |
51 | virtual ~PatternMatchVisitor();
52 | };
53 |
54 | #endif /* PATTERNMATCHVISITOR_H_ */
55 |
--------------------------------------------------------------------------------
/src/patternMatch/RectanglePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "RectanglePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | RectanglePatternMatch::RectanglePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo)
5 | : PatternMatch(wedgeMatchInfo.createWedgeSegment()),
6 | upperTrendLine_(wedgeMatchInfo.upperTrendLine()),
7 | lowerTrendLine_(wedgeMatchInfo.lowerTrendLine())
8 | {
9 | }
10 |
11 |
12 | void RectanglePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
13 | {
14 | visitor.visitRectanglePatternMatch(*this);
15 | }
16 |
--------------------------------------------------------------------------------
/src/patternMatch/RectanglePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef RECTANGLEPATTERNMATCH_H
2 | #define RECTANGLEPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 | #include "WedgeMatchValidationInfo.h"
6 |
7 | class RectanglePatternMatch : public PatternMatch
8 | {
9 | private:
10 | ChartSegmentPtr upperTrendLine_;
11 | ChartSegmentPtr lowerTrendLine_;
12 | public:
13 | RectanglePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo);
14 |
15 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
16 |
17 | const ChartSegmentPtr &lowerTrendLine() const { return lowerTrendLine_; }
18 | const ChartSegmentPtr &upperTrendLine() const { return upperTrendLine_; }
19 |
20 | virtual std::string matchType() const { return "Rectangle"; }
21 |
22 | };
23 |
24 | #endif // RECTANGLEPATTERNMATCH_H
25 |
--------------------------------------------------------------------------------
/src/patternMatch/RisingWedgePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "RisingWedgePatternMatch.h"
2 |
3 | RisingWedgePatternMatch::RisingWedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo)
4 | : WedgePatternMatch(wedgeMatchInfo)
5 | {
6 | }
7 |
--------------------------------------------------------------------------------
/src/patternMatch/RisingWedgePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef RISINGWEDGEPATTERNMATCH_H
2 | #define RISINGWEDGEPATTERNMATCH_H
3 |
4 | #include "WedgePatternMatch.h"
5 |
6 | class RisingWedgePatternMatch : public WedgePatternMatch
7 | {
8 | public:
9 | RisingWedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo);
10 |
11 | virtual std::string matchType() const { return "Rising Wedge"; }
12 |
13 | };
14 |
15 | #endif // RISINGWEDGEPATTERNMATCH_H
16 |
--------------------------------------------------------------------------------
/src/patternMatch/SymetricTrianglePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * WedgePatternMatch.cpp
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include
10 | #include "PatternMatchVisitor.h"
11 |
12 | SymetricTrianglePatternMatch::SymetricTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
13 | const ChartSegmentPtr &upperTrendLine,
14 | const ChartSegmentPtr &lowerTrendLine)
15 | : TrianglePatternMatch(wedgeSegment,upperTrendLine,lowerTrendLine)
16 | {
17 |
18 | }
19 |
20 | void SymetricTrianglePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
21 | {
22 | TrianglePatternMatch::acceptVisitor(visitor);
23 | visitor.visitSymetricWedgePatternMatch(*this);
24 | }
25 |
--------------------------------------------------------------------------------
/src/patternMatch/SymetricTrianglePatternMatch.h:
--------------------------------------------------------------------------------
1 | /*
2 | * WedgePatternMatch.h
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SYMETRICTRIANGLEPATTERNMATCH_H_
9 | #define SYMETRICTRIANGLEPATTERNMATCH_H_
10 |
11 | #include
12 | #include "ChartSegment.h"
13 |
14 | #include "TrianglePatternMatch.h"
15 |
16 | class SymetricTrianglePatternMatch: public TrianglePatternMatch {
17 | public:
18 | SymetricTrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
19 | const ChartSegmentPtr &upperTrendLine,
20 | const ChartSegmentPtr &lowerTrendLine);
21 |
22 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
23 |
24 | virtual std::string matchType() const { return "Symetric Triangle"; }
25 |
26 | };
27 |
28 | #endif /* SYMETRICTRIANGLEPATTERNMATCH_H_ */
29 |
--------------------------------------------------------------------------------
/src/patternMatch/TrianglePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "TrianglePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | TrianglePatternMatch::TrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
5 | const ChartSegmentPtr &upperTrendLine,
6 | const ChartSegmentPtr &lowerTrendLine)
7 | : PatternMatch(wedgeSegment),
8 | upperTrendLine_(upperTrendLine),
9 | lowerTrendLine_(lowerTrendLine)
10 | {
11 |
12 | }
13 |
14 | void TrianglePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
15 | {
16 | visitor.visitTrianglePatternMatch(*this);
17 | }
18 |
19 |
20 | PeriodValCltn::iterator TrianglePatternMatch::patternBeginIter() const
21 | {
22 | // The pattern always beings with the pivot high which starts the first trend line.
23 | return upperTrendLine_->firstValIter();
24 | }
25 |
26 |
27 | XYCoord TrianglePatternMatch::trendLineIntercept() const
28 | {
29 | XYCoord interceptCoord = lowerTrendLine_->segmentEq()->intercept(*(upperTrendLine_->segmentEq()));
30 |
31 | // Intercept must start after initial pivot high occuring at the first value
32 | // of the upper trend line.
33 | assert(interceptCoord.x() > (*patternBeginIter()).pseudoXVal());
34 |
35 | return interceptCoord;
36 | }
37 |
38 |
39 | PeriodValCltn::iterator TrianglePatternMatch::interceptEndIter() const
40 | {
41 | XYCoord interceptCoord = trendLineIntercept();
42 |
43 | // Throughout this library, all the calculations are done on a "fly-weight" to the
44 | // same underlying PeriodValCltnPtr. Assuming this, the unerlyting PeriodValCltnPtr
45 | // is obtained from the upperTrendLine_.
46 | PeriodValCltnPtr perValCltn = upperTrendLine_->perValSegment()->perValCltn();
47 | unsigned int interceptPerValIndex = floor(interceptCoord.x());
48 | assert(interceptPerValIndex >= 0);
49 | if(interceptPerValIndex >= perValCltn->size())
50 | {
51 | // Special case: If the intercept occurs after the end of the entire underlying
52 | // PeriodValSegment, then the iterator should point to the last value in the PeriodValSegment
53 | // The trend-lines may not intersect by this point, but this is the last value representing
54 | // the closest point within the actual data where the intersection takes place.
55 | return perValCltn->end();
56 | }
57 | else
58 | {
59 | PeriodValCltn::iterator lastValIter = perValCltn->begin();
60 | std::advance(lastValIter,interceptPerValIndex);
61 | assert(lastValIter != perValCltn->end());
62 | assert((*lastValIter).perValIndex() == interceptPerValIndex);
63 | lastValIter++; // advance one more, so the iterator can function like end() in a conventional STL iterator loop
64 | return lastValIter;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/patternMatch/TrianglePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef TRIANGLEPATTERNMATCH_H
2 | #define TRIANGLEPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 | #include "ChartSegment.h"
6 |
7 | class TrianglePatternMatch: public PatternMatch {
8 | private:
9 | ChartSegmentPtr upperTrendLine_;
10 | ChartSegmentPtr lowerTrendLine_;
11 |
12 | public:
13 | TrianglePatternMatch(const ChartSegmentPtr &wedgeSegment,
14 | const ChartSegmentPtr &upperTrendLine,
15 | const ChartSegmentPtr &lowerTrendLine);
16 |
17 | ChartSegmentPtr upperTrendLine() const { return upperTrendLine_; }
18 | ChartSegmentPtr lowerTrendLine() const { return lowerTrendLine_; }
19 |
20 | XYCoord trendLineIntercept() const;
21 |
22 |
23 | // Iterators defining the beginning and end of the trend lines
24 | // comprising the pattern. These methods are useful for iterating
25 | // through the period values and drawing the lower and upper
26 | // trend lines.
27 | PeriodValCltn::iterator patternBeginIter() const;
28 | PeriodValCltn::iterator interceptEndIter() const;
29 |
30 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
31 |
32 | virtual ~TrianglePatternMatch() {}
33 | };
34 |
35 |
36 | #endif // WEDGEPATTERNMATCH_H
37 |
--------------------------------------------------------------------------------
/src/patternMatch/VPatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "VPatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | VPatternMatch::VPatternMatch(const PatternMatchPtr &downTrend, const PatternMatchPtr upTrend)
5 | : PatternMatch(downTrend->appendMatch(*upTrend)->segments()),
6 | downTrend_(downTrend),
7 | upTrend_(upTrend)
8 | {
9 | }
10 |
11 |
12 | void VPatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
13 | {
14 | downTrend_->acceptVisitor(visitor);
15 | upTrend_->acceptVisitor(visitor);
16 | visitor.visitVPatternMatch(*this);
17 | }
18 |
--------------------------------------------------------------------------------
/src/patternMatch/VPatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef VPATTERNMATCH_H
2 | #define VPATTERNMATCH_H
3 |
4 | #include "PatternMatch.h"
5 | #include "ChartSegment.h"
6 |
7 | class VPatternMatch: public PatternMatch {
8 | PatternMatchPtr downTrend_;
9 | PatternMatchPtr upTrend_;
10 | public:
11 | VPatternMatch(const PatternMatchPtr &downTrend, const PatternMatchPtr upTrend);
12 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
13 |
14 | const PatternMatchPtr &downTrend() const { return downTrend_; }
15 | const PatternMatchPtr &upTrend() const { return upTrend_; }
16 |
17 | };
18 |
19 | #endif // VPATTERNMATCH_H
20 |
--------------------------------------------------------------------------------
/src/patternMatch/WedgePatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include "WedgePatternMatch.h"
2 | #include "PatternMatchVisitor.h"
3 |
4 | WedgePatternMatch::WedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo)
5 | : PatternMatch(wedgeMatchInfo.createWedgeSegment()),
6 | upperTrendLine_(wedgeMatchInfo.upperTrendLine()),
7 | lowerTrendLine_(wedgeMatchInfo.lowerTrendLine())
8 | {
9 | }
10 |
11 |
12 | void WedgePatternMatch::acceptVisitor(PatternMatchVisitor &visitor)
13 | {
14 | visitor.visitWedgePatternMatch(*this);
15 | }
16 |
--------------------------------------------------------------------------------
/src/patternMatch/WedgePatternMatch.h:
--------------------------------------------------------------------------------
1 | #ifndef WEDGEPATTERNMATCH_H
2 | #define WEDGEPATTERNMATCH_H
3 |
4 | #include "WedgeMatchValidationInfo.h"
5 | #include "PatternMatch.h"
6 |
7 | class WedgePatternMatch : public PatternMatch
8 | {
9 | private:
10 | ChartSegmentPtr upperTrendLine_;
11 | ChartSegmentPtr lowerTrendLine_;
12 | public:
13 | WedgePatternMatch(const WedgeMatchValidationInfo &wedgeMatchInfo);
14 |
15 | const ChartSegmentPtr &lowerTrendLine() const { return lowerTrendLine_; }
16 | const ChartSegmentPtr &upperTrendLine() const { return upperTrendLine_; }
17 |
18 | virtual void acceptVisitor(PatternMatchVisitor &visitor);
19 | };
20 |
21 | #endif // WEDGEPATTERNMATCH_H
22 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchFilter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchFilter.h
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHFILTER_H_
9 | #define PATTERNMATCHFILTER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PatternMatchSortFunctor.h"
13 | #include "PatternMatchUniqueFunctor.h"
14 | #include "PatternMatchFindPredicate.h"
15 |
16 | namespace patternMatchFilter {
17 |
18 | PatternMatchListPtr filterUniqueStartEndTime(const PatternMatchListPtr &unfilteredMatches);
19 |
20 | // Filter then return unique matches with the same lowest-low or highest-high. This is useful
21 | // for filtering the pivot lows or pivot highs.
22 | PatternMatchListPtr filterUniqueAndLongestHighestHigh(const PatternMatchListPtr &unfilteredMatches);
23 | PatternMatchListPtr filterUniqueAndLongestLowestLow(const PatternMatchListPtr &unfilteredMatches);
24 |
25 | // Sort the patterns by their end date, then by length (from longest to shortest). Then
26 | // return a unique list of patterns with the same end date.
27 | PatternMatchListPtr filterUniqueLongestPatternSameEndDate(const PatternMatchListPtr &unfilteredMatches);
28 |
29 | PatternMatchListPtr sortPatternMatches(const PatternMatchListPtr &unsortedMatches,
30 | const PatternMatchSortFunctor &sortFunc);
31 | PatternMatchListPtr uniquePatternMatches(const PatternMatchListPtr &unfilteredMatches,
32 | const PatternMatchUniqueFunctor &uniqueFunc);
33 |
34 | PatternMatchListPtr sortThenFilterUniqueMatches(const PatternMatchListPtr &unfilteredMatches,
35 | const PatternMatchSortFunctor &sortFunc, const PatternMatchUniqueFunctor &uniqueFunc);
36 |
37 | // Starting at the beginning of patternMatches, find the first PatternMatch satisfying findPred
38 | PatternMatchList::iterator findFirstPatternMatch(const PatternMatchListPtr &patternMatches,
39 | const PatternMatchFindPredicate &findPred);
40 |
41 |
42 |
43 | }
44 |
45 | #endif /* PATTERNMATCHFILTER_H_ */
46 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchFindPredicate.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchFindPredicate.cpp
3 | *
4 | * Created on: Jul 23, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | bool LowestLowAfterTime::operator() (const PatternMatchPtr &patternMatch) const
11 | {
12 | return patternMatch->lowestLowTime() > comparisonTime_;
13 | }
14 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchFindPredicate.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchFindPredicate.h
3 | *
4 | * Created on: Jul 23, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHFINDPREDICATE_H_
9 | #define PATTERNMATCHFINDPREDICATE_H_
10 |
11 | #include "PatternMatch.h"
12 | #include
13 |
14 |
15 | class PatternMatchFindPredicate {
16 | public:
17 | PatternMatchFindPredicate() {}
18 |
19 | virtual bool operator() (const PatternMatchPtr &patternMatch) const = 0;
20 |
21 | virtual ~PatternMatchFindPredicate() {}
22 | };
23 |
24 | class LowestLowAfterTime: public PatternMatchFindPredicate {
25 | private:
26 | boost::posix_time::ptime comparisonTime_;
27 | public:
28 | LowestLowAfterTime(const boost::posix_time::ptime &comparisonTime) : comparisonTime_(comparisonTime) {}
29 |
30 | virtual bool operator() (const PatternMatchPtr &patternMatch) const;
31 |
32 | virtual ~LowestLowAfterTime() {}
33 | };
34 |
35 |
36 | #endif /* PATTERNMATCHFINDPREDICATE_H_ */
37 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchSortFunctor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchSortFunctor.h
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHSORTFUNCTOR_H_
9 | #define PATTERNMATCHSORTFUNCTOR_H_
10 |
11 | #include "PatternMatch.h"
12 |
13 | class PatternMatchSortFunctor {
14 | public:
15 | PatternMatchSortFunctor() {}
16 |
17 | virtual bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const = 0;
18 |
19 | virtual ~PatternMatchSortFunctor() {}
20 | };
21 |
22 | // Sort by end date, then by start date. This will give you a PatternMatchList where
23 | // PatternMatch objects with the same end date are adjacent to one another. Then
24 | // PatternMatch objects with the same end date are sorted by start date with the
25 | // PatternMatch object with earlier start time coming first.
26 | //
27 | // The result of this sort is suitable for use with the PatternMatchList unique method.
28 | // Combined with the unique function, the results will be PatternMatch objects with unique end
29 | // dates, but with the earliest start dates for the same end dates (in other words, longest
30 | // PatternMatch leading up to the end date).
31 | class SortPatternMatchByEndTimeThenLength : public PatternMatchSortFunctor {
32 | public:
33 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
34 | };
35 |
36 | class ReverseSortPatternMatchByEndTimeThenLength : public PatternMatchSortFunctor {
37 | public:
38 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
39 | };
40 |
41 |
42 | // Sort first by start date, then by end date, from earliest to latest dates for each
43 | class SortPatternMatchByStartAndEndDate : public PatternMatchSortFunctor {
44 | public:
45 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
46 | };
47 |
48 | // The PatternMatch class has a highestHighTime member function. This method
49 | // returns the period time when the highest high took place. This is useful
50 | // to first sort by the highest high, then the length of the pattern to identify
51 | // unique pivot points with the same highest high.
52 | class SortPatternMatchByHighestHighTimeThenLength : public PatternMatchSortFunctor {
53 | public:
54 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
55 | };
56 |
57 | class SortPatternMatchByLowestLowTimeThenLength : public PatternMatchSortFunctor {
58 | public:
59 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
60 | };
61 |
62 |
63 |
64 | #endif /* PATTERNMATCHSORTFUNCTOR_H_ */
65 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchUniqueFunctor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchUniqueFunctor.cpp
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | bool SameStartAndEndDate::operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const
11 | {
12 | return( (first->startTime() == second->startTime()) &&
13 | (first->endTime() == second->endTime()) );
14 | }
15 |
16 | bool SameEndTime::operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const
17 | {
18 | return(first->endTime() == second->endTime() );
19 | }
20 |
21 |
22 | bool SameHighestHighTime::operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const
23 | {
24 | return(first->highestHighTime() == second->highestHighTime() );
25 | }
26 |
27 | bool SameLowestLowTime::operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const
28 | {
29 | return(first->lowestLowTime() == second->lowestLowTime() );
30 | }
31 |
--------------------------------------------------------------------------------
/src/patternMatchFilter/PatternMatchUniqueFunctor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchUniqueFunctor.h
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHUNIQUEFUNCTOR_H_
9 | #define PATTERNMATCHUNIQUEFUNCTOR_H_
10 |
11 | #include "PatternMatch.h"
12 |
13 |
14 | class PatternMatchUniqueFunctor {
15 | public:
16 | PatternMatchUniqueFunctor() {}
17 |
18 | virtual bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const =0;
19 |
20 | virtual ~PatternMatchUniqueFunctor() {}
21 | };
22 |
23 | class SameStartAndEndDate: public PatternMatchUniqueFunctor {
24 | public:
25 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
26 | };
27 |
28 | class SameEndTime: public PatternMatchUniqueFunctor {
29 | public:
30 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
31 | };
32 |
33 |
34 | class SameHighestHighTime: public PatternMatchUniqueFunctor {
35 | public:
36 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
37 | };
38 |
39 | class SameLowestLowTime: public PatternMatchUniqueFunctor {
40 | public:
41 | bool operator() (const PatternMatchPtr &first, const PatternMatchPtr &second) const;
42 | };
43 |
44 |
45 | #endif /* PATTERNMATCHUNIQUEFUNCTOR_H_ */
46 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ANDPatternMatchValidator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ANDPatternMatchValidator.cpp
3 | *
4 | * Created on: Jul 8, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | ANDPatternMatchValidator::ANDPatternMatchValidator(const PatternMatchValidatorList &andList)
11 | : andList_(andList)
12 | {
13 | }
14 |
15 |
16 | bool ANDPatternMatchValidator::validPattern(const PatternMatch &candidateMatch)
17 | {
18 | if(andList_.size() == 0)
19 | {
20 | return true;
21 | }
22 | else
23 | {
24 | for(PatternMatchValidatorList::const_iterator valIter = andList_.begin();
25 | valIter != andList_.end(); valIter++)
26 | {
27 | if(!(*valIter)->validPattern(candidateMatch))
28 | {
29 | return false;
30 | }
31 | }
32 | return true;
33 | }
34 | }
35 |
36 |
37 | ANDPatternMatchValidator::~ANDPatternMatchValidator() {
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ANDPatternMatchValidator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ANDPatternMatchValidator.h
3 | *
4 | * Created on: Jul 8, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ANDPATTERNMATCHVALIDATOR_H_
9 | #define ANDPATTERNMATCHVALIDATOR_H_
10 |
11 | #include
12 |
13 | class ANDPatternMatchValidator: public PatternMatchValidator {
14 | private:
15 | PatternMatchValidatorList andList_;
16 | public:
17 | ANDPatternMatchValidator(const PatternMatchValidatorList &andList);
18 | virtual bool validPattern(const PatternMatch &candidateMatch);
19 | virtual ~ANDPatternMatchValidator();
20 | };
21 |
22 | #endif /* ANDPATTERNMATCHVALIDATOR_H_ */
23 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/AnyPatternMatchValidator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * AnyPatternMatchValidator.cpp
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | AnyPatternMatchValidator::AnyPatternMatchValidator() {
11 | }
12 |
13 |
14 | bool AnyPatternMatchValidator::validPattern(const PatternMatch &)
15 | {
16 | return true;
17 | }
18 |
19 | AnyPatternMatchValidator::~AnyPatternMatchValidator() {
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/AnyPatternMatchValidator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AnyPatternMatchValidator.h
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ANYPATTERNMATCHVALIDATOR_H_
9 | #define ANYPATTERNMATCHVALIDATOR_H_
10 |
11 | #include
12 |
13 | // PatternMatchValidator for testing - always return true
14 | // for validPattern.
15 | class AnyPatternMatchValidator: public PatternMatchValidator {
16 | public:
17 | AnyPatternMatchValidator();
18 | virtual bool validPattern(const PatternMatch &candidateMatch);
19 | virtual ~AnyPatternMatchValidator();
20 | };
21 |
22 | #endif /* ANYPATTERNMATCHVALIDATOR_H_ */
23 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/BreakoutAboveFirstHighValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | #include "BreakoutAboveFirstHighValidatorFactory.h"
2 |
3 | #include "ValueComparator.h"
4 | #include "PatternMatchValueRef.h"
5 | #include "ValueComparisonMatchValidator.h"
6 | #include "PeriodValueRef.h"
7 | #include "ANDPatternMatchValidator.h"
8 |
9 |
10 | BreakoutAboveFirstHighValidatorFactory::BreakoutAboveFirstHighValidatorFactory()
11 | {
12 | }
13 |
14 |
15 | PatternMatchValidatorPtr BreakoutAboveFirstHighValidatorFactory::createValidator(const PatternMatchVector &previousMatches) const
16 | {
17 | assert(previousMatches.size() >0);
18 | PatternMatchPtr prevMatch = previousMatches[0];
19 |
20 | ValueComparatorPtr greaterThanCompare(new GreaterThanValueComparator());
21 | ValueComparatorPtr lessThanCompare(new LessThanValueComparator());
22 |
23 |
24 | PatternMatchValueRefPtr firstHigh(new FixedPatternMatchValueRef(prevMatch->firstValue().high()));
25 |
26 | PeriodValueRefPtr closeValueRef(new ClosePeriodValueRef());
27 |
28 | PatternMatchValueRefPtr lastCloseRef(new LastPeriodValPatternMatchValueRef(closeValueRef));
29 |
30 | PatternMatchValueRefPtr secondToLastCloseRef(new SecondToLastPeriodValPatternMatchValueRef(closeValueRef));
31 |
32 | PatternMatchValidatorPtr closeAboveHighValidator(
33 | new ValueComparisonMatchValidator(lastCloseRef,firstHigh,greaterThanCompare));
34 |
35 | PatternMatchValidatorPtr secondToLastCloseBelowHighValidator(
36 | new ValueComparisonMatchValidator(secondToLastCloseRef,firstHigh,lessThanCompare));
37 |
38 | // Except for the last value, ensure none of the previous close values exceeds the first high.
39 | // This ensures breakout for the last value is preceded by another value which also goes
40 | // above the first high.
41 | ValueComparatorPtr lessCompare(new LessThanValueComparator());
42 | PatternMatchValueRefPtr highestCloseExceptLast(new HighestValExceptLastPatternMatchValueRef(closeValueRef));
43 | PatternMatchValidatorPtr highestCloseExceptLastBelowFirstHigh(
44 | new ValueComparisonMatchValidator(highestCloseExceptLast,firstHigh,lessCompare));
45 |
46 | PatternMatchValidatorList breakoutValidators;
47 | breakoutValidators.push_back(closeAboveHighValidator);
48 | breakoutValidators.push_back(secondToLastCloseBelowHighValidator);
49 | breakoutValidators.push_back(highestCloseExceptLastBelowFirstHigh);
50 |
51 | PatternMatchValidatorPtr upSideBreakoutValidator(new ANDPatternMatchValidator(breakoutValidators));
52 |
53 |
54 | return upSideBreakoutValidator;
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/BreakoutAboveFirstHighValidatorFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef BREAKOUTABOVEFIRSTHIGHVALIDATORFACTORY_H
2 | #define BREAKOUTABOVEFIRSTHIGHVALIDATORFACTORY_H
3 |
4 | #include "PatternMatchValidatorFactory.h"
5 |
6 | class BreakoutAboveFirstHighValidatorFactory : public PatternMatchValidatorFactory
7 | {
8 | public:
9 | BreakoutAboveFirstHighValidatorFactory();
10 | PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
11 |
12 | };
13 |
14 | #endif // BREAKOUTABOVEFIRSTHIGHVALIDATORFACTORY_H
15 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/CloseWithinPercentOfDepthFromFirstHighValidator.cpp:
--------------------------------------------------------------------------------
1 | #include "CloseWithinPercentOfDepthFromFirstHighValidator.h"
2 | #include "PatternMatch.h"
3 |
4 | CloseWithinPercentOfDepthFromFirstHighValidator::CloseWithinPercentOfDepthFromFirstHighValidator(double percDepthThreshold)
5 | : percDepthThreshold_(percDepthThreshold)
6 | {
7 | assert(percDepthThreshold >= -2.0); // -300%
8 | assert(percDepthThreshold <= 2.0); // +300%
9 | }
10 |
11 | bool CloseWithinPercentOfDepthFromFirstHighValidator::validPattern(const PatternMatch &candidateMatch)
12 | {
13 | double firstHigh = candidateMatch.firstValue().high();
14 | double lowestLow = candidateMatch.lowestLow();
15 | assert(firstHigh >= lowestLow);
16 | double depth = firstHigh-lowestLow;
17 |
18 | double thresholdHigh = firstHigh + (depth * percDepthThreshold_);
19 |
20 | double lastClose = candidateMatch.lastValue().close();
21 |
22 | return (lastClose <= thresholdHigh) ? true: false;
23 | }
24 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/CloseWithinPercentOfDepthFromFirstHighValidator.h:
--------------------------------------------------------------------------------
1 | #ifndef CLOSEWITHINPERCENTOFDEPTHFROMFIRSTHIGHVALIDATOR_H
2 | #define CLOSEWITHINPERCENTOFDEPTHFROMFIRSTHIGHVALIDATOR_H
3 |
4 | #include "PatternMatchValidator.h"
5 |
6 | class CloseWithinPercentOfDepthFromFirstHighValidator : public PatternMatchValidator
7 | {
8 | private:
9 | double percDepthThreshold_;
10 | public:
11 | CloseWithinPercentOfDepthFromFirstHighValidator(double percDepthThreshold);
12 | virtual bool validPattern(const PatternMatch &candidateMatch);
13 | };
14 |
15 | #endif // CLOSEWITHINPERCENTOFDEPTHFROMFIRSTHIGHVALIDATOR_H
16 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/CompositePatternMatchValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * CompositePatternMatchValidatorFactory.cpp
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "StaticPatternMatchValidatorFactory.h"
10 | #include "ANDPatternMatchValidator.h"
11 |
12 | CompositePatternMatchValidatorFactory::CompositePatternMatchValidatorFactory() {
13 | }
14 |
15 | void CompositePatternMatchValidatorFactory::addFactory(const PatternMatchValidatorFactoryPtr &factory)
16 | {
17 | factories_.push_back(factory);
18 | }
19 |
20 | void CompositePatternMatchValidatorFactory::addStaticValidator(const PatternMatchValidatorPtr &validator)
21 | {
22 | PatternMatchValidatorFactoryPtr staticFactory(new StaticPatternMatchValidatorFactory(validator));
23 | factories_.push_back(staticFactory);
24 | }
25 |
26 | PatternMatchValidatorPtr CompositePatternMatchValidatorFactory::createValidator(
27 | const PatternMatchVector &previousMatches) const
28 | {
29 | PatternMatchValidatorList validators;
30 | for(PatternMatchValidatorFactoryList::const_iterator factoryIter = factories_.begin();
31 | factoryIter != factories_.end(); factoryIter++)
32 | {
33 | validators.push_back((*factoryIter)->createValidator(previousMatches));
34 | }
35 | return PatternMatchValidatorPtr(new ANDPatternMatchValidator(validators));
36 |
37 | }
38 |
39 |
40 |
41 | CompositePatternMatchValidatorFactory::~CompositePatternMatchValidatorFactory() {
42 |
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/CompositePatternMatchValidatorFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * CompositePatternMatchValidatorFactory.h
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef COMPOSITEPATTERNMATCHVALIDATORFACTORY_H_
9 | #define COMPOSITEPATTERNMATCHVALIDATORFACTORY_H_
10 |
11 | #include "PatternMatchValidatorFactory.h"
12 |
13 | class CompositePatternMatchValidatorFactory: public PatternMatchValidatorFactory {
14 | private:
15 | PatternMatchValidatorFactoryList factories_;
16 | public:
17 | CompositePatternMatchValidatorFactory();
18 |
19 | void addFactory(const PatternMatchValidatorFactoryPtr &factory);
20 | void addStaticValidator(const PatternMatchValidatorPtr &validator);
21 |
22 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
23 |
24 | virtual ~CompositePatternMatchValidatorFactory();
25 | };
26 |
27 | #endif /* COMPOSITEPATTERNMATCHVALIDATORFACTORY_H_ */
28 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/EndWithinPercentOfStart.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * EndWithinPercentOfStart.cpp
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "EndWithinPercentOfStart.h"
9 | #include "MathHelper.h"
10 |
11 | EndWithinPercentOfStart::EndWithinPercentOfStart(double relPercent)
12 | : relPercent_(relPercent)
13 | {
14 | assert(relPercent >= -100.0);
15 | assert(relPercent != 0.0);
16 | }
17 |
18 |
19 | bool EndWithinPercentOfStart::validPattern(const PatternMatch &candidateMatch)
20 | {
21 | double startingVal = candidateMatch.firstValue().high();
22 | double endingVal = candidateMatch.lastValue().close();
23 | double relPercResult = MathHelper::relativePercentVal(endingVal,startingVal);
24 |
25 | // std::cerr << "EndWithinPercentOfStart: Relative Percent Val: start=" << startingVal << " end=" << endingVal
26 | // << " relPerc=" << relPercResult << std::endl;
27 |
28 | if(relPercent_ < 0.0)
29 | {
30 | if((relPercResult < 0.0) && (relPercResult >= relPercent_))
31 | {
32 | return true;
33 | }
34 | else
35 | {
36 | return false;
37 | }
38 | }
39 | else // relPercent_ > 0.0
40 | {
41 | if((relPercResult > 0.0) && (relPercResult <= relPercent_))
42 | {
43 | return true;
44 | }
45 | else
46 | {
47 | return false;
48 | }
49 | }
50 |
51 | }
52 |
53 |
54 | EndWithinPercentOfStart::~EndWithinPercentOfStart() {
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/EndWithinPercentOfStart.h:
--------------------------------------------------------------------------------
1 | /*
2 | * EndWithinPercentOfStart.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ENDWITHINPERCENTOFSTART_H_
9 | #define ENDWITHINPERCENTOFSTART_H_
10 |
11 | #include "PatternMatchValidator.h"
12 | #include "PatternMatch.h"
13 |
14 | class EndWithinPercentOfStart: public PatternMatchValidator {
15 | private:
16 | double relPercent_;
17 | double relativePercentVal(double comparisonVal, double baseVal) const;
18 | public:
19 | EndWithinPercentOfStart(double relPercent);
20 |
21 | bool validPattern(const PatternMatch &candidateMatch);
22 |
23 | ~EndWithinPercentOfStart();
24 | };
25 |
26 | #endif /* ENDWITHINPERCENTOFSTART_H_ */
27 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/HigherLowPatternMatchValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * HigherLowPatternMatchValidatorFactory.cpp
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "ValueComparator.h"
10 | #include "PatternMatchValueRef.h"
11 | #include "ValueComparisonMatchValidator.h"
12 |
13 | HigherLowPatternMatchValidatorFactory::HigherLowPatternMatchValidatorFactory() {
14 | }
15 |
16 | PatternMatchValidatorPtr HigherLowPatternMatchValidatorFactory::createValidator(const PatternMatchVector &previousMatches) const
17 | {
18 | assert(previousMatches.size()==1); // only works when provided with 1 previous match.
19 |
20 | PatternMatchPtr prevMatch = previousMatches[0];
21 |
22 | ValueComparatorPtr greaterThanEqualCompare(new GreaterThanEqualValueComparator());
23 |
24 | PatternMatchValueRefPtr prevLow(new FixedPatternMatchValueRef(prevMatch->lowestLow()));
25 |
26 | PatternMatchValueRefPtr validationLowRef(new LowestLowPatternMatchValueRef());
27 |
28 | PatternMatchValidatorPtr higherLowValidator(
29 | new ValueComparisonMatchValidator(validationLowRef,prevLow,greaterThanEqualCompare));
30 | return higherLowValidator;
31 |
32 | }
33 |
34 | HigherLowPatternMatchValidatorFactory::~HigherLowPatternMatchValidatorFactory() {
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/HigherLowPatternMatchValidatorFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * HigherLowPatternMatchValidatorFactory.h
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef HIGHERLOWPATTERNMATCHVALIDATORFACTORY_H_
9 | #define HIGHERLOWPATTERNMATCHVALIDATORFACTORY_H_
10 |
11 | #include
12 |
13 | class HigherLowPatternMatchValidatorFactory: public PatternMatchValidatorFactory {
14 | public:
15 | HigherLowPatternMatchValidatorFactory();
16 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
17 | virtual ~HigherLowPatternMatchValidatorFactory();
18 | };
19 |
20 | #endif /* HIGHERLOWPATTERNMATCHVALIDATORFACTORY_H_ */
21 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/HighestHighLessThanFirstHigh.cpp:
--------------------------------------------------------------------------------
1 | #include "HighestHighLessThanFirstHigh.h"
2 | #include "DebugLog.h"
3 |
4 | HighestHighLessThanFirstHigh::HighestHighLessThanFirstHigh()
5 | {
6 | }
7 |
8 |
9 | bool HighestHighLessThanFirstHigh::validPattern(const PatternMatch &candidateMatch)
10 | {
11 | assert(candidateMatch.numPeriods() > 1);
12 | PeriodValCltn::iterator matchIter = candidateMatch.matchSegment()->segBegin();
13 |
14 | double firstHigh = (*matchIter).high();
15 | double firstHighWithTolerance = firstHigh + 0.001;
16 |
17 | double highestHigh = candidateMatch.highestHigh();
18 |
19 | DEBUG_MSG("HighestHighLessThanFirstHigh: first high: " << firstHigh
20 | << " highest high: " << highestHigh);
21 |
22 |
23 | return (highestHigh <= firstHighWithTolerance)? true : false;
24 | }
25 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/HighestHighLessThanFirstHigh.h:
--------------------------------------------------------------------------------
1 | #ifndef HIGHESTHIGHLESSTHANFIRSTHIGH_H
2 | #define HIGHESTHIGHLESSTHANFIRSTHIGH_H
3 |
4 | #include "PatternMatchValidator.h"
5 |
6 | class HighestHighLessThanFirstHigh : public PatternMatchValidator
7 | {
8 | public:
9 | HighestHighLessThanFirstHigh();
10 | virtual bool validPattern(const PatternMatch &candidateMatch);
11 | };
12 |
13 | #endif // HIGHESTHIGHLESSTHANFIRSTHIGH_H
14 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LastValueAbovePointValue.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LastValueCloseAbovePointValue.cpp
3 | *
4 | * Created on: Jun 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "LastValueAbovePointValue.h"
9 |
10 | LastValueAbovePointValue::LastValueAbovePointValue(const PeriodValueRefPtr &perValRef, double thresholdPointValue)
11 | : perValRef_(perValRef),
12 | thresholdPointValue_(thresholdPointValue)
13 | {
14 | assert(thresholdPointValue_ >= 0.0);
15 |
16 | }
17 |
18 | bool LastValueAbovePointValue::validPattern(const PatternMatch &candidateMatch)
19 | {
20 | return (perValRef_->referencedVal(candidateMatch.lastValue()) >= thresholdPointValue_)?true:false;
21 | }
22 |
23 |
24 | LastValueAbovePointValue::~LastValueAbovePointValue() {
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LastValueAbovePointValue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LastValueCloseAbovePointValue.h
3 | *
4 | * Created on: Jun 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef LASTVALUEABOVEPOINTVALUE_H_
9 | #define LASTVALUEABOVEPOINTVALUE_H_
10 |
11 | #include "PatternMatchValidator.h"
12 | #include "PeriodValueRef.h"
13 |
14 | class LastValueAbovePointValue: public PatternMatchValidator {
15 | private:
16 | // Parameterize which value from the PeriodVal is used is used for comparison
17 | // (e.g., high, low close).
18 | PeriodValueRefPtr perValRef_;
19 |
20 | double thresholdPointValue_;
21 | public:
22 | LastValueAbovePointValue(const PeriodValueRefPtr &perValRef, double thresholdPointValue);
23 |
24 | bool validPattern(const PatternMatch &candidateMatch);
25 |
26 | virtual ~LastValueAbovePointValue();
27 | };
28 |
29 | #endif /* LASTVALUEABOVEPOINTVALUE_H_ */
30 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LowerHighPatternMatchValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | #include "LowerHighPatternMatchValidatorFactory.h"
2 | #include "ValueComparator.h"
3 | #include "PatternMatchValueRef.h"
4 | #include "ValueComparisonMatchValidator.h"
5 |
6 |
7 | LowerHighPatternMatchValidatorFactory::LowerHighPatternMatchValidatorFactory()
8 | {
9 | }
10 |
11 |
12 | PatternMatchValidatorPtr LowerHighPatternMatchValidatorFactory::createValidator(const PatternMatchVector &previousMatches) const
13 | {
14 | assert(previousMatches.size()==1); // only works when provided with 1 previous match.
15 |
16 | PatternMatchPtr prevMatch = previousMatches[0];
17 |
18 | ValueComparatorPtr lessThanCompare(new LessThanValueComparator());
19 |
20 | PatternMatchValueRefPtr prevHigh(new FixedPatternMatchValueRef(prevMatch->highestHigh()));
21 |
22 | PatternMatchValueRefPtr validationHighRef(new HighestHighPatternMatchValueRef());
23 |
24 | PatternMatchValidatorPtr lowerHighValidator(
25 | new ValueComparisonMatchValidator(validationHighRef,prevHigh,lessThanCompare));
26 |
27 | return lowerHighValidator;
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LowerHighPatternMatchValidatorFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef LOWERHIGHPATTERNMATCHVALIDATORFACTORY_H
2 | #define LOWERHIGHPATTERNMATCHVALIDATORFACTORY_H
3 |
4 | #include "PatternMatchValidatorFactory.h"
5 |
6 | class LowerHighPatternMatchValidatorFactory : public PatternMatchValidatorFactory
7 | {
8 | public:
9 | LowerHighPatternMatchValidatorFactory();
10 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
11 | };
12 |
13 | #endif // LOWERHIGHPATTERNMATCHVALIDATORFACTORY_H
14 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LowestLowGreaterThanLastLow.cpp:
--------------------------------------------------------------------------------
1 | #include "LowestLowGreaterThanLastLow.h"
2 |
3 | LowestLowGreaterThanLastLow::LowestLowGreaterThanLastLow()
4 | {
5 | }
6 |
7 | bool LowestLowGreaterThanLastLow::validPattern(const PatternMatch &candidateMatch)
8 | {
9 | double lowestLow = candidateMatch.lowestLow();
10 | double lastLow = candidateMatch.lastValue().low();
11 | return (lastLow <= lowestLow)? true : false;
12 | }
13 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/LowestLowGreaterThanLastLow.h:
--------------------------------------------------------------------------------
1 | #ifndef LOWESTLOWGREATERTHANLASTLOW_H
2 | #define LOWESTLOWGREATERTHANLASTLOW_H
3 |
4 | #include "PatternMatch.h"
5 | #include "PatternMatchValidator.h"
6 |
7 | class LowestLowGreaterThanLastLow : public PatternMatchValidator
8 | {
9 | public:
10 | LowestLowGreaterThanLastLow();
11 | virtual bool validPattern(const PatternMatch &candidateMatch);
12 | };
13 |
14 | #endif // LOWESTLOWGREATERTHANLASTLOW_H
15 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ORPatternMatchValidator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ORPatternMatchValidator.cpp
3 | *
4 | * Created on: Jun 19, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | ORPatternMatchValidator::ORPatternMatchValidator(const PatternMatchValidatorList &orList)
11 | : orList_(orList)
12 | {
13 | }
14 |
15 | bool ORPatternMatchValidator::validPattern(const PatternMatch &candidateMatch)
16 | {
17 | if(orList_.size() == 0)
18 | {
19 | return true;
20 | }
21 | else
22 | {
23 | for(PatternMatchValidatorList::const_iterator valIter = orList_.begin();
24 | valIter != orList_.end(); valIter++)
25 | {
26 | if((*valIter)->validPattern(candidateMatch))
27 | {
28 | return true;
29 | }
30 | }
31 | return false;
32 | }
33 | }
34 |
35 |
36 |
37 | ORPatternMatchValidator::~ORPatternMatchValidator() {
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ORPatternMatchValidator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ORPatternMatchValidator.h
3 | *
4 | * Created on: Jun 19, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ORPATTERNMATCHVALIDATOR_H_
9 | #define ORPATTERNMATCHVALIDATOR_H_
10 |
11 | #include
12 |
13 | // PatternMatchValidator which performs a boolean OR for
14 | // the validPattern() results for the validators in orList.
15 | class ORPatternMatchValidator: public PatternMatchValidator {
16 | private:
17 | PatternMatchValidatorList orList_;
18 | public:
19 | ORPatternMatchValidator(const PatternMatchValidatorList &orList);
20 |
21 | virtual bool validPattern(const PatternMatch &candidateMatch);
22 |
23 | virtual ~ORPatternMatchValidator();
24 | };
25 |
26 | #endif /* ORPATTERNMATCHVALIDATOR_H_ */
27 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternLengthAtLeast.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternLengthAtLeast.cpp
3 | *
4 | * Created on: Jun 26, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | PatternLengthAtLeast::PatternLengthAtLeast(unsigned int minPeriods)
11 | : minPeriods_(minPeriods)
12 | {
13 | assert(minPeriods > 0);
14 |
15 | }
16 |
17 | bool PatternLengthAtLeast::validPattern(const PatternMatch &candidateMatch)
18 | {
19 | return (candidateMatch.numPeriods() >= minPeriods_)?true:false;
20 | }
21 |
22 | PatternLengthAtLeast::~PatternLengthAtLeast() {
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternLengthAtLeast.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternLengthAtLeast.h
3 | *
4 | * Created on: Jun 26, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNLENGTHATLEAST_H_
9 | #define PATTERNLENGTHATLEAST_H_
10 |
11 | #include
12 |
13 | class PatternLengthAtLeast: public PatternMatchValidator {
14 | private:
15 | unsigned int minPeriods_;
16 | public:
17 | PatternLengthAtLeast(unsigned int minPeriods);
18 | virtual bool validPattern(const PatternMatch &candidateMatch);
19 | virtual ~PatternLengthAtLeast();
20 | };
21 |
22 | #endif /* PATTERNLENGTHATLEAST_H_ */
23 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternLengthLessThanEqual.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternLengthLessThanEqual.cpp
3 | *
4 | * Created on: Jun 27, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | PatternLengthLessThanEqual::PatternLengthLessThanEqual(unsigned int maxPeriods)
11 | : maxPeriods_(maxPeriods)
12 | {
13 | assert(maxPeriods > 0);
14 | }
15 |
16 | bool PatternLengthLessThanEqual::validPattern(const PatternMatch &candidateMatch)
17 | {
18 | return (candidateMatch.numPeriods() <= maxPeriods_)?true:false;
19 | }
20 |
21 |
22 | PatternLengthLessThanEqual::~PatternLengthLessThanEqual() {
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternLengthLessThanEqual.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternLengthLessThanEqual.h
3 | *
4 | * Created on: Jun 27, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNLENGTHLESSTHANEQUAL_H_
9 | #define PATTERNLENGTHLESSTHANEQUAL_H_
10 |
11 | #include
12 |
13 | class PatternLengthLessThanEqual: public PatternMatchValidator {
14 | private:
15 | unsigned int maxPeriods_;
16 | public:
17 | PatternLengthLessThanEqual(unsigned int maxPeriods);
18 | virtual bool validPattern(const PatternMatch &candidateMatch);
19 | virtual ~PatternLengthLessThanEqual();
20 | };
21 |
22 | #endif /* PATTERNLENGTHLESSTHANEQUAL_H_ */
23 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternMatchValidator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchValidator.cpp
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include "PatternMatchValidator.h"
9 |
10 | PatternMatchValidator::PatternMatchValidator() {
11 | }
12 |
13 | PatternMatchValidator::~PatternMatchValidator() {
14 | }
15 |
16 | PatternMatchListPtr PatternMatchValidator::filterMatches(const PatternMatchValidatorPtr &validator,
17 | const PatternMatchListPtr &unfilteredMatches)
18 | {
19 | PatternMatchListPtr filteredMatches(new PatternMatchList());
20 | for(PatternMatchList::const_iterator matchIter = unfilteredMatches->begin();
21 | matchIter != unfilteredMatches->end(); matchIter++)
22 | {
23 | if(validator->validPattern(**matchIter))
24 | {
25 | filteredMatches->push_back(*matchIter);
26 | }
27 | }
28 | return filteredMatches;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternMatchValidator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchValidator.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHVALIDATOR_H_
9 | #define PATTERNMATCHVALIDATOR_H_
10 |
11 | #include
12 | #include "PatternMatch.h"
13 |
14 | class PatternMatchValidator;
15 | typedef boost::shared_ptr PatternMatchValidatorPtr;
16 | typedef std::list PatternMatchValidatorList;
17 |
18 |
19 | // The PatternMatchValidator class is a base class for classes
20 | // which validate a pattern as a whole, given a candidate match
21 | // (e.g., based upon length, % change since start, etc).
22 | class PatternMatchValidator {
23 | public:
24 | PatternMatchValidator();
25 |
26 | // TODO - Change argument to PatternMatchPtr. In the context of scanning
27 | // PatternMatchPtr is always passed around.
28 | virtual bool validPattern(const PatternMatch &candidateMatch) = 0;
29 |
30 | static PatternMatchListPtr filterMatches(const PatternMatchValidatorPtr &validator,
31 | const PatternMatchListPtr &unfilteredMatches);
32 |
33 | virtual ~PatternMatchValidator();
34 | };
35 |
36 |
37 | #endif /* PATTERNMATCHVALIDATOR_H_ */
38 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternMatchValidatorCreationHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchValidatorCreationHelper.h
3 | *
4 | * Created on: Jul 8, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHVALIDATORCREATIONHELPER_H_
9 | #define PATTERNMATCHVALIDATORCREATIONHELPER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PatternMatchValueRef.h"
13 | #include "ValueComparisonMatchValidator.h"
14 | #include "DoubleRange.h"
15 | #include "PeriodValueRef.h"
16 |
17 | namespace patternMatchValidatorCreationHelper
18 | {
19 |
20 | PatternMatchValidatorPtr minValValidator(double minVal, const PatternMatchValueRefPtr &comparisonValRef);
21 |
22 | PatternMatchValidatorPtr depthWithinRangeValidator(const DoubleRange &minMaxDepthPerc);
23 | PatternMatchValidatorPtr depthSinceStartWithinRangeValidator(const DoubleRange &minMaxDepthPerc);
24 |
25 | // In comparison with another pattern 'compareWith', validate that the given
26 | // pattern has a lower low than compareWith.
27 | PatternMatchValidatorPtr lowerLowValidator(const PatternMatchPtr &compareWith);
28 |
29 | PatternMatchValidatorPtr lowAbovePercDepthOfOtherPattern(const PatternMatchPtr &otherPattern, double percDepthOther);
30 |
31 | PatternMatchValidatorPtr lastHighAboveFixedValue(double thresholdValue);
32 | PatternMatchValidatorPtr lastHighAboveFirstHigh();
33 |
34 | PatternMatchValidatorPtr highestHighBelowLastHigh();
35 |
36 | PatternMatchValidatorPtr highestCloseBelowFirstHigh();
37 |
38 | }
39 |
40 |
41 | #endif /* PATTERNMATCHVALIDATORCREATIONHELPER_H_ */
42 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternMatchValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchValidatorFactory.cpp
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | PatternMatchValidatorFactory::PatternMatchValidatorFactory() {
11 | }
12 |
13 | PatternMatchValidatorPtr PatternMatchValidatorFactory::createValidator0() const
14 | {
15 | PatternMatchVector previousMatches;
16 | return createValidator(previousMatches);
17 | }
18 |
19 |
20 | PatternMatchValidatorPtr PatternMatchValidatorFactory::createValidator1(const PatternMatchPtr &otherMatch) const
21 | {
22 | PatternMatchVector previousMatches;
23 | previousMatches.push_back(otherMatch);
24 | return createValidator(previousMatches);
25 | }
26 |
27 | PatternMatchValidatorPtr PatternMatchValidatorFactory::createValidator2(const PatternMatchPtr &firstMatch,
28 | const PatternMatchPtr &secondMatch) const
29 | {
30 | PatternMatchVector previousMatches;
31 | previousMatches.push_back(firstMatch);
32 | previousMatches.push_back(secondMatch);
33 | return createValidator(previousMatches);
34 | }
35 |
36 | PatternMatchValidatorPtr PatternMatchValidatorFactory::createValidator3(const PatternMatchPtr &firstMatch,
37 | const PatternMatchPtr &secondMatch,const PatternMatchPtr &thirdMatch) const
38 | {
39 | PatternMatchVector previousMatches;
40 | previousMatches.push_back(firstMatch);
41 | previousMatches.push_back(secondMatch);
42 | previousMatches.push_back(thirdMatch);
43 | return createValidator(previousMatches);
44 | }
45 |
46 | PatternMatchValidatorPtr PatternMatchValidatorFactory::createValidator(const PatternMatchPtr &firstMatch,
47 | const PatternMatchPtr &secondMatch,const PatternMatchPtr &thirdMatch) const
48 | {
49 | PatternMatchVector previousMatches;
50 | previousMatches.push_back(firstMatch);
51 | previousMatches.push_back(secondMatch);
52 | previousMatches.push_back(thirdMatch);
53 | return createValidator(previousMatches);
54 | }
55 |
56 |
57 | PatternMatchValidatorFactory::~PatternMatchValidatorFactory() {
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternMatchValidatorFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternMatchValidatorFactory.h
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNMATCHVALIDATORFACTORY_H_
9 | #define PATTERNMATCHVALIDATORFACTORY_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PatternMatchValidator.h"
13 |
14 | #include
15 |
16 | // The various pattern scanner classes often need (derived) PatternMatchValidator's
17 | // which are constructed & configured based upon a previous pattern. For example,
18 | // DoubleBottomScanner configures the VScanner on the LHS so it's uptrend must
19 | // recover a certain percentage of the initial downtrend. Rather than hard-code
20 | // the various PatternMatchValidators in the scanner classes, the PatternMatchValidatorFactory
21 | // allows the sub-pattern scanners such as VScanner to be configured for the type
22 | // of validation behavior they need.
23 | class PatternMatchValidatorFactory {
24 | public:
25 | PatternMatchValidatorFactory();
26 |
27 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const = 0;
28 |
29 | // Convenience/helper methods for creating validators with a certain number of previous
30 | // matches.
31 | PatternMatchValidatorPtr createValidator0() const;
32 | PatternMatchValidatorPtr createValidator1(const PatternMatchPtr &otherMatch) const;
33 | PatternMatchValidatorPtr createValidator2(const PatternMatchPtr &firstMatch,
34 | const PatternMatchPtr &secondMatch) const;
35 | PatternMatchValidatorPtr createValidator3(const PatternMatchPtr &firstMatch,
36 | const PatternMatchPtr &secondMatch,const PatternMatchPtr &thirdMatch) const;
37 |
38 | PatternMatchValidatorPtr createValidator(const PatternMatchPtr &firstMatch,
39 | const PatternMatchPtr &secondMatch,const PatternMatchPtr &thirdMatch) const;
40 |
41 | virtual ~PatternMatchValidatorFactory();
42 | };
43 |
44 | typedef boost::shared_ptr PatternMatchValidatorFactoryPtr;
45 | typedef std::list PatternMatchValidatorFactoryList;
46 |
47 | #endif /* PATTERNMATCHVALIDATORFACTORY_H_ */
48 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternSegmentValsCloseToLinearEq.cpp:
--------------------------------------------------------------------------------
1 | #include "PatternSegmentValsCloseToLinearEq.h"
2 | #include "SegmentValsCloseToLinearEq.h"
3 |
4 | PatternSegmentValsCloseToLinearEq::PatternSegmentValsCloseToLinearEq(double maxDeltaPercVsEquation)
5 | : maxDeltaPercVsEquation_(maxDeltaPercVsEquation)
6 | {
7 | }
8 |
9 |
10 | bool PatternSegmentValsCloseToLinearEq::validPattern(const PatternMatch &candidateMatch)
11 | {
12 | return SegmentValsCloseToLinearEq(maxDeltaPercVsEquation_).validSegment(candidateMatch.matchSegment());
13 | }
14 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternSegmentValsCloseToLinearEq.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSEGMENTVALSCLOSETOLINEAREQ_H
2 | #define PATTERNSEGMENTVALSCLOSETOLINEAREQ_H
3 |
4 | #include "PatternMatch.h"
5 | #include "PatternMatchValidator.h"
6 |
7 | class PatternSegmentValsCloseToLinearEq : public PatternMatchValidator
8 | {
9 | private:
10 | double maxDeltaPercVsEquation_;
11 | public:
12 | PatternSegmentValsCloseToLinearEq(double maxDeltaPercVsEquation);
13 | virtual bool validPattern(const PatternMatch &candidateMatch);
14 |
15 | };
16 |
17 | #endif // PATTERNSEGMENTVALSCLOSETOLINEAREQ_H
18 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternSlopeWithinRange.cpp:
--------------------------------------------------------------------------------
1 | #include "PatternSlopeWithinRange.h"
2 | #include "SlopeWithinRangeConstraint.h"
3 |
4 | PatternSlopeWithinRange::PatternSlopeWithinRange(const DoubleRange &slopeRange)
5 | : slopeRange_(slopeRange)
6 | {
7 | }
8 |
9 |
10 | bool PatternSlopeWithinRange::validPattern(const PatternMatch &candidateMatch)
11 | {
12 | return SlopeWithinRangeConstraint(slopeRange_).validSegment(candidateMatch.matchSegment());
13 | }
14 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PatternSlopeWithinRange.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSLOPEWITHINRANGE_H
2 | #define PATTERNSLOPEWITHINRANGE_H
3 |
4 |
5 | #include "PatternMatchValidator.h"
6 | #include "DoubleRange.h"
7 |
8 | class PatternSlopeWithinRange : public PatternMatchValidator
9 | {
10 | private:
11 | DoubleRange slopeRange_;
12 | public:
13 | PatternSlopeWithinRange(const DoubleRange &slopeRange);
14 | virtual bool validPattern(const PatternMatch &candidateMatch);
15 | };
16 |
17 | #endif // PATTERNSLOPEWITHINRANGE_H
18 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PercentIntersectingPatternLineValidator.cpp:
--------------------------------------------------------------------------------
1 | #include "PercentIntersectingPatternLineValidator.h"
2 | #include "LinearEquation.h"
3 | #include "ChartSegment.h"
4 |
5 |
6 | #define PERC_INTERSECTING_LINE_DEFAULT_PERC 0.6
7 |
8 | PercentIntersectingPatternLineValidator::PercentIntersectingPatternLineValidator()
9 | {
10 | }
11 |
12 |
13 | bool PercentIntersectingPatternLineValidator::validPattern(const PatternMatch &candidateMatch)
14 | {
15 | assert(candidateMatch.numPeriods() > 1);
16 | assert(candidateMatch.segments().size() ==1); // Only works with single-segment pattern matches
17 |
18 | PeriodValCltn::iterator segBegin = candidateMatch.matchSegment()->segBegin();
19 | PeriodValCltn::iterator segEnd = candidateMatch.matchSegment()->segEnd();
20 |
21 | LinearEquationPtr patternEq = candidateMatch.segments().front()->segmentEq();
22 |
23 | double totalIntersecting = 0.0;
24 | double totalValues = 0.0;
25 |
26 | for(PeriodValCltn::iterator segIter = segBegin; segIter != segEnd; segIter++)
27 | {
28 | if(patternEq->aboveLine((*segIter).highCoord()) &&
29 | patternEq->belowLine((*segIter).lowCoord()))
30 | {
31 | totalIntersecting += 1.0;
32 | }
33 | totalValues += 1.0;
34 | }
35 |
36 | assert(totalValues > 0.0);
37 |
38 |
39 | double percIntersect = totalIntersecting/totalValues;
40 |
41 | if(percIntersect > PERC_INTERSECTING_LINE_DEFAULT_PERC)
42 | {
43 | return true;
44 | }
45 | else
46 | {
47 | return false;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PercentIntersectingPatternLineValidator.h:
--------------------------------------------------------------------------------
1 | #ifndef PERCENTINTERSECTINGPATTERNLINEVALIDATOR_H
2 | #define PERCENTINTERSECTINGPATTERNLINEVALIDATOR_H
3 |
4 | #include "PatternMatchValidator.h"
5 | #include "PatternMatch.h"
6 |
7 | class PercentIntersectingPatternLineValidator : public PatternMatchValidator
8 | {
9 | public:
10 | PercentIntersectingPatternLineValidator();
11 | bool validPattern(const PatternMatch &candidateMatch);
12 | };
13 |
14 | #endif // PERCENTINTERSECTINGPATTERNLINEVALIDATOR_H
15 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternDepthThreshold.cpp:
--------------------------------------------------------------------------------
1 | #include "PrevPatternDepthThreshold.h"
2 | #include "ValueComparisonMatchValidator.h"
3 |
4 | PrevPatternDepthThreshold::PrevPatternDepthThreshold(double depthThresholdMult,
5 | const PatternMatchValueRefPtr &comparisonVal,
6 | const ValueComparatorPtr &comparator)
7 | : depthThresholdMult_(depthThresholdMult),
8 | comparisonVal_(comparisonVal),
9 | comparator_(comparator)
10 | {
11 | assert(depthThresholdMult_ >= 0.0);
12 | assert(depthThresholdMult <= 10.0); // sanity check
13 | }
14 |
15 |
16 | PatternMatchValidatorPtr PrevPatternDepthThreshold::createValidator(
17 | const PatternMatchVector &previousMatches) const
18 | {
19 | // This validator always compares against the first previous match.
20 | assert(previousMatches.size() > 0);
21 | PatternMatchPtr otherMatch = previousMatches[0];
22 |
23 | double depth = otherMatch->depthPoints();
24 | double depthThreshold = otherMatch->highestHigh()-(depth * depthThresholdMult_);
25 |
26 | PatternMatchValueRefPtr thresholdValRef(new FixedPatternMatchValueRef(depthThreshold));
27 |
28 | PatternMatchValidatorPtr compareWithThresholdValidator(
29 | new ValueComparisonMatchValidator(comparisonVal_,thresholdValRef,comparator_));
30 | return compareWithThresholdValidator;
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternDepthThreshold.h:
--------------------------------------------------------------------------------
1 | #ifndef PREVPATTERNDEPTHTHRESHOLD_H
2 | #define PREVPATTERNDEPTHTHRESHOLD_H
3 |
4 | #include "PatternMatchValidatorFactory.h"
5 | #include "PatternMatchValueRef.h"
6 | #include "ValueComparator.h"
7 |
8 | class PrevPatternDepthThreshold : public PatternMatchValidatorFactory
9 | {
10 | private:
11 | double depthThresholdMult_;
12 | PatternMatchValueRefPtr comparisonVal_;
13 | ValueComparatorPtr comparator_;
14 | public:
15 | PrevPatternDepthThreshold(double depthThresholdMult,
16 | const PatternMatchValueRefPtr &comparisonVal,
17 | const ValueComparatorPtr &comparator);
18 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
19 | };
20 |
21 | #endif // PREVPATTERNDEPTHTHRESHOLD_H
22 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternValueCompareValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | #include "PrevPatternValueCompareValidatorFactory.h"
2 | #include "ValueComparisonMatchValidator.h"
3 |
4 | PrevPatternValueCompareValidatorFactory::PrevPatternValueCompareValidatorFactory(
5 | const ValueComparatorPtr &comparison,
6 | const PatternMatchValueRefPtr &compareValueRef)
7 | : comparison_(comparison),
8 | compareValueRef_(compareValueRef)
9 | {
10 |
11 |
12 | }
13 |
14 |
15 | PatternMatchValidatorPtr PrevPatternValueCompareValidatorFactory::createValidator(
16 | const PatternMatchVector &previousMatches) const
17 | {
18 | // This validator always compares against the first previous match.
19 | assert(previousMatches.size() > 0);
20 | PatternMatchPtr otherMatch = previousMatches[0];
21 |
22 | double otherVal = compareValueRef_->patternMatchVal(*otherMatch);
23 | PatternMatchValueRefPtr otherValueRef(new FixedPatternMatchValueRef(otherVal));
24 |
25 | PatternMatchValidatorPtr comparisonValidator(
26 | new ValueComparisonMatchValidator(compareValueRef_,otherValueRef,comparison_));
27 |
28 | return comparisonValidator;
29 | }
30 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternValueCompareValidatorFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef PREVPATTERNVALUECOMPAREVALIDATORFACTORY_H
2 | #define PREVPATTERNVALUECOMPAREVALIDATORFACTORY_H
3 |
4 | #include "PatternMatchValidatorFactory.h"
5 | #include "ValueComparator.h"
6 | #include "PatternMatchValueRef.h"
7 |
8 | class PrevPatternValueCompareValidatorFactory : public PatternMatchValidatorFactory
9 | {
10 | private:
11 | ValueComparatorPtr comparison_;
12 | PatternMatchValueRefPtr compareValueRef_; // value used for comparison
13 | public:
14 | PrevPatternValueCompareValidatorFactory(const ValueComparatorPtr &comparison,
15 | const PatternMatchValueRefPtr &compareValueRef);
16 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
17 | };
18 |
19 | #endif // PREVPATTERNVALUECOMPAREVALIDATORFACTORY_H
20 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternValueRatioValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | #include "PrevPatternValueRatioValidatorFactory.h"
2 | #include "ValueComparator.h"
3 | #include "ANDPatternMatchValidator.h"
4 | #include "ValueComparisonMatchValidator.h"
5 |
6 | PrevPatternValueRatioValidatorFactory::PrevPatternValueRatioValidatorFactory(const DoubleRange &validRatios,
7 | const PatternMatchValueRefPtr &ratioValueRef)
8 | : validRatios_(validRatios),
9 | ratioValueRef_(ratioValueRef)
10 | {
11 | assert(validRatios_.positiveVals()); // ratios must be positive
12 | }
13 |
14 | PatternMatchValidatorPtr PrevPatternValueRatioValidatorFactory::createValidator(
15 | const PatternMatchVector &previousMatches) const
16 | {
17 | // This validator always compares against the first previous match.
18 | assert(previousMatches.size() > 0);
19 | PatternMatchPtr prevMatch = previousMatches[0];
20 |
21 | double prevVal = ratioValueRef_->patternMatchVal(*prevMatch);
22 |
23 | double minRatioThreshold = prevVal*validRatios_.minVal();
24 | PatternMatchValueRefPtr minThresholdValueRef(new FixedPatternMatchValueRef(minRatioThreshold));
25 | ValueComparatorPtr greaterEqualCompare(new GreaterThanEqualValueComparator());
26 | PatternMatchValidatorPtr minRatioValidator(
27 | new ValueComparisonMatchValidator(ratioValueRef_,minThresholdValueRef,greaterEqualCompare));
28 |
29 | double maxRatioThreshold = prevVal*validRatios_.maxVal();
30 | PatternMatchValueRefPtr maxThresholdValueRef(new FixedPatternMatchValueRef(maxRatioThreshold));
31 | ValueComparatorPtr lessEqualCompare(new LessThanEqualValueComparator());
32 | PatternMatchValidatorPtr maxRatioValidator(
33 | new ValueComparisonMatchValidator(ratioValueRef_,maxThresholdValueRef,lessEqualCompare));
34 |
35 | PatternMatchValidatorList minAndMax;
36 | minAndMax.push_back(minRatioValidator);
37 | minAndMax.push_back(maxRatioValidator);
38 |
39 | return PatternMatchValidatorPtr(new ANDPatternMatchValidator(minAndMax));
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/PrevPatternValueRatioValidatorFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef PREVPATTERNVALUERATIOVALIDATORFACTORY_H
2 | #define PREVPATTERNVALUERATIOVALIDATORFACTORY_H
3 |
4 | #include "PatternMatchValidatorFactory.h"
5 | #include "DoubleRange.h"
6 | #include "PatternMatchValueRef.h"
7 |
8 | class PrevPatternValueRatioValidatorFactory : public PatternMatchValidatorFactory
9 | {
10 | private:
11 | DoubleRange validRatios_;
12 | PatternMatchValueRefPtr ratioValueRef_; // value reference for ratio values
13 | public:
14 | PrevPatternValueRatioValidatorFactory(const DoubleRange &validRatios,
15 | const PatternMatchValueRefPtr &ratioValueRef);
16 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
17 | };
18 |
19 | #endif // PREVPATTERNVALUERATIOVALIDATORFACTORY_H
20 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/RecoverPercentOfDepth.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * RecoverPercentOfDepth.cpp
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "PeriodValueRef.h"
10 | #include "DoubleRange.h"
11 | #include "LastValueAbovePointValue.h"
12 | #include "PeriodValueRef.h"
13 |
14 | RecoverPercentOfDepth::RecoverPercentOfDepth(double depthPercRecover)
15 | : depthPercRecover_(depthPercRecover)
16 | {
17 | assert(DoubleRange(0.0,100.0).valueWithinRange(depthPercRecover));
18 | }
19 |
20 |
21 | PatternMatchValidatorPtr RecoverPercentOfDepth::createValidator(
22 | const PatternMatchVector &previousMatches) const
23 | {
24 | // This validator always compares against the first previous match.
25 | assert(previousMatches.size() > 0);
26 | PatternMatchPtr otherMatch = previousMatches[0];
27 |
28 | // Create a pattern match constraint for the up-trend's close to exceed a
29 | // percentage threshold of the immediately preceding downtrend.
30 | PeriodValueRefPtr closeRef(new ClosePeriodValueRef());
31 |
32 | double depthPercBelowHigh = 100.0 - depthPercRecover_;
33 |
34 | double thresholdValBelowHigh = otherMatch->pointsAtPercentOfDepthBelowHigh(depthPercBelowHigh);
35 | PatternMatchValidatorPtr recoverPerc(new
36 | LastValueAbovePointValue(closeRef,thresholdValBelowHigh));
37 |
38 | return recoverPerc;
39 |
40 | }
41 |
42 | RecoverPercentOfDepth::~RecoverPercentOfDepth() {
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/RecoverPercentOfDepth.h:
--------------------------------------------------------------------------------
1 | /*
2 | * RecoverPercentOfDepth.h
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef RECOVERPERCENTOFDEPTH_H_
9 | #define RECOVERPERCENTOFDEPTH_H_
10 |
11 | #include
12 |
13 | class RecoverPercentOfDepth: public PatternMatchValidatorFactory {
14 | private:
15 | double depthPercRecover_;
16 | public:
17 | RecoverPercentOfDepth(double depthPercRecover);
18 |
19 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
20 |
21 | virtual ~RecoverPercentOfDepth();
22 | };
23 |
24 | #endif /* RECOVERPERCENTOFDEPTH_H_ */
25 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/SecondPeriodValuePivotsLower.cpp:
--------------------------------------------------------------------------------
1 | #include "SecondPeriodValuePivotsLower.h"
2 |
3 | SecondPeriodValuePivotsLower::SecondPeriodValuePivotsLower()
4 | {
5 | }
6 |
7 |
8 | bool SecondPeriodValuePivotsLower::validPattern(const PatternMatch &candidateMatch)
9 | {
10 | assert(candidateMatch.numPeriods() > 1);
11 | PeriodValCltn::iterator matchIter = candidateMatch.matchSegment()->segBegin();
12 |
13 | double firstVal = (*matchIter).typicalPrice();
14 |
15 | matchIter++;
16 | double secondVal = (*matchIter).typicalPrice();
17 |
18 | return (firstVal < secondVal)? true : false;
19 | }
20 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/SecondPeriodValuePivotsLower.h:
--------------------------------------------------------------------------------
1 | #ifndef SECONDPERIODVALUEPIVOTSLOWER_H
2 | #define SECONDPERIODVALUEPIVOTSLOWER_H
3 |
4 | #include "PatternMatchValidator.h"
5 |
6 | class SecondPeriodValuePivotsLower : public PatternMatchValidator
7 | {
8 | public:
9 | SecondPeriodValuePivotsLower();
10 |
11 | virtual bool validPattern(const PatternMatch &candidateMatch);
12 | };
13 |
14 | #endif // SECONDPERIODVALUEPIVOTSLOWER_H
15 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/StaticPatternMatchValidatorFactory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * StaticPatternMatchValidatorFactory.cpp
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | StaticPatternMatchValidatorFactory::StaticPatternMatchValidatorFactory(const PatternMatchValidatorPtr &staticValidator)
11 | : staticValidator_(staticValidator)
12 | {
13 | }
14 |
15 | PatternMatchValidatorPtr StaticPatternMatchValidatorFactory::createValidator(
16 | const PatternMatchVector &) const
17 | {
18 | // staticValidor_ is not dependent on the otherMatch for validation,
19 | // just return the validator as is (hence the "static" in the class name).
20 | return staticValidator_;
21 |
22 | }
23 |
24 | StaticPatternMatchValidatorFactory::~StaticPatternMatchValidatorFactory() {
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/StaticPatternMatchValidatorFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * StaticPatternMatchValidatorFactory.h
3 | *
4 | * Created on: Jul 11, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef STATICPATTERNMATCHVALIDATORFACTORY_H_
9 | #define STATICPATTERNMATCHVALIDATORFACTORY_H_
10 |
11 | #include "PatternMatchValidatorFactory.h"
12 |
13 | class StaticPatternMatchValidatorFactory: public PatternMatchValidatorFactory {
14 | private:
15 | PatternMatchValidatorPtr staticValidator_;
16 | public:
17 | StaticPatternMatchValidatorFactory(const PatternMatchValidatorPtr &staticValidator);
18 |
19 | virtual PatternMatchValidatorPtr createValidator(const PatternMatchVector &previousMatches) const;
20 |
21 | virtual ~StaticPatternMatchValidatorFactory();
22 | };
23 |
24 | #endif /* STATICPATTERNMATCHVALIDATORFACTORY_H_ */
25 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ValueComparisonMatchValidator.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LessThanEqualMatchValidator.cpp
3 | *
4 | * Created on: Jul 7, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | ValueComparisonMatchValidator::ValueComparisonMatchValidator(const PatternMatchValueRefPtr &lhsValRef,
11 | const PatternMatchValueRefPtr &rhsValRef,
12 | const ValueComparatorPtr &comparator)
13 | : lhsValRef_(lhsValRef),
14 | rhsValRef_(rhsValRef),
15 | comparator_(comparator)
16 | {
17 | }
18 |
19 | bool ValueComparisonMatchValidator::validPattern(const PatternMatch &candidateMatch)
20 | {
21 | return comparator_->compare(lhsValRef_->patternMatchVal(candidateMatch),
22 | rhsValRef_->patternMatchVal(candidateMatch));
23 | }
24 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ValueComparisonMatchValidator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LessThanEqualMatchValidator.h
3 | *
4 | * Created on: Jul 7, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef LESSTHANEQUALMATCHVALIDATOR_H_
9 | #define LESSTHANEQUALMATCHVALIDATOR_H_
10 |
11 | #include
12 | #include "PatternMatchValueRef.h"
13 | #include "ValueComparator.h"
14 |
15 | class ValueComparisonMatchValidator: public PatternMatchValidator {
16 | private:
17 | PatternMatchValueRefPtr lhsValRef_;
18 | PatternMatchValueRefPtr rhsValRef_;
19 | ValueComparatorPtr comparator_;
20 | public:
21 | ValueComparisonMatchValidator(const PatternMatchValueRefPtr &lhsValRef,
22 | const PatternMatchValueRefPtr &rhsValRef,
23 | const ValueComparatorPtr &comparator);
24 |
25 | virtual bool validPattern(const PatternMatch &candidateMatch);
26 |
27 | virtual ~ValueComparisonMatchValidator() {}
28 | };
29 |
30 | #endif /* LESSTHANEQUALMATCHVALIDATOR_H_ */
31 |
--------------------------------------------------------------------------------
/src/patternMatchValidator/ValuesCloseToTrendLineValidatorMathComment.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/src/patternMatchValidator/ValuesCloseToTrendLineValidatorMathComment.pdf
--------------------------------------------------------------------------------
/src/patternMatchValidator/ValuesCloseToTrendlineValidator.h:
--------------------------------------------------------------------------------
1 | #ifndef VALUESCLOSETOTRENDLINEVALIDATOR_H
2 | #define VALUESCLOSETOTRENDLINEVALIDATOR_H
3 |
4 | #include "PatternMatchValidator.h"
5 |
6 | class ValuesCloseToTrendlineValidator : public PatternMatchValidator
7 | {
8 | public:
9 | ValuesCloseToTrendlineValidator();
10 | virtual bool validPattern(const PatternMatch &candidateMatch);
11 | };
12 |
13 | #endif // VALUESCLOSETOTRENDLINEVALIDATOR_H
14 |
--------------------------------------------------------------------------------
/src/patternScan/AscendingBasePullbackScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AscendingBasePullbackScanner.h
3 | *
4 | * Created on: Jul 9, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ASCENDINGBASEPULLBACKSCANNER_H_
9 | #define ASCENDINGBASEPULLBACKSCANNER_H_
10 |
11 | #include "PeriodValSegment.h"
12 | #include "PatternMatch.h"
13 | #include "DoubleRange.h"
14 |
15 | // An ascending base consists of 3 pull-backs of 10-20%, followed by a break-out
16 | // above the highest one.
17 | class AscendingBasePullbackScanner {
18 | private:
19 | DoubleRange minMaxDepthPerc_;
20 | public:
21 | AscendingBasePullbackScanner(const DoubleRange &minMaxDepthPerc);
22 |
23 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
24 |
25 | virtual ~AscendingBasePullbackScanner();
26 | };
27 |
28 | #endif /* ASCENDINGBASEPULLBACKSCANNER_H_ */
29 |
--------------------------------------------------------------------------------
/src/patternScan/AscendingBaseScanner.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * AscendingBaseScanner.cpp
3 | *
4 | * Created on: Jul 9, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "AscendingBasePullbackScanner.h"
10 | #include "ScannerHelper.h"
11 | #include "CompositePatternMatchValidatorFactory.h"
12 | #include "HigherLowPatternMatchValidatorFactory.h"
13 | #include "PatternMatchFilter.h"
14 |
15 | using namespace scannerHelper;
16 |
17 | AscendingBaseScanner::AscendingBaseScanner() {
18 | }
19 |
20 |
21 | PatternMatchListPtr AscendingBaseScanner::scanPatternMatches(const PeriodValSegmentPtr &chartVals) const
22 | {
23 | DoubleRange ascendingBaseDepthRange(10.0,20.0);
24 | CompositePatternMatchValidatorFactory pullbackValidatorFactory;
25 | pullbackValidatorFactory.addFactory(
26 | PatternMatchValidatorFactoryPtr(new HigherLowPatternMatchValidatorFactory()));
27 |
28 | PatternMatchListPtr ascendingBaseMatches(new PatternMatchList());
29 |
30 | AscendingBasePullbackScanner pullbackScanner(ascendingBaseDepthRange);
31 |
32 | PatternMatchListPtr pullback1Matches = pullbackScanner.scanPatternMatches(chartVals);
33 |
34 | for(PatternMatchList::const_iterator pullback1MatchIter = pullback1Matches->begin();
35 | pullback1MatchIter!=pullback1Matches->end();pullback1MatchIter++)
36 | {
37 | PeriodValSegmentPtr valsFor2ndPullbackScan = (*pullback1MatchIter)->trailingValsWithLastVal();
38 | PatternMatchValidatorPtr pullback2Validator = pullbackValidatorFactory.createValidator1(*pullback1MatchIter);
39 | PatternMatchListPtr pullback2Matches = PatternMatchValidator::filterMatches(pullback2Validator,
40 | pullbackScanner.scanPatternMatches(valsFor2ndPullbackScan));
41 |
42 | for(PatternMatchList::const_iterator pullback2MatchIter = pullback2Matches->begin();
43 | pullback2MatchIter!=pullback2Matches->end();pullback2MatchIter++)
44 | {
45 | PeriodValSegmentPtr valsFor3rdPullbackScan = (*pullback2MatchIter)->trailingValsWithLastVal();
46 | PatternMatchValidatorPtr pullback3Validator = pullbackValidatorFactory.createValidator1(*pullback2MatchIter);
47 | PatternMatchListPtr pullback3Matches = PatternMatchValidator::filterMatches(pullback3Validator,
48 | pullbackScanner.scanPatternMatches(valsFor3rdPullbackScan));
49 |
50 | for(PatternMatchList::const_iterator pullback3MatchIter = pullback3Matches->begin();
51 | pullback3MatchIter!=pullback3Matches->end();pullback3MatchIter++)
52 | {
53 |
54 | PatternMatchPtr overallMatch = (*pullback1MatchIter)->appendMatch(**pullback2MatchIter)
55 | ->appendMatch(**pullback3MatchIter);
56 | // TODO Validate the overall match for length.
57 |
58 | ascendingBaseMatches->push_back(overallMatch);
59 |
60 | } // For each 3rd pull-back
61 | } // for each match of the 2nd pull back
62 | } // for each match in the first pull back
63 |
64 | return patternMatchFilter::filterUniqueStartEndTime(ascendingBaseMatches);
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/src/patternScan/AscendingBaseScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AscendingBaseScanner.h
3 | *
4 | * Created on: Jul 9, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef ASCENDINGBASESCANNER_H_
9 | #define ASCENDINGBASESCANNER_H_
10 |
11 | #include
12 |
13 | class AscendingBaseScanner: public PatternScanner {
14 | public:
15 | AscendingBaseScanner();
16 |
17 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
18 |
19 | virtual ~AscendingBaseScanner() {}
20 | };
21 |
22 | #endif /* ASCENDINGBASESCANNER_H_ */
23 |
--------------------------------------------------------------------------------
/src/patternScan/AscendingTriangleScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "AscendingTriangleScanner.h"
2 | #include "AscendingTrianglePatternMatch.h"
3 |
4 | AscendingTriangleScanner::AscendingTriangleScanner()
5 | : TriangleScanner(WedgeScannerEngine::FLAT_SLOPE_RANGE,WedgeScannerEngine::UPTREND_SLOPE_RANGE)
6 | {
7 | }
8 |
9 | PatternMatchPtr AscendingTriangleScanner::findPatternMatch(const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
10 | {
11 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
12 | if (breakoutInfo)
13 | {
14 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
15 | PatternMatchPtr patternMatch = PatternMatchPtr(new AscendingTrianglePatternMatch(wedgeSeg,
16 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
17 | patternMatch->breakoutInfo = breakoutInfo;
18 | return patternMatch;
19 | }
20 |
21 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
22 | if (breakdownInfo)
23 | {
24 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
25 | PatternMatchPtr patternMatch = PatternMatchPtr(new AscendingTrianglePatternMatch(wedgeSeg,
26 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
27 | patternMatch->breakdownInfo = breakdownInfo;
28 | return patternMatch;
29 | }
30 |
31 | if(wedgeMatchValidationInfo.incompletePatternMatch())
32 | {
33 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
34 | PatternMatchPtr patternMatch = PatternMatchPtr(new AscendingTrianglePatternMatch(wedgeSeg,
35 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
36 | return patternMatch;
37 | }
38 |
39 |
40 | return PatternMatchPtr(); // NULL (smart) pointer
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/patternScan/AscendingTriangleScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef ASCENDINGTRIANGLESCANNER_H
2 | #define ASCENDINGTRIANGLESCANNER_H
3 |
4 | #include "TriangleScanner.h"
5 |
6 | class AscendingTriangleScanner : public TriangleScanner
7 | {
8 | protected:
9 |
10 | // Test if a completed pattern match is found at the location pointed to by
11 | // currPerValIter.
12 | virtual PatternMatchPtr findPatternMatch(const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
13 | public:
14 | AscendingTriangleScanner();
15 | };
16 |
17 | #endif // ASCENDINGTRIANGLESCANNER_H
18 |
--------------------------------------------------------------------------------
/src/patternScan/CupScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * CupScanner.h
3 | *
4 | * Created on: Jun 18, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef CUPSCANNER_H_
9 | #define CUPSCANNER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PeriodValSegment.h"
13 | #include "PatternScannerEngine.h"
14 | #include "CompositePatternMatchValidatorFactory.h"
15 | #include "PatternScanner.h"
16 |
17 | class CupScanner: public PatternScanner {
18 | private:
19 | CompositePatternMatchValidatorFactory downTrendValidatorFactory_;
20 | CompositePatternMatchValidatorFactory flatBottomValidatorFactory_;
21 | CompositePatternMatchValidatorFactory upTrendValidatorFactory_;
22 | CompositePatternMatchValidatorFactory overallValidatorFactory_;
23 |
24 | double trendlineMaxDistancePerc_;
25 | unsigned int minTrendLineSegmentLength_;
26 |
27 | void initConstraints();
28 |
29 | public:
30 | CupScanner();
31 | CupScanner(unsigned int minTrendLineSegmentLength);
32 |
33 | CompositePatternMatchValidatorFactory &downTrendValidatorFactory() { return downTrendValidatorFactory_; }
34 | CompositePatternMatchValidatorFactory &flatBottomValidatorFactory() { return flatBottomValidatorFactory_; }
35 | CompositePatternMatchValidatorFactory &upTrendValidatorFactory() { return upTrendValidatorFactory_; }
36 | CompositePatternMatchValidatorFactory &overallValidatorFactory() { return overallValidatorFactory_; }
37 |
38 |
39 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
40 |
41 | virtual ~CupScanner() {}
42 | };
43 |
44 | #endif /* CUPSCANNER_H_ */
45 |
--------------------------------------------------------------------------------
/src/patternScan/CupWithHandleScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef CUPWITHHANDLESCANNER_H
2 | #define CUPWITHHANDLESCANNER_H
3 |
4 | #include "PatternScanner.h"
5 | #include "CompositePatternMatchValidatorFactory.h"
6 |
7 | class CupWithHandleScanner : public PatternScanner
8 | {
9 | private:
10 | CompositePatternMatchValidatorFactory handleValidatorFactory_;
11 | public:
12 | CupWithHandleScanner();
13 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
14 |
15 | };
16 |
17 | #endif // CUPWITHHANDLESCANNER_H
18 |
--------------------------------------------------------------------------------
/src/patternScan/CupWithoutHandleScanner.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "CupWithoutHandleScanner.h"
4 | #include "CloseWithinPercentOfDepthFromFirstHighValidator.h"
5 | #include "BreakoutAboveFirstHighValidatorFactory.h"
6 | #include "CupScanner.h"
7 | #include "CupWithoutHandlePatternMatch.h"
8 | #include "PatternMatchValidatorCreationHelper.h"
9 | #include "DebugLog.h"
10 |
11 | #define CUP_WITHOUT_HANDLE_SCANNER_CUP_LAST_CLOSE_PERC_ABOVE_DEPTH_FROM_FIRST_CLOSE_THRESHOLD 0.2
12 |
13 | #define CUP_WITHOUT_HANDLE_MIN_DEPTH_PERC_SINCE_START 8.0
14 | #define CUP_WITHOUT_HANDLE_MAX_DEPTH_PERC_SINCE_START 30.0
15 | #define CUP_WITHOUT_HANDLE_MIN_CALENDAR_DAYS_LENGTH 20.0
16 |
17 | using namespace patternMatchValidatorCreationHelper;
18 |
19 | CupWithoutHandleScanner::CupWithoutHandleScanner()
20 | {
21 | }
22 |
23 |
24 | PatternMatchListPtr CupWithoutHandleScanner::scanPatternMatches(const PeriodValSegmentPtr &chartVals) const
25 | {
26 | PatternMatchListPtr cupWithHandleMatches(new PatternMatchList());
27 |
28 | CupScanner cupScanner;
29 | cupScanner.overallValidatorFactory().addFactory(
30 | PatternMatchValidatorFactoryPtr(new BreakoutAboveFirstHighValidatorFactory()));
31 | cupScanner.overallValidatorFactory().addStaticValidator(depthSinceStartWithinRangeValidator(
32 | DoubleRange(CUP_WITHOUT_HANDLE_MIN_DEPTH_PERC_SINCE_START,CUP_WITHOUT_HANDLE_MAX_DEPTH_PERC_SINCE_START)));
33 |
34 | cupScanner.overallValidatorFactory().addStaticValidator(
35 | minValValidator(CUP_WITHOUT_HANDLE_MIN_CALENDAR_DAYS_LENGTH,
36 | PatternMatchValueRefPtr(new CalendarDaysLengthPatternMatchValueRef())));
37 |
38 |
39 | PatternMatchListPtr cupMatches = cupScanner.scanPatternMatches(chartVals);
40 |
41 | for(PatternMatchList::iterator cupIter = cupMatches->begin(); cupIter != cupMatches->end();
42 | cupIter++)
43 | {
44 | cupWithHandleMatches->push_back(PatternMatchPtr(new CupWithoutHandlePatternMatch(*cupIter)));
45 | }
46 |
47 | DEBUG_MSG("CupWithoutHandleScanner: number of cup matches: " << cupWithHandleMatches->size());
48 |
49 | return cupWithHandleMatches;
50 | }
51 |
--------------------------------------------------------------------------------
/src/patternScan/CupWithoutHandleScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef CUPWITHOUTHANDLESCANNER_H
2 | #define CUPWITHOUTHANDLESCANNER_H
3 |
4 | #include "PatternScanner.h"
5 |
6 | class CupWithoutHandleScanner : public PatternScanner
7 | {
8 | public:
9 | CupWithoutHandleScanner();
10 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
11 | };
12 |
13 | #endif // CUPWITHOUTHANDLESCANNER_H
14 |
--------------------------------------------------------------------------------
/src/patternScan/DescendingTriangleScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "DescendingTriangleScanner.h"
2 | #include "DescendingTrianglePatternMatch.h"
3 |
4 | DescendingTriangleScanner::DescendingTriangleScanner()
5 | : TriangleScanner(WedgeScannerEngine::DOWNTREND_SLOPE_RANGE,WedgeScannerEngine::FLAT_SLOPE_RANGE)
6 | {
7 | }
8 |
9 | PatternMatchPtr DescendingTriangleScanner::findPatternMatch(
10 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
11 | {
12 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
13 | if (breakoutInfo)
14 | {
15 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
16 | PatternMatchPtr patternMatch = PatternMatchPtr(new DescendingTrianglePatternMatch(wedgeSeg,
17 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
18 | patternMatch->breakoutInfo = breakoutInfo;
19 | return patternMatch;
20 | }
21 |
22 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
23 | if (breakdownInfo)
24 | {
25 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
26 | PatternMatchPtr patternMatch = PatternMatchPtr(new DescendingTrianglePatternMatch(wedgeSeg,
27 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
28 | patternMatch->breakdownInfo = breakdownInfo;
29 | return patternMatch;
30 | }
31 |
32 | if(wedgeMatchValidationInfo.incompletePatternMatch())
33 | {
34 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
35 | PatternMatchPtr patternMatch = PatternMatchPtr(new DescendingTrianglePatternMatch(wedgeSeg,
36 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
37 | return patternMatch;
38 | }
39 |
40 |
41 |
42 | return PatternMatchPtr(); // NULL (smart) pointer
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/patternScan/DescendingTriangleScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef DESCEDNDINGTRIANGLESCANNER_H
2 | #define DESCEDNDINGTRIANGLESCANNER_H
3 |
4 | #include "TriangleScanner.h"
5 |
6 | class DescendingTriangleScanner : public TriangleScanner
7 | {
8 | protected:
9 |
10 | // Test if a completed pattern match is found at the location pointed to by
11 | // currPerValIter.
12 | virtual PatternMatchPtr findPatternMatch(
13 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
14 | public:
15 | DescendingTriangleScanner();
16 | };
17 |
18 | #endif // FALLINGWEDGESCANNER_H
19 |
--------------------------------------------------------------------------------
/src/patternScan/DoubleBottomScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DoubleBottomScanner.h
3 | *
4 | * Created on: Jul 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef DOUBLEBOTTOMSCANNER_H_
9 | #define DOUBLEBOTTOMSCANNER_H_
10 |
11 | #include
12 | #include "PatternMatchValidator.h"
13 | #include "DoubleRange.h"
14 | #include "CompositePatternMatchValidatorFactory.h"
15 |
16 | class DoubleBottomScanner: public PatternScanner {
17 | private:
18 | DoubleRange minMaxDepthPerc_;
19 |
20 | CompositePatternMatchValidatorFactory rhsVValidatorFactory_;
21 | CompositePatternMatchValidatorFactory lhsVValidatorFactory_;
22 |
23 | void initValidators();
24 |
25 | public:
26 | DoubleBottomScanner(const DoubleRange &minMaxDepthPerc);
27 | DoubleBottomScanner();
28 |
29 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
30 | virtual ~DoubleBottomScanner();
31 | };
32 |
33 | #endif /* DOUBLEBOTTOMSCANNER_H_ */
34 |
--------------------------------------------------------------------------------
/src/patternScan/FallingWedgeScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "FallingWedgeScanner.h"
2 |
3 | #include "FallingWedgePatternMatch.h"
4 | #include "DoubleRange.h"
5 |
6 | #define FALLING_WEDGE_SCANNER_MIN_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO 0.1
7 | #define FALLING_WEDGE_SCANNER_MAX_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO 0.5
8 |
9 | FallingWedgeScanner::FallingWedgeScanner()
10 | : WedgeScanner(WedgeScannerEngine::DOWNTREND_SLOPE_RANGE,WedgeScannerEngine::DOWNTREND_SLOPE_RANGE)
11 | {
12 | }
13 |
14 |
15 | PatternMatchPtr FallingWedgeScanner::findPatternMatch(
16 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
17 | {
18 |
19 | if(!DoubleRange(FALLING_WEDGE_SCANNER_MIN_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO,
20 | FALLING_WEDGE_SCANNER_MAX_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO).valueWithinRange(
21 | wedgeMatchValidationInfo.lastToFirstTrendlineDistanceRatio()))
22 | {
23 | return PatternMatchPtr(); // NULL (smart) pointer
24 | }
25 |
26 |
27 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
28 | if (breakoutInfo)
29 | {
30 | PatternMatchPtr patternMatch = PatternMatchPtr(new FallingWedgePatternMatch(wedgeMatchValidationInfo));
31 | patternMatch->breakoutInfo = breakoutInfo;
32 | return patternMatch;
33 | }
34 |
35 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
36 | if (breakdownInfo)
37 | {
38 | PatternMatchPtr patternMatch = PatternMatchPtr(new FallingWedgePatternMatch(wedgeMatchValidationInfo));
39 | patternMatch->breakdownInfo = breakdownInfo;
40 | return patternMatch;
41 | }
42 |
43 | if(wedgeMatchValidationInfo.incompletePatternMatch())
44 | {
45 | PatternMatchPtr patternMatch = PatternMatchPtr(new FallingWedgePatternMatch(wedgeMatchValidationInfo));
46 | return patternMatch;
47 | }
48 |
49 |
50 | return PatternMatchPtr(); // NULL (smart) pointer
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/patternScan/FallingWedgeScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef FALLINGWEDGESCANNER_H
2 | #define FALLINGWEDGESCANNER_H
3 |
4 | #include "WedgeScanner.h"
5 |
6 | class FallingWedgeScanner: public WedgeScanner
7 | {
8 | public:
9 | FallingWedgeScanner();
10 |
11 | virtual PatternMatchPtr findPatternMatch(
12 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
13 |
14 | };
15 |
16 | #endif // FALLINGWEDGESCANNER_H
17 |
--------------------------------------------------------------------------------
/src/patternScan/InvertedVScanner.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * InvertedVScanner.cpp
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | #include "TrendLineScanner.h"
11 | #include "ScannerHelper.h"
12 | #include "PatternMatchFilter.h"
13 | #include "DebugLog.h"
14 |
15 | using namespace scannerHelper;
16 |
17 |
18 | InvertedVScanner::InvertedVScanner() {
19 | trendLineMaxDistancePerc_ = 3.0;
20 | }
21 |
22 | InvertedVScanner::InvertedVScanner(double trendLineMaxDistancePerc)
23 | : trendLineMaxDistancePerc_(trendLineMaxDistancePerc)
24 | {
25 |
26 | }
27 |
28 | PatternMatchListPtr InvertedVScanner::scanPatternMatches(const PeriodValSegmentPtr &chartVals) const
29 | {
30 | PatternScannerPtr uptrendScanner(new TrendLineScanner(TrendLineScanner::UPTREND_SLOPE_RANGE,trendLineMaxDistancePerc_));
31 | PatternMatchListPtr uptrendMatches = uptrendScanner->scanPatternMatches(chartVals);
32 | DEBUG_MSG("VScanner: number of up-trend matches: " << uptrendMatches->size());
33 |
34 | PatternMatchListPtr invertedVMatches(new PatternMatchList());
35 |
36 | for(PatternMatchList::iterator utMatchIter = uptrendMatches->begin();
37 | utMatchIter!=uptrendMatches->end();utMatchIter++)
38 | {
39 | logMatchInfo("InvertedVScanner: up-trend match",**utMatchIter);
40 |
41 | PatternScannerPtr downtrendScanner(new TrendLineScanner(TrendLineScanner::DOWNTREND_SLOPE_RANGE,trendLineMaxDistancePerc_));
42 | PeriodValSegmentPtr valsForDowntrendScan = (*utMatchIter)->trailingValsWithLastVal();
43 | PatternMatchListPtr downtrendMatches = downtrendScanner->scanPatternMatches(valsForDowntrendScan);
44 |
45 | for(PatternMatchList::iterator dtMatchIter = downtrendMatches->begin();
46 | dtMatchIter!=downtrendMatches->end();dtMatchIter++)
47 | {
48 | PatternMatchValidatorPtr downTrendValidator =
49 | downTrendValidatorFactory_.createValidator1(*dtMatchIter);
50 | if(downTrendValidator->validPattern(**dtMatchIter))
51 | {
52 | PatternMatchPtr overallPattern = (*utMatchIter)->appendMatch(**dtMatchIter);
53 |
54 | PatternMatchValidatorPtr overallValidate =
55 | overallValidatorFactory_.createValidator2(*utMatchIter,*dtMatchIter);
56 | if(overallValidate->validPattern(*overallPattern))
57 | {
58 | invertedVMatches->push_back(overallPattern);
59 | }
60 | }
61 |
62 | } // For each matching up-trend pattern
63 | } // for each down-trend match
64 |
65 | DEBUG_MSG("InvertedVScanner: number of overall matches: " << invertedVMatches->size());
66 |
67 |
68 | // For purposes of pattern matching, there's no need to return duplicate patterns with
69 | // the same start and end date.
70 | return patternMatchFilter::filterUniqueStartEndTime(invertedVMatches);
71 | }
72 |
73 |
74 | InvertedVScanner::~InvertedVScanner() {
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/src/patternScan/InvertedVScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * InvertedVScanner.h
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef INVERTEDVSCANNER_H_
9 | #define INVERTEDVSCANNER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PeriodValSegment.h"
13 | #include "PatternScanner.h"
14 | #include "PatternMatchValidator.h"
15 | #include "CompositePatternMatchValidatorFactory.h"
16 |
17 |
18 | class InvertedVScanner : public PatternScanner {
19 | private:
20 |
21 | double trendLineMaxDistancePerc_;
22 | CompositePatternMatchValidatorFactory downTrendValidatorFactory_;
23 | CompositePatternMatchValidatorFactory overallValidatorFactory_;
24 |
25 | public:
26 |
27 | CompositePatternMatchValidatorFactory &upTrendValidatorFactory() { return downTrendValidatorFactory_; }
28 | CompositePatternMatchValidatorFactory &overallValidatorFactory() { return overallValidatorFactory_; }
29 |
30 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
31 |
32 | InvertedVScanner();
33 | InvertedVScanner(double trendLineMaxDistancePerc);
34 | virtual ~InvertedVScanner();
35 | };
36 |
37 | #endif /* INVERTEDVSCANNER_H_ */
38 |
--------------------------------------------------------------------------------
/src/patternScan/MultiPatternScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * MultiPatternScanner.h
3 | *
4 | * Created on: Jul 16, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef MULTIPATTERNSCANNER_H_
9 | #define MULTIPATTERNSCANNER_H_
10 |
11 | #include "PatternScanner.h"
12 | #include "PeriodValSegment.h"
13 |
14 | class MultiPatternScanner {
15 | private:
16 | PatternScannerPtr singlePatternScanner_;
17 |
18 | void scanFromStartingPoint(const PatternMatchListPtr &matches,
19 | const PeriodValCltn::iterator &scanStartIter, const PeriodValSegmentPtr &chartVals) const;
20 |
21 | public:
22 | MultiPatternScanner(const PatternScannerPtr &singlePatternScanner);
23 |
24 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
25 |
26 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals,
27 | const PeriodValCltnIterListPtr &scanStartingPoints) const;
28 |
29 | // Scan for all the matches starting anywhere in chartVals, but filter the matched
30 | // patterns to those not ending on the same date and the earliest start time.
31 | PatternMatchListPtr scanUniquePatternMatches(const PeriodValSegmentPtr &chartVals) const;
32 |
33 | PatternMatchListPtr scanUniquePatternMatches(const PeriodValSegmentPtr &chartVals,
34 | const PeriodValCltnIterListPtr &scanStartingPoints) const;
35 |
36 |
37 | virtual ~MultiPatternScanner();
38 | };
39 |
40 | #endif /* MULTIPATTERNSCANNER_H_ */
41 |
--------------------------------------------------------------------------------
/src/patternScan/PatternScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternScanner.h
3 | *
4 | * Created on: Jun 20, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNSCANNER_H_
9 | #define PATTERNSCANNER_H_
10 |
11 | #include
12 | #include "PeriodValSegment.h"
13 | #include "PatternMatch.h"
14 |
15 | class PatternScanner {
16 | public:
17 | PatternScanner() {}
18 |
19 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const = 0;
20 |
21 | virtual ~PatternScanner() {}
22 | };
23 |
24 | typedef boost::shared_ptr PatternScannerPtr;
25 |
26 |
27 | #endif /* PATTERNSCANNER_H_ */
28 |
--------------------------------------------------------------------------------
/src/patternScan/PatternScannerEngine.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PatternScanner.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PATTERNSCANNERENGINE_H_
9 | #define PATTERNSCANNERENGINE_H_
10 |
11 | #include "SegmentConstraint.h"
12 | #include "SegmentListConstraint.h"
13 | #include "PatternMatch.h"
14 | #include "PatternMatchValidator.h"
15 | #include "PeriodValSegment.h"
16 | #include "UnsignedIntRange.h"
17 | #include "PatternScanner.h"
18 |
19 | class PatternScannerEngine: public PatternScanner {
20 | private:
21 | SegmentConstraintPtr segmentConstraint_;
22 | SegmentListConstraintPtr segmentListConstraint_;
23 | PatternMatchValidatorPtr patternMatchValidator_;
24 |
25 | UnsignedIntRange segmentLengthRange_;
26 |
27 | PatternMatchListPtr scanPatternMatches(
28 | const ChartSegmentList &leadingSegments,
29 | const PeriodValSegmentPtr &remainingVals) const;
30 | public:
31 | PatternScannerEngine(const SegmentConstraintPtr &segmentConstraint,
32 | const SegmentListConstraintPtr &segmentListConstraint,
33 | const PatternMatchValidatorPtr &patternMatchValidator);
34 |
35 | PatternScannerEngine(const SegmentConstraintPtr &segmentConstraint,
36 | const SegmentListConstraintPtr &segmentListConstraint,
37 | const PatternMatchValidatorPtr &patternMatchValidator,
38 | const UnsignedIntRange &segmentLengthRange);
39 |
40 |
41 | static const UnsignedIntRange DEFAULT_SCAN_SEGMENT_LENGTH_RANGE;
42 |
43 | // Scan to find a pattern match(es) starting at the first value in chartVals.
44 | // This is the main entry point for scanning (i.e., the top level of recursion).
45 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
46 |
47 | virtual ~PatternScannerEngine();
48 | };
49 |
50 |
51 |
52 | #endif /* PATTERNSCANNERENGINE_H_ */
53 |
--------------------------------------------------------------------------------
/src/patternScan/PivotHighScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PivotHighScanner.h
3 | *
4 | * Created on: Jul 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PIVOTHIGHSCANNER_H_
9 | #define PIVOTHIGHSCANNER_H_
10 |
11 | #include "PeriodValSegment.h"
12 | #include "PatternMatch.h"
13 |
14 | class PivotHighScanner {
15 | private:
16 | double pivotHighMaxTrendLineDistancePerc_;
17 | public:
18 | PivotHighScanner();
19 | PivotHighScanner(double maxTrendLineDistancePerc);
20 |
21 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
22 |
23 | PeriodValCltnIterListPtr scanPivotHighBeginIters(const PeriodValSegmentPtr &chartVals) const;
24 |
25 | virtual ~PivotHighScanner();
26 | };
27 |
28 | #endif /* PIVOTHIGHSCANNER_H_ */
29 |
--------------------------------------------------------------------------------
/src/patternScan/PivotLowScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PivotLowScanner.h
3 | *
4 | * Created on: Jul 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PIVOTLOWSCANNER_H_
9 | #define PIVOTLOWSCANNER_H_
10 |
11 | #include "PeriodValSegment.h"
12 | #include "PatternMatch.h"
13 |
14 | class PivotLowScanner {
15 | private:
16 | double pivotLowMaxTrendLineDistancePerc_;
17 | public:
18 | PivotLowScanner();
19 | PivotLowScanner(double maxDistanceToTrendLinesPerc);
20 |
21 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
22 |
23 | virtual ~PivotLowScanner();
24 | };
25 |
26 | #endif /* PIVOTLOWSCANNER_H_ */
27 |
--------------------------------------------------------------------------------
/src/patternScan/RectangleScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "RectangleScanner.h"
2 | #include "TriangleScanner.h"
3 | #include "DoubleRange.h"
4 | #include "RectanglePatternMatch.h"
5 |
6 | #define FLAT_BASE_SCANNER_DEFAULT_MIN_PERIODS 15
7 | #define FLAT_BASE_SCANNER_DEFAULT_MAX_PERIODS 200
8 |
9 | RectangleScanner::RectangleScanner(const UnsignedIntRange &validPeriodRange)
10 | : validPeriodRange_(validPeriodRange)
11 | {
12 | }
13 |
14 | RectangleScanner::RectangleScanner()
15 | : validPeriodRange_(UnsignedIntRange(FLAT_BASE_SCANNER_DEFAULT_MIN_PERIODS,FLAT_BASE_SCANNER_DEFAULT_MAX_PERIODS))
16 | {
17 | }
18 |
19 | bool RectangleScanner::validTrendLines(const ChartSegmentPtr &upperTrendLine,
20 | const ChartSegmentPtr &lowerTrendLine) const
21 | {
22 | DoubleRange validSlopeRange = WedgeScannerEngine::FLAT_SLOPE_RANGE;
23 |
24 | if(!WedgeScannerEngine::validTrendLines(upperTrendLine,lowerTrendLine))
25 | {
26 | return false;
27 | }
28 |
29 | // For starters, the trend-line slope for the upper and lower trendlines must be within
30 | // the acceptable ranges.
31 | if(!(WedgeScannerEngine::validTrendlinePercChangePerYear(validSlopeRange,upperTrendLine) &&
32 | WedgeScannerEngine::validTrendlinePercChangePerYear(validSlopeRange,lowerTrendLine)))
33 | {
34 | return false;
35 | }
36 |
37 |
38 | if(!pivotsInterleaved(upperTrendLine,lowerTrendLine))
39 | {
40 | return false;
41 | }
42 |
43 | return true;
44 | }
45 |
46 | unsigned int RectangleScanner::minPatternPeriods(const ChartSegmentPtr &,
47 | const ChartSegmentPtr &) const
48 | {
49 | return validPeriodRange_.minVal();
50 | }
51 |
52 | unsigned int RectangleScanner::maxPatternPeriods(const ChartSegmentPtr &, const ChartSegmentPtr &) const
53 | {
54 | return validPeriodRange_.maxVal();
55 | }
56 |
57 | PatternMatchPtr RectangleScanner::findPatternMatch(
58 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
59 | {
60 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
61 | if (breakoutInfo)
62 | {
63 | PatternMatchPtr patternMatch = PatternMatchPtr(new RectanglePatternMatch(wedgeMatchValidationInfo));
64 | patternMatch->breakoutInfo = breakoutInfo;
65 | return patternMatch;
66 | }
67 |
68 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
69 | if (breakdownInfo)
70 | {
71 | PatternMatchPtr patternMatch = PatternMatchPtr(new RectanglePatternMatch(wedgeMatchValidationInfo));
72 | patternMatch->breakdownInfo = breakdownInfo;
73 | return patternMatch;
74 | }
75 |
76 | if(wedgeMatchValidationInfo.incompletePatternMatch())
77 | {
78 | PatternMatchPtr patternMatch = PatternMatchPtr(new RectanglePatternMatch(wedgeMatchValidationInfo));
79 | return patternMatch;
80 | }
81 |
82 |
83 | return PatternMatchPtr(); // NULL (smart) pointer
84 |
85 | }
86 |
87 |
88 |
--------------------------------------------------------------------------------
/src/patternScan/RectangleScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef RECTANGLESCANNER_H
2 | #define RECTANGLESCANNER_H
3 |
4 | #include "UnsignedIntRange.h"
5 | #include "WedgeScannerEngine.h"
6 |
7 | class RectangleScanner : public WedgeScannerEngine
8 | {
9 | private:
10 | UnsignedIntRange validPeriodRange_;
11 | public:
12 | RectangleScanner(const UnsignedIntRange &validPeriodRange);
13 | RectangleScanner();
14 |
15 | virtual bool validTrendLines(const ChartSegmentPtr &upperTrendLine,
16 | const ChartSegmentPtr &lowerTrendLine) const;
17 |
18 | // Calculate the minimum and maximum number of periods for a valid
19 | // pattern match.
20 | virtual unsigned int maxPatternPeriods(const ChartSegmentPtr &upperTrendLine,
21 | const ChartSegmentPtr &lowerTrendLine) const;
22 | virtual unsigned int minPatternPeriods(const ChartSegmentPtr &upperTrendLine,
23 | const ChartSegmentPtr &lowerTrendLine) const;
24 |
25 | virtual PatternMatchPtr findPatternMatch(
26 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
27 |
28 | };
29 |
30 | #endif // RECTANGLESCANNER_H
31 |
--------------------------------------------------------------------------------
/src/patternScan/RisingWedgeScanner.cpp:
--------------------------------------------------------------------------------
1 | #include "RisingWedgeScanner.h"
2 |
3 | #include "RisingWedgePatternMatch.h"
4 | #include "DoubleRange.h"
5 |
6 | #define RISING_WEDGE_SCANNER_MIN_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO 0.1
7 | #define RISING_WEDGE_SCANNER_MAX_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO 0.5
8 |
9 | RisingWedgeScanner::RisingWedgeScanner()
10 | : WedgeScanner(WedgeScannerEngine::UPTREND_SLOPE_RANGE,WedgeScannerEngine::UPTREND_SLOPE_RANGE)
11 | {
12 | }
13 |
14 |
15 | PatternMatchPtr RisingWedgeScanner::findPatternMatch(
16 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
17 | {
18 |
19 | if(!DoubleRange(RISING_WEDGE_SCANNER_MIN_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO,
20 | RISING_WEDGE_SCANNER_MAX_LAST_TO_FIRST_TRENDLINE_DISTANCE_RATIO).valueWithinRange(
21 | wedgeMatchValidationInfo.lastToFirstTrendlineDistanceRatio()))
22 | {
23 | return PatternMatchPtr(); // NULL (smart) pointer
24 | }
25 |
26 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
27 | if (breakoutInfo)
28 | {
29 | PatternMatchPtr patternMatch = PatternMatchPtr(new RisingWedgePatternMatch(wedgeMatchValidationInfo));
30 | patternMatch->breakoutInfo = breakoutInfo;
31 | return patternMatch;
32 | }
33 |
34 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
35 | if (breakdownInfo)
36 | {
37 | PatternMatchPtr patternMatch = PatternMatchPtr(new RisingWedgePatternMatch(wedgeMatchValidationInfo));
38 | patternMatch->breakdownInfo = breakdownInfo;
39 | return patternMatch;
40 | }
41 |
42 | if(wedgeMatchValidationInfo.incompletePatternMatch())
43 | {
44 | PatternMatchPtr patternMatch = PatternMatchPtr(new RisingWedgePatternMatch(wedgeMatchValidationInfo));
45 | return patternMatch;
46 | }
47 |
48 | return PatternMatchPtr(); // NULL (smart) pointer
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/patternScan/RisingWedgeScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef RISINGWEDGESCANNER_H
2 | #define RISINGWEDGESCANNER_H
3 |
4 | #include "WedgeScanner.h"
5 |
6 | class RisingWedgeScanner : public WedgeScanner
7 | {
8 | public:
9 | RisingWedgeScanner();
10 |
11 | virtual PatternMatchPtr findPatternMatch(
12 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
13 |
14 | };
15 |
16 | #endif // RISINGWEDGESCANNER_H
17 |
--------------------------------------------------------------------------------
/src/patternScan/ScannerHelper.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ScannerHelper.cpp
3 | *
4 | * Created on: Jul 2, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "PatternMatch.h"
10 | #include "TimeHelper.h"
11 | #include "PatternMatchFilter.h"
12 |
13 | #include "SecondPeriodValuePivotsLower.h"
14 | #include "HighestHighLessThanFirstHigh.h"
15 | #include "LowerHighPatternMatchValidatorFactory.h"
16 | #include "LowestLowGreaterThanLastLow.h"
17 | #include "ValuesCloseToTrendlineValidator.h"
18 | #include "PatternMatchValidatorCreationHelper.h"
19 | #include "RecoverPercentOfDepth.h"
20 | #include "DebugLog.h"
21 |
22 | using namespace timeHelper;
23 |
24 | namespace scannerHelper {
25 |
26 | void logMatchInfo(const std::string &prefix, const PatternMatch &match)
27 | {
28 | DEBUG_MSG(prefix
29 | << ": start = " << formatDate(match.firstValue().periodTime())
30 | << ", end = " << formatDate(match.lastValue().periodTime())
31 | << ", num segments = " << match.numSegments()
32 | << ", depth (pts/%) = " << match.depthPoints() << "/" << match.depthPercent()
33 | << ", last close = " << match.lastValue().close());
34 | }
35 |
36 | void logMatchesInfo(const std::string &prefix, const PatternMatchListPtr &matches)
37 | {
38 | for(PatternMatchList::const_iterator matchIter = matches->begin(); matchIter != matches->end(); matchIter++)
39 | {
40 | logMatchInfo(prefix,**matchIter);
41 | }
42 | }
43 |
44 | void appendValidatedMatches(const PatternMatchListPtr &appendTo,
45 | const PatternMatchListPtr &unfilteredMatches,
46 | const PatternMatchValidatorPtr &matchValidator)
47 | {
48 | PatternMatchListPtr filteredMatches = PatternMatchValidator::filterMatches(
49 | matchValidator,unfilteredMatches);
50 | appendTo->insert(appendTo->end(),filteredMatches->begin(),filteredMatches->end());
51 |
52 | }
53 |
54 | } // namespace
55 |
56 |
--------------------------------------------------------------------------------
/src/patternScan/ScannerHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ScannerHelper.h
3 | *
4 | * Created on: Jul 2, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SCANNERHELPER_H_
9 | #define SCANNERHELPER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PatternMatchValidator.h"
13 | #include "CompositePatternMatchValidatorFactory.h"
14 |
15 | namespace scannerHelper {
16 |
17 | void logMatchInfo(const std::string &prefix, const PatternMatch &match);
18 |
19 | void logMatchesInfo(const std::string &prefix, const PatternMatchListPtr &matches);
20 |
21 | // Filter unfilteredMatches to only those pattern matches passing validation,
22 | // then append the results to the end of appendTo.
23 | void appendValidatedMatches(const PatternMatchListPtr &appendTo,
24 | const PatternMatchListPtr &unfilteredMatches,
25 | const PatternMatchValidatorPtr &matchValidator);
26 | }
27 |
28 |
29 | #endif /* SCANNERHELPER_H_ */
30 |
--------------------------------------------------------------------------------
/src/patternScan/SingleSegmentPatternScannerEngine.cpp:
--------------------------------------------------------------------------------
1 | #include "SingleSegmentPatternScannerEngine.h"
2 | #include "ChartSegment.h"
3 | #include "PatternMatch.h"
4 |
5 |
6 | const UnsignedIntRange SingleSegmentPatternScannerEngine::DEFAULT_SCAN_LENGTH_RANGE(3,200);
7 |
8 |
9 | SingleSegmentPatternScannerEngine::SingleSegmentPatternScannerEngine()
10 | : segmentLengthRange_(SingleSegmentPatternScannerEngine::DEFAULT_SCAN_LENGTH_RANGE)
11 | {
12 | }
13 |
14 | SingleSegmentPatternScannerEngine::SingleSegmentPatternScannerEngine(const UnsignedIntRange &segmentLengthRange)
15 | : segmentLengthRange_(segmentLengthRange)
16 | {
17 | }
18 |
19 |
20 | PatternMatchListPtr SingleSegmentPatternScannerEngine::scanPatternMatches(const PeriodValSegmentPtr &chartVals) const
21 | {
22 | // matchingPatterns remains empty, unless one or patterns are matched
23 | PatternMatchListPtr matchingPatterns = PatternMatchListPtr(new PatternMatchList());
24 |
25 | unsigned int minRemSegmentLen = segmentLengthRange_.minVal();
26 | unsigned int maxRemSegmentLen = std::min((unsigned int)chartVals->numVals(),
27 | segmentLengthRange_.maxVal());
28 |
29 | if(chartVals->numVals() < minRemSegmentLen)
30 | {
31 | // There's not enough values remaining to continue
32 | // matching, so return an empty list of matches.
33 | return matchingPatterns;
34 | }
35 |
36 | PatternMatchValidatorPtr candidateMatchValidator = validatorFactory_.createValidator0();
37 |
38 | // The for loop logic includes a '<=' since a splitPos for maxRemSegmentLen
39 | // will return all the remaining values.
40 | for(unsigned int splitPos = minRemSegmentLen; splitPos <= maxRemSegmentLen; splitPos++)
41 | {
42 | PeriodValSegmentPair segmentSplit = chartVals->split(splitPos);
43 | PeriodValSegmentPtr candidateSegment = segmentSplit.first;
44 |
45 | ChartSegmentPtr chartSeg(new ChartSegment(candidateSegment));
46 | PatternMatchPtr candidateMatch(new PatternMatch(chartSeg));
47 |
48 | if(candidateMatchValidator->validPattern(*candidateMatch))
49 | {
50 | matchingPatterns->push_back(candidateMatch);
51 | }
52 |
53 |
54 | }
55 |
56 | return matchingPatterns;
57 | }
58 |
--------------------------------------------------------------------------------
/src/patternScan/SingleSegmentPatternScannerEngine.h:
--------------------------------------------------------------------------------
1 | #ifndef SINGLESEGMENTPATTERNSCANNERENGINE_H
2 | #define SINGLESEGMENTPATTERNSCANNERENGINE_H
3 |
4 | #include "UnsignedIntRange.h"
5 | #include "PatternMatch.h"
6 | #include "PeriodValSegment.h"
7 | #include "PatternMatchValidatorFactory.h"
8 | #include "CompositePatternMatchValidatorFactory.h"
9 | #include "UnsignedIntRange.h"
10 |
11 | class SingleSegmentPatternScannerEngine
12 | {
13 | private:
14 | UnsignedIntRange segmentLengthRange_;
15 |
16 | CompositePatternMatchValidatorFactory validatorFactory_;
17 |
18 |
19 | public:
20 | SingleSegmentPatternScannerEngine();
21 | SingleSegmentPatternScannerEngine(const UnsignedIntRange &segmentLengthRange);
22 |
23 | static const UnsignedIntRange DEFAULT_SCAN_LENGTH_RANGE;
24 |
25 | PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
26 |
27 | CompositePatternMatchValidatorFactory &validatorFactory() { return validatorFactory_; }
28 |
29 |
30 |
31 | };
32 |
33 | #endif // SINGLESEGMENTPATTERNSCANNERENGINE_H
34 |
--------------------------------------------------------------------------------
/src/patternScan/SymetricTriangleScanner.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SymetricWedgeScanner.cpp
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include "TrendLineScanner.h"
10 | #include "ChartSegment.h"
11 | #include "SymetricTrianglePatternMatch.h"
12 |
13 | SymetricTriangleScanner::SymetricTriangleScanner()
14 | : TriangleScanner(WedgeScannerEngine::DOWNTREND_SLOPE_RANGE,WedgeScannerEngine::UPTREND_SLOPE_RANGE)
15 | {
16 | }
17 |
18 | PatternMatchPtr SymetricTriangleScanner::findPatternMatch(
19 | const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const
20 | {
21 | PatternMatchBreakoutInfoPtr breakoutInfo = wedgeMatchValidationInfo.upperTrendLineBreakout();
22 | if (breakoutInfo)
23 | {
24 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
25 | PatternMatchPtr patternMatch = PatternMatchPtr(new SymetricTrianglePatternMatch(wedgeSeg,
26 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
27 | patternMatch->breakoutInfo = breakoutInfo;
28 | return patternMatch;
29 | }
30 |
31 | PatternMatchBreakoutInfoPtr breakdownInfo = wedgeMatchValidationInfo.lowerTrendLineBreakdown();
32 | if (breakdownInfo)
33 | {
34 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
35 | PatternMatchPtr patternMatch = PatternMatchPtr(new SymetricTrianglePatternMatch(wedgeSeg,
36 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
37 | patternMatch->breakdownInfo = breakdownInfo;
38 | return patternMatch;
39 | }
40 |
41 | if(wedgeMatchValidationInfo.incompletePatternMatch())
42 | {
43 | ChartSegmentPtr wedgeSeg = wedgeMatchValidationInfo.createWedgeSegment();
44 | PatternMatchPtr patternMatch = PatternMatchPtr(new SymetricTrianglePatternMatch(wedgeSeg,
45 | wedgeMatchValidationInfo.upperTrendLine(),wedgeMatchValidationInfo.lowerTrendLine()));
46 | return patternMatch;
47 | }
48 |
49 |
50 | return PatternMatchPtr(); // NULL (smart) pointer
51 |
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/src/patternScan/SymetricTriangleScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SymetricTriangleScanner.h
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef SYMETRICTRIANGLESCANNER_H_
9 | #define SYMETRICTRIANGLESCANNER_H_
10 |
11 | #include
12 |
13 | class SymetricTriangleScanner: public TriangleScanner {
14 | protected:
15 |
16 | // Test if a completed pattern match is found at the location pointed to by
17 | // currPerValIter.
18 | virtual PatternMatchPtr findPatternMatch(const WedgeMatchValidationInfo &wedgeMatchValidationInfo) const;
19 | public:
20 | SymetricTriangleScanner();
21 | };
22 |
23 | #endif /* SYMETRICTRIANGLESCANNER_H_ */
24 |
--------------------------------------------------------------------------------
/src/patternScan/TrendLineScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TrendLineScanner.h
3 | *
4 | * Created on: Jun 20, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef TRENDLINESCANNER_H_
9 | #define TRENDLINESCANNER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PeriodValSegment.h"
13 | #include "PatternScannerEngine.h"
14 | #include "PatternMatchValidator.h"
15 | #include "DoubleRange.h"
16 | #include "UnsignedIntRange.h"
17 |
18 |
19 | class TrendLineScanner: public PatternScanner {
20 | private:
21 | PatternScannerPtr trendScanner_;
22 |
23 | void initTrendScanner(const DoubleRange &slopeRange,
24 | const PatternMatchValidatorPtr &matchConstraint, double maxPercDistanceToLineEquation,
25 | const UnsignedIntRange &segmentLengthRange);
26 | public:
27 | // matchConstraint is a constraint which must match for the whole trend line. The slope of the individual
28 | // segments must be within the given slope range and also the pattern as a whole must match matchContraint.
29 | TrendLineScanner(const DoubleRange &slopeRange,const PatternMatchValidatorPtr &matchConstraint);
30 |
31 | TrendLineScanner(const DoubleRange &slopeRange);
32 | TrendLineScanner(const DoubleRange &slopeRange, double maxPercDistToLineEquation);
33 | TrendLineScanner(const DoubleRange &slopeRange, double maxPercDistToLineEquation, const UnsignedIntRange segmentLengthRange);
34 |
35 | static const DoubleRange DOWNTREND_SLOPE_RANGE;
36 | static const DoubleRange UPTREND_SLOPE_RANGE;
37 | static const DoubleRange FLAT_SLOPE_RANGE;
38 |
39 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
40 |
41 | virtual ~TrendLineScanner();
42 | };
43 |
44 | #endif /* TRENDLINESCANNER_H_ */
45 |
--------------------------------------------------------------------------------
/src/patternScan/TriangleScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TriangleScanner.h
3 | *
4 | * Created on: Aug 1, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef TRIANGLESCANNER_H_
9 | #define TRIANGLESCANNER_H_
10 |
11 | #include
12 | #include "DoubleRange.h"
13 |
14 | class TriangleScanner: public WedgeScannerEngine {
15 | private:
16 | // Threshold for how far a PeriodVal must be to the intercept between
17 | // the lower and upper trend line for a break-out to be valid.
18 | double minPercDistanceToUpperLowerTrendlineIntercept_;
19 |
20 | // The minimum percentage of values in the pattern which must be
21 | // between the upper and lower trend-line. This allows for some
22 | // elasticity in the pattern matching, where a few values may
23 | // whip-saw above and below the trend-lines, but the overall pattern
24 | // is still considered valid.
25 | double minPercValsBetweenTrendlines_;
26 |
27 |
28 |
29 | DoubleRange upperTrendLineSlopeRange_;
30 | DoubleRange lowerTrendLineSlopeRange_;
31 |
32 | protected:
33 |
34 | bool pivotsSpacedOut(const ChartSegmentPtr &upperTrendLine,
35 | const ChartSegmentPtr &lowerTrendLine) const;
36 |
37 |
38 | virtual bool validTrendLines(const ChartSegmentPtr &upperTrendLine,
39 | const ChartSegmentPtr &lowerTrendLine) const;
40 |
41 | // Calculate the minimum and maximum number of periods for a valid
42 | // pattern match.
43 | virtual unsigned int maxPatternPeriods(const ChartSegmentPtr &upperTrendLine,
44 | const ChartSegmentPtr &lowerTrendLine) const;
45 | virtual unsigned int minPatternPeriods(const ChartSegmentPtr &upperTrendLine,
46 | const ChartSegmentPtr &lowerTrendLine) const;
47 |
48 | // The findPatternMatch method is still virtual
49 |
50 | public:
51 | TriangleScanner(const DoubleRange &upperTrendLineSlopeRange,
52 | const DoubleRange &lowerTrendLineSlopeRange);
53 |
54 | virtual ~TriangleScanner();
55 | };
56 |
57 | #endif /* TRIANGLESCANNER_H_ */
58 |
--------------------------------------------------------------------------------
/src/patternScan/VScanner.h:
--------------------------------------------------------------------------------
1 | /*
2 | * VScanner.h
3 | *
4 | * Created on: Jun 20, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef VSCANNER_H_
9 | #define VSCANNER_H_
10 |
11 | #include "PatternMatch.h"
12 | #include "PeriodValSegment.h"
13 | #include "PatternScanner.h"
14 | #include "PatternMatchValidator.h"
15 | #include "CompositePatternMatchValidatorFactory.h"
16 |
17 | // Scan for V shaped patterns. This class is a building block
18 | // for double bottoms or other patterns with a V shape.
19 | class VScanner : public PatternScanner {
20 | private:
21 | CompositePatternMatchValidatorFactory upTrendValidatorFactory_;
22 | CompositePatternMatchValidatorFactory downTrendValidatorFactory_;
23 |
24 | CompositePatternMatchValidatorFactory overallValidatorFactory_;
25 | double trendLineMaxDistancePerc_;
26 | unsigned int minTrendLineSegmentLength_;
27 |
28 | void initValidationConstraints();
29 | public:
30 | VScanner();
31 | VScanner(double trendLineMaxDistancePerc, unsigned int minTrendLineSegmentLength);
32 |
33 | CompositePatternMatchValidatorFactory &downTrendValidatorFactory() { return downTrendValidatorFactory_; }
34 | CompositePatternMatchValidatorFactory &upTrendValidatorFactory() { return upTrendValidatorFactory_; }
35 | CompositePatternMatchValidatorFactory &overallValidatorFactory() { return overallValidatorFactory_; }
36 |
37 | virtual PatternMatchListPtr scanPatternMatches(const PeriodValSegmentPtr &chartVals) const;
38 | virtual ~VScanner();
39 | };
40 |
41 | #endif /* VSCANNER_H_ */
42 |
--------------------------------------------------------------------------------
/src/patternScan/WedgeMatchValidationInfo.h:
--------------------------------------------------------------------------------
1 | #ifndef WEDGEMATCHVALIDATIONINFO_H
2 | #define WEDGEMATCHVALIDATIONINFO_H
3 |
4 | #include "PeriodValSegment.h"
5 | #include "ChartSegment.h"
6 | #include "PatternMatchBreakoutInfo.h"
7 |
8 |
9 | class WedgeMatchValidationInfo
10 | {
11 | private:
12 | PeriodValSegmentPtr chartVals_;
13 | ChartSegmentPtr upperTrendLine_;
14 | ChartSegmentPtr lowerTrendLine_;
15 | PeriodValCltn::iterator currPerValIter_;
16 | public:
17 | WedgeMatchValidationInfo(const PeriodValSegmentPtr &chartVals,
18 | const ChartSegmentPtr &upperTrendLine,
19 | const ChartSegmentPtr &lowerTrendLine,
20 | const PeriodValCltn::iterator &currPerValIter);
21 |
22 | const PeriodValSegmentPtr &chartVals() const { return chartVals_; }
23 | const ChartSegmentPtr &upperTrendLine() const { return upperTrendLine_; }
24 | const ChartSegmentPtr &lowerTrendLine() const { return lowerTrendLine_; }
25 | const PeriodValCltn::iterator &currPerValIter() const { return currPerValIter_; }
26 | const PeriodValCltn::iterator patternBeginIter() const;
27 |
28 | // Return an end to the potential pattern match. This is an ending iterator
29 | // in the same sense as STL's standard end() for collections. In other words,
30 | // don't reference the underlying PeriodValCltn using what is returned from
31 | // this function.
32 | const PeriodValCltn::iterator patternEndIter() const;
33 |
34 |
35 | // Helper functions for validation
36 | double firstXVal() const;
37 | double lastXVal() const;
38 | double distanceBetweenTrendLines(double pseudoXVal) const;
39 | double lastToFirstTrendlineDistanceRatio() const;
40 |
41 |
42 | ChartSegmentPtr createWedgeSegment() const;
43 |
44 | // Returns a non-null pointer to the breakout info if a breakout/breakdown exists,
45 | // otherwise returns the null smart pointer.
46 | PatternMatchBreakoutInfoPtr upperTrendLineBreakout() const;
47 | PatternMatchBreakoutInfoPtr lowerTrendLineBreakdown() const;
48 |
49 | bool incompletePatternMatch() const;
50 | };
51 |
52 | #endif // WEDGEMATCHVALIDATIONINFO_H
53 |
--------------------------------------------------------------------------------
/src/patternScan/WedgeScanner.h:
--------------------------------------------------------------------------------
1 | #ifndef WEDGESCANNER_H
2 | #define WEDGESCANNER_H
3 |
4 | #include "DoubleRange.h"
5 | #include "UnsignedIntRange.h"
6 | #include "WedgeScannerEngine.h"
7 |
8 | class WedgeScanner : public WedgeScannerEngine
9 | {
10 | private:
11 | DoubleRange upperTrendLineSlopeRange_;
12 | DoubleRange lowerTrendLineSlopeRange_;
13 | UnsignedIntRange validPeriodRange_;
14 | public:
15 | WedgeScanner(const DoubleRange &upperTrendLineSlopeRange,
16 | const DoubleRange &lowerTrendLineSlopeRange);
17 |
18 | virtual bool validTrendLines(const ChartSegmentPtr &upperTrendLine,
19 | const ChartSegmentPtr &lowerTrendLine) const;
20 |
21 | // Calculate the minimum and maximum number of periods for a valid
22 | // pattern match.
23 | virtual unsigned int maxPatternPeriods(const ChartSegmentPtr &upperTrendLine,
24 | const ChartSegmentPtr &lowerTrendLine) const;
25 | virtual unsigned int minPatternPeriods(const ChartSegmentPtr &upperTrendLine,
26 | const ChartSegmentPtr &lowerTrendLine) const;
27 |
28 | // The findPatternMatch method is still virtual
29 |
30 | };
31 |
32 | #endif // WEDGESCANNER_H
33 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShape.cpp:
--------------------------------------------------------------------------------
1 | #include "PatternShape.h"
2 |
3 | PatternShape::PatternShape()
4 | {
5 | curveShapes_ = PatternShapePointVectorVectorPtr(new PatternShapePointVectorVector());
6 | lineShapes_ = PatternShapePointVectorVectorPtr(new PatternShapePointVectorVector());
7 | }
8 |
9 | void PatternShape::addCurveShape(const PatternShapePointVectorPtr &curveShape)
10 | {
11 | curveShapes_->push_back(curveShape);
12 | }
13 |
14 | void PatternShape::addLineShape(const PatternShapePointVectorPtr &lineShape)
15 | {
16 | lineShapes_->push_back(lineShape);
17 | }
18 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShape.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSHAPE_H_
2 | #define PATTERNSHAPE_H_
3 |
4 | #include "PeriodVal.h"
5 | #include "PatternShapePoint.h"
6 | #include
7 |
8 |
9 | class PatternShape {
10 | private:
11 | PatternShapePointVectorVectorPtr curveShapes_;
12 | PatternShapePointVectorVectorPtr lineShapes_;
13 | public:
14 | PatternShape();
15 |
16 | // Add a vector of PatternShapePoint's comprising a curve or line
17 | // for the pattern shape.
18 | void addCurveShape(const PatternShapePointVectorPtr &curveShape);
19 | void addLineShape(const PatternShapePointVectorPtr &lineShape);
20 |
21 |
22 | unsigned int numCurveShapes() const { return curveShapes_->size(); }
23 | PatternShapePointVectorVectorPtr curveShapes() const { return curveShapes_; }
24 |
25 | unsigned int numLineShapes() const { return lineShapes_->size(); }
26 | PatternShapePointVectorVectorPtr lineShapes() const { return lineShapes_; }
27 |
28 | unsigned int numShapes() const { return numLineShapes() + numCurveShapes(); }
29 |
30 |
31 | virtual ~PatternShape() {}
32 | };
33 |
34 | typedef boost::shared_ptr PatternShapePtr;
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShapeCurveGenerator.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSHAPECURVEGENERATOR_H
2 | #define PATTERNSHAPECURVEGENERATOR_H
3 |
4 | #include "PatternShapePoint.h"
5 | #include "XYCoord.h"
6 |
7 | class PatternShapeCurveGenerator
8 | {
9 | public:
10 | PatternShapeCurveGenerator() {}
11 |
12 | PatternShapePointVectorPtr createCurvedShape(const XYCoordVector &shapePoints);
13 |
14 | virtual ~PatternShapeCurveGenerator() {}
15 | };
16 |
17 | #endif // PATTERNSHAPECURVEGENERATOR_H
18 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShapeGenerator.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSHAPEGENERATOR_H
2 | #define PATTERNSHAPEGENERATOR_H
3 |
4 | #include "PatternMatchVisitor.h"
5 | #include "PeriodVal.h"
6 | #include "PatternMatch.h"
7 | #include "PatternShapePoint.h"
8 | #include "PatternShape.h"
9 | #include "PatternMatchBreakoutInfo.h"
10 |
11 | class PatternShapeGenerator : public PatternMatchVisitor
12 | {
13 | private:
14 | PatternShapePtr patternShape_;
15 |
16 | PatternMatchBreakoutInfoPtr breakoutInfo_;
17 |
18 | void generateWedgeShape(const PatternMatch &match,
19 | const LinearEquationPtr &upperTrendlineEq, const LinearEquationPtr &lowerTrendLineEq);
20 |
21 | public:
22 | PatternShapeGenerator();
23 |
24 | PatternShapePtr generateShape(PatternMatch &patternMatch);
25 |
26 | virtual void visitTrianglePatternMatch(TrianglePatternMatch&);
27 |
28 | virtual void visitSymetricWedgePatternMatch(SymetricTrianglePatternMatch &);
29 |
30 | virtual void visitDescendingTrianglePatternMatch(DescendingTrianglePatternMatch &);
31 | virtual void visitAscendingTrianglePatternMatch(AscendingTrianglePatternMatch &);
32 |
33 | virtual void visitRectanglePatternMatch(RectanglePatternMatch &);
34 |
35 | virtual void visitWedgePatternMatch(WedgePatternMatch &);
36 |
37 | virtual void visitVPatternMatch(VPatternMatch &);
38 |
39 | virtual void visitDoubleBottomMiddle(DoubleBottomPatternMatch &);
40 | virtual void visitDoubleBottomPatternMatch(DoubleBottomPatternMatch &);
41 |
42 | virtual void visitCupPatternMatch(CupPatternMatch &);
43 |
44 | virtual void visitCupWithHandlePatternMatch(CupWithHandlePatternMatch &);
45 | virtual void visitCupWithHandleHandleStart(CupWithHandlePatternMatch &);
46 |
47 | virtual void visitCupWithoutHandleStart(CupWithoutHandlePatternMatch &);
48 | virtual void visitCupWithoutHandlePatternMatch(CupWithoutHandlePatternMatch &);
49 |
50 | };
51 |
52 | #endif // PATTERNSHAPEGENERATOR_H
53 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShapePoint.cpp:
--------------------------------------------------------------------------------
1 | #include "PatternShapePoint.h"
2 |
3 | PatternShapePoint::PatternShapePoint(double pseudoXVal, double periodVal)
4 | : pseudoXVal_(pseudoXVal),
5 | periodVal_(periodVal)
6 | {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/patternShape/PatternShapePoint.h:
--------------------------------------------------------------------------------
1 | #ifndef PATTERNSHAPEPOINT_H
2 | #define PATTERNSHAPEPOINT_H
3 |
4 | #include
5 | #include
6 |
7 |
8 | class PatternShapePoint
9 | {
10 | private:
11 | double pseudoXVal_;
12 | double periodVal_;
13 | public:
14 | PatternShapePoint(double pseudoXVal, double periodVal);
15 | double periodVal() const { return periodVal_; }
16 | double pseudoXVal() const { return pseudoXVal_; }
17 | };
18 |
19 | typedef std::vector PatternShapePointVector;
20 | typedef boost::shared_ptr PatternShapePointVectorPtr;
21 |
22 | typedef std::vector PatternShapePointVectorVector;
23 | typedef boost::shared_ptr PatternShapePointVectorVectorPtr;
24 |
25 | #endif // PATTERNSHAPEPOINT_H
26 |
--------------------------------------------------------------------------------
/src/quoteData/PerValCltnSlidingWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef PERVALCLTNSLIDINGWINDOW_H
2 | #define PERVALCLTNSLIDINGWINDOW_H
3 |
4 | #include "PeriodVal.h"
5 |
6 | class PerValCltnSlidingWindow
7 | {
8 | private:
9 | PeriodValCltn::iterator cltnBegin_;
10 | PeriodValCltn::iterator cltnEnd_;
11 |
12 | PeriodValCltn::iterator windowBegin_;
13 | PeriodValCltn::iterator windowMiddle_;
14 | PeriodValCltn::iterator windowEnd_;
15 |
16 | unsigned int windowSize_;
17 | public:
18 | PerValCltnSlidingWindow(unsigned int windowSize,
19 | const PeriodValCltn::iterator &cltnBegin,
20 | const PeriodValCltn::iterator &cltnEnd);
21 |
22 | void resetToCltnBegin();
23 | bool windowAtEnd() const;
24 | void advanceWindow();
25 |
26 | const PeriodValCltn::iterator &windowBegin() const;
27 | PeriodValCltn::iterator windowEnd() const;
28 |
29 |
30 | const PeriodValCltn::iterator &windowFirst() const;
31 | const PeriodValCltn::iterator &windowMiddle() const;
32 | const PeriodValCltn::iterator &windowLast() const;
33 |
34 | const PeriodVal &firstVal() const;
35 | const PeriodVal &lastVal() const;
36 | const PeriodVal &middleVal() const;
37 |
38 | static bool windowFitsWithinRange(unsigned int windowSize,
39 | const PeriodValCltn::iterator &cltnBegin,
40 | const PeriodValCltn::iterator &cltnEnd);
41 |
42 | };
43 |
44 | #endif // PERVALCLTNSLIDINGWINDOW_H
45 |
--------------------------------------------------------------------------------
/src/quoteData/PeriodVal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PeriodVal.h
3 | *
4 | * Created on: Jun 10, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PERIODVAL_H_
9 | #define PERIODVAL_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "XYCoord.h"
16 |
17 | class PeriodVal;
18 | typedef std::list PeriodValCltn;
19 | typedef boost::shared_ptr PeriodValCltnPtr;
20 | typedef std::list PeriodValCltnIterList;
21 | typedef boost::shared_ptr PeriodValCltnIterListPtr;
22 |
23 |
24 | class PeriodVal {
25 | private:
26 | boost::posix_time::ptime periodTime_;
27 | double open_;
28 | double high_;
29 | double low_;
30 | double close_;
31 | unsigned int volume_;
32 |
33 | // Each PeriodVal needs to be assigned a unique index value w.r.t the
34 | // other PeriodVal's in the same collection. A "flyweight" iterator is
35 | // used to access all the PeriodVal's, and this index is used for
36 | // calculations with LinearEquations, since a date cannot be used
37 | // as an X value in a LinearEquation.
38 | unsigned int perValIndex_;
39 |
40 | // setIndex is for internal use by code for reading PeriodVal's
41 | void setIndex(unsigned int index) { perValIndex_ = index; }
42 |
43 |
44 | public:
45 | PeriodVal(boost::posix_time::ptime &periodTime,
46 | double open, double high, double low, double close, unsigned int volume,
47 | unsigned int perValIndex);
48 |
49 | const boost::posix_time::ptime &periodTime() const { return periodTime_; }
50 | double open() const { return open_; }
51 | double high() const { return high_; }
52 | double low() const { return low_; }
53 | double close() const { return close_; }
54 | unsigned int volume() const { return volume_; }
55 |
56 | unsigned int perValIndex() const { return perValIndex_; }
57 | double pseudoXVal() const { return (double)perValIndex_; }
58 |
59 | // Coordinate based upon psuedoXVal and the closing price. This
60 | // is used to test the closing price for cross-overs of a LinearEquation's line.
61 | // (e.g. for wedge pattern matching).
62 | XYCoord closeCoord() const { return XYCoord(pseudoXVal(),close()); }
63 | XYCoord typicalCoord() const { return XYCoord(pseudoXVal(),typicalPrice()); }
64 | XYCoord lowCoord() const { return XYCoord(pseudoXVal(),low()); }
65 | XYCoord highCoord() const { return XYCoord(pseudoXVal(),high()); }
66 |
67 | static void reAssignIndices(PeriodValCltn &perValCltn);
68 |
69 | static PeriodValCltnPtr readFromFile(const std::string &fileName);
70 |
71 | double typicalPrice() const;
72 |
73 | friend std::ostream& operator<<(std::ostream& os, const PeriodVal& perVal);
74 |
75 | virtual ~PeriodVal();
76 | };
77 |
78 |
79 |
80 | #endif /* PERIODVAL_H_ */
81 |
--------------------------------------------------------------------------------
/src/quoteData/PeriodValueRef.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * PeriodValueRef.cpp
3 | *
4 | * Created on: Jun 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 |
10 | PeriodValueRef::PeriodValueRef() {
11 | }
12 |
13 | PeriodValueRef::~PeriodValueRef() {
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/src/quoteData/PeriodValueRef.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PeriodValueRef.h
3 | *
4 | * Created on: Jun 30, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef PERIODVALUEREF_H_
9 | #define PERIODVALUEREF_H_
10 |
11 | #include "PeriodVal.h"
12 |
13 | #include
14 |
15 |
16 | class PeriodValueRef {
17 | public:
18 | PeriodValueRef();
19 |
20 | virtual double referencedVal(const PeriodVal &periodVal) const = 0;
21 |
22 | virtual ~PeriodValueRef();
23 | };
24 |
25 | typedef boost::shared_ptr PeriodValueRefPtr;
26 |
27 | class HighPeriodValueRef: public PeriodValueRef {
28 | public:
29 | virtual double referencedVal(const PeriodVal &periodVal) const { return periodVal.high(); }
30 | };
31 |
32 | class LowPeriodValueRef: public PeriodValueRef {
33 | public:
34 | virtual double referencedVal(const PeriodVal &periodVal) const { return periodVal.low(); }
35 | };
36 |
37 |
38 | class TypicalPricePeriodValueRef: public PeriodValueRef {
39 | public:
40 | virtual double referencedVal(const PeriodVal &periodVal) const { return periodVal.typicalPrice(); }
41 | };
42 |
43 | class ClosePeriodValueRef: public PeriodValueRef {
44 | public:
45 | virtual double referencedVal(const PeriodVal &periodVal) const { return periodVal.close(); }
46 | };
47 |
48 |
49 |
50 | #endif /* PERIODVALUEREF_H_ */
51 |
--------------------------------------------------------------------------------
/test/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | PatternRecognitionLibTest
4 |
5 |
6 | PatternRecognitionLib
7 |
8 |
9 |
10 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
11 | clean,full,incremental,
12 |
13 |
14 |
15 |
16 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
17 | full,incremental,
18 |
19 |
20 |
21 |
22 |
23 | org.eclipse.cdt.core.cnature
24 | org.eclipse.cdt.core.ccnature
25 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
26 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
27 |
28 |
29 |
--------------------------------------------------------------------------------
/test/.settings/org.eclipse.ltk.core.refactoring.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
3 |
--------------------------------------------------------------------------------
/test/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Pattern Recognition Library Tests
3 |
4 | ## Running Tests from the Command Line
5 |
6 | To run the tests from the command line, the test executable must be run from the test project's root directory
7 | (i.e., the directory/folder with the ".pro" project file)
8 |
9 | On Windows, the DLL path for Boost and Qt Libraries also needs to first be set as follows in the terminal:
10 |
11 | set PATH=C:\Qt\5.3\mingw482_32\bin;C:\boost_1_56_0\stage\lib;%PATH%
12 |
13 | This will ensure the Boost and Qt libraries will be found by the executable.
14 |
15 | ## Running the Entire Test Suite
16 |
17 | The following will run the entire test suite and generate a summary report at the end.
18 |
19 | $ ../build-TestPatternRecognitionLib-Desktop_Qt_5_3_clang_64bit-Debug/TestPatternRecognitionLib --report_level=detailed
20 |
21 | ## Running a Single Test
22 |
23 | The example below runs a single test.
24 |
25 | $ ../build-TestPatternRecognitionLib-Desktop_Qt_5_3_clang_64bit-Debug/TestPatternRecognitionLib --log_level=all --run_test=PeriodValTest_YahooCSVValid
26 |
27 | ## Filtering Test Output for Errors
28 |
29 | Filtering for failure output is accomplished by re-directing stderr to stdout, then grepping for failure strings.
30 | The given grep command will do a case-insensitive search for each of the words combined with the -e arguments.
31 |
32 | $ ../build-TestPatternRecognitionLib-Desktop_Qt_5_3_clang_64bit-Debug/TestPatternRecognitionLib --report_level=detailed 2>&1 | grep -i -e error -e fail -e abort
33 |
--------------------------------------------------------------------------------
/test/RunTests.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | // The #define's below cause this file to be setup as a main driver
5 | // for all the test cases compiled together for the project.
6 |
7 | #define BOOST_TEST_DYN_LINK
8 | #define BOOST_TEST_MAIN
9 | #define BOOST_TEST_MODULE PatternRecognitionLibTest
10 |
11 | #include
12 |
--------------------------------------------------------------------------------
/test/TestHelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TestUtil.h
3 | *
4 | * Created on: Jun 26, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef TESTHELPER_H_
9 | #define TESTHELPER_H_
10 |
11 | #include "PeriodVal.h"
12 | #include "PatternMatch.h"
13 | #include "PeriodValSegment.h"
14 | #include "TestPerValRange.h"
15 |
16 | #include
17 | #include
18 |
19 | namespace testHelper {
20 |
21 | PeriodVal testPeriodVal(unsigned int year, unsigned int month,
22 | unsigned int day, double val, unsigned int vol, unsigned int periodValIndex);
23 |
24 | PeriodValSegmentPtr synthesizePeriodValSegment(const boost::gregorian::date &startDate,
25 | const TestPerValRangeList &ranges);
26 |
27 | void genPatternMatchInfo(const std::string &prefix, const PatternMatchPtr &patternMatch);
28 | void genPatternMatchListInfo(const std::string prefix, const PatternMatchList &matchList);
29 |
30 | void verifyMatchList(const std::string prefix,
31 | const PatternMatchListPtr &matchList, unsigned int expectedNumMatches);
32 |
33 | void genPeriodValSegmentInfo(const std::string prefix, const PeriodValSegment &perSegment);
34 |
35 | void genPivotLowInfo(const PatternMatchListPtr &pivotLows);
36 | void genPivotHighInfo(const PatternMatchListPtr &pivotLows);
37 |
38 | void verifyPatternMatch(const std::string &prefix,const boost::posix_time::ptime &expectedStart,
39 | const boost::posix_time::ptime &expectedEnd, unsigned int expectedSegments,
40 | const PatternMatchPtr &patternMatch);
41 | void verifyPatternMatch(const std::string &prefix,
42 | const boost::posix_time::ptime &expectedStart,
43 | const boost::posix_time::ptime &expectedEnd, unsigned int expectedSegments,
44 | const PatternMatchListPtr &patternMatchList, unsigned int matchIndex);
45 |
46 | boost::posix_time::ptime dateToTime(unsigned int year, unsigned int month, unsigned int day);
47 |
48 | PatternMatchPtr segmentSpiceToPatternMatch(const PeriodValSegmentPtr &seg, unsigned int beginRange, unsigned int endRange);
49 | PatternMatchPtr segmentToPatternMatch(const PeriodValSegmentPtr &seg);
50 | PatternMatchPtr synthesizePatternMatch(const boost::gregorian::date &startDate,
51 | const TestPerValRangeList &ranges);
52 |
53 | };
54 |
55 | #endif /* TESTHELPER_H_ */
56 |
--------------------------------------------------------------------------------
/test/TestPatternRecognitionLib.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | SOURCES += RunTests.cpp \
7 | math/LinearEquation.cpp \
8 | math/XYCoord.cpp \
9 | patternMatch/PatternMatch.cpp \
10 | patternMatch/PatternMatchValidator.cpp \
11 | patternMatchFilter/PatternMatchFilter.cpp \
12 | patternScan/AscendingBase.cpp \
13 | patternScan/CupWithHandle.cpp \
14 | patternScan/DoubleBottom.cpp \
15 | patternScan/MultiPatternScan.cpp \
16 | patternScan/TrendLine.cpp \
17 | patternScan/VScanner.cpp \
18 | quoteData/PeriodVal.cpp \
19 | quoteData/PeriodValSegment.cpp \
20 | TestHelper.cpp \
21 | TestPerValRange.cpp \
22 | patternShape/PatternShape.cpp \
23 | patternScan/PivotScanner.cpp \
24 | patternScan/CupWithoutHandle.cpp \
25 | patternScan/TriangleScanners.cpp \
26 | patternScan/WedgeScanners.cpp
27 |
28 | HEADERS += \
29 | TestHelper.h \
30 | TestPerValRange.h
31 |
32 |
33 | # Configure compiling and linking against libc++ instead of libstdc++
34 | # This is needed to ensure consistency for all components, including
35 | # the boost library.
36 | macx: QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 -stdlib=libc++
37 | QMAKE_CXXFLAGS += -std=c++11
38 | macx: LIBS += -mmacosx-version-min=10.7 -stdlib=libc++
39 | CONFIG += c++11
40 |
41 | ## Link with pre-built version of Boost. Using -isystem to include the boost headers supresses
42 | ## Warnings from these headers.
43 | DEFINES += BOOST_ALL_DYN_LINK
44 | DEFINES += BOOST_LOG_DYN_LINK
45 | macx: QMAKE_CXXFLAGS += -isystem /usr/local/boost156/include
46 | win32: QMAKE_CXXFLAGS += -isystem c:/boost_1_56_0
47 | macx: LIBS += -L/usr/local/boost156/lib -lboost_date_time-mt -lboost_unit_test_framework-mt
48 | win32:LIBS += -L"C:/boost_1_56_0/stage/lib/" -lboost_date_time-mgw48-mt-1_56 -llibboost_unit_test_framework-mgw48-1_56
49 |
50 |
51 | CONFIG(debug, debug|release) {
52 | macx: PATTERNRECOGLIBDIR = build-PatternRecognitionLib-Desktop_Qt_5_3_clang_64bit-Debug
53 | win32: PATTERNRECOGLIBDIR = build-PatternRecognitionLib-Desktop_Qt_5_3_MinGW_32bit-Debug\debug
54 | } else {
55 | macx: PATTERNRECOGLIBDIR = build-PatternRecognitionLib-Desktop_Qt_5_3_clang_64bit-Release
56 | win32: PATTERNRECOGLIBDIR = build-PatternRecognitionLib-Desktop_Qt_5_3_MinGW_32bit-Release\release
57 | DEFINES += QT_NO_DEBUG_OUTPUT
58 | DEFINES += NDEBUG
59 | }
60 |
61 |
62 | # Link with the PatternRecognitionLib and establish a build dependency to re-link if the library changes.
63 | LIBS += -L$$PWD/../$$PATTERNRECOGLIBDIR -lPatternRecognitionLib
64 | PRE_TARGETDEPS += $$PWD/../$$PATTERNRECOGLIBDIR/libPatternRecognitionLib.a
65 |
66 | INCLUDEPATH += $$PWD/../src/chartSegment\
67 | $$PWD/../src/chartSegmentList\
68 | $$PWD/../src/date\
69 | $$PWD/../src/math\
70 | $$PWD/../src/patternMatch\
71 | $$PWD/../src/patternMatchFilter\
72 | $$PWD/../src/patternMatchValidator\
73 | $$PWD/../src/patternScan\
74 | $$PWD/../src/patternShape\
75 | $$PWD/../src/quoteData
76 |
77 | OTHER_FILES += \
78 | README.md
79 |
--------------------------------------------------------------------------------
/test/TestPerValRange.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * TestPerValRange.cpp
3 | *
4 | * Created on: Jul 7, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #include
9 | #include
10 |
11 | TestPerValRange::TestPerValRange(unsigned int numVals, double startVal, double endVal)
12 | : numVals_(numVals),
13 | startVal_(startVal),
14 | endVal_(endVal)
15 | {
16 | assert(numVals >= 2);
17 | assert(startVal != endVal);
18 | }
19 |
20 | double TestPerValRange::valIncr() const
21 | {
22 | return (endVal() - startVal())/(double)(numVals()-1);
23 | }
24 |
25 |
26 |
27 | TestPerValRange::~TestPerValRange() {
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/test/TestPerValRange.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TestPerValRange.h
3 | *
4 | * Created on: Jul 7, 2014
5 | * Author: sroehling
6 | */
7 |
8 | #ifndef TESTPERVALRANGE_H_
9 | #define TESTPERVALRANGE_H_
10 |
11 | #include
12 |
13 | class TestPerValRange {
14 | private:
15 | unsigned int numVals_;
16 | double startVal_;
17 | double endVal_;
18 |
19 | public:
20 | TestPerValRange(unsigned int numVals, double startVal, double endVal);
21 |
22 | double startVal() const { return startVal_; }
23 | double endVal() const { return endVal_; }
24 | unsigned int numVals() const { return numVals_; }
25 | double valIncr() const;
26 |
27 | virtual ~TestPerValRange();
28 | };
29 |
30 | #endif /* TESTPERVALRANGE_H_ */
31 |
32 | typedef std::list TestPerValRangeList;
33 |
--------------------------------------------------------------------------------
/test/math/LinearEquation.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "LinearEquation.h"
5 |
6 | BOOST_AUTO_TEST_CASE( LinearEquationTest )
7 | {
8 | LinearEquation noSlope(0.0,0.0);
9 |
10 | BOOST_CHECK( noSlope.yVal(0.0) == 0.0);
11 | }
12 |
13 |
14 | BOOST_AUTO_TEST_CASE( LinearEquation_Intersection )
15 | {
16 |
17 | // Example taken from: https://www.evernote.com/shard/s3/sh/da1d5daa-2e24-404a-b26c-f84d9edb1aa3/4c4e4dd48d11085f49629933e0600aa2
18 | LinearEquation equation1(3.0,2.0);
19 | LinearEquation equation2(2.0,-1.0);
20 |
21 | XYCoord intercept = equation1.intercept(equation2);
22 |
23 | BOOST_CHECK( intercept.x() == -3.0);
24 | BOOST_CHECK( intercept.y() == -7.0);
25 | }
26 |
27 |
28 | BOOST_AUTO_TEST_CASE( LinearEquation_InterceptEndpoints )
29 | {
30 |
31 | BOOST_TEST_MESSAGE("LinearEquation_InterceptEndpoints: checking intercept used in WedgeScannerEngine_SynthesizedPattern test case");
32 |
33 | LinearEquation upperTrendline(XYCoord(3,100),XYCoord(11,98));
34 | LinearEquation lowerTrendline(XYCoord(7,92),XYCoord(15,94));
35 |
36 | XYCoord intercept = upperTrendline.intercept(lowerTrendline);
37 |
38 | BOOST_TEST_MESSAGE("LinearEquation_InterceptEndpoints: intercept: " << intercept);
39 |
40 | BOOST_CHECK_CLOSE( intercept.x(),21,0.001);
41 | BOOST_CHECK_CLOSE( intercept.y(),95.5,0.001);
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/test/math/XYCoord.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | #define BOOST_TEST_DYN_LINK
3 | #define BOOST_TEST_MODULE LinearEquationTest
4 | */
5 |
6 | #include
7 |
8 | #include "XYCoord.h"
9 |
10 | BOOST_AUTO_TEST_CASE( XYCoordTest )
11 | {
12 | XYCoord simple(1.0,2.0);
13 |
14 | BOOST_CHECK( simple.x() == 1.0);
15 | BOOST_CHECK( simple.y() == 2.0);
16 | }
17 |
--------------------------------------------------------------------------------
/test/patternMatch/PatternMatch.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "PatternMatch.h"
4 | #include "PeriodVal.h"
5 | #include "PeriodValSegment.h"
6 | #include "ChartSegment.h"
7 | #include "TestHelper.h"
8 |
9 | using namespace testHelper;
10 |
11 | BOOST_AUTO_TEST_CASE( PatternMatchNumPeriods )
12 | {
13 |
14 | PeriodValCltnPtr testData(new PeriodValCltn());
15 |
16 | unsigned int periodValIndex=0;
17 | testData->push_back(testPeriodVal(2013,1,1,1.0,1,periodValIndex++));
18 | testData->push_back(testPeriodVal(2013,2,1,2.0,2,periodValIndex++));
19 | testData->push_back(testPeriodVal(2013,3,1,3.0,3,periodValIndex++));
20 | testData->push_back(testPeriodVal(2013,4,1,4.0,4,periodValIndex++));
21 | testData->push_back(testPeriodVal(2013,5,1,5.0,5,periodValIndex++));
22 |
23 | PeriodValSegmentPtr testSeg(new PeriodValSegment(testData));
24 | PeriodValSegmentPair splitTestSeg = testSeg->split(3);
25 |
26 |
27 | ChartSegmentPtr chartSeg1(new ChartSegment(splitTestSeg.first));
28 | ChartSegmentPtr chartSeg2(new ChartSegment(splitTestSeg.second->moveSegBeginToPrev()));
29 |
30 | ChartSegmentList matchSegments;
31 | matchSegments.push_back(chartSeg1);
32 | matchSegments.push_back(chartSeg2);
33 |
34 | PatternMatchPtr patternMatch(new PatternMatch(matchSegments));
35 |
36 | BOOST_CHECK(patternMatch->numPeriods()==5);
37 |
38 | ChartSegmentList matchSegments2;
39 | matchSegments2.push_back(chartSeg1);
40 | PatternMatchPtr patternMatchSingleSeg(new PatternMatch(matchSegments2));
41 | BOOST_CHECK(patternMatchSingleSeg->numPeriods()==3);
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/test/patternScan/AMBA_Daily_2014.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2014-03-03,32.69,33.45,31.68,33.10,1463100,33.10
3 | 2014-02-28,34.01,34.76,32.20,33.45,1436100,33.45
4 | 2014-02-27,32.64,34.09,32.64,33.91,1215400,33.91
5 | 2014-02-26,31.58,33.25,31.26,32.52,1204500,32.52
6 | 2014-02-25,31.80,32.41,30.75,31.09,1088400,31.09
7 | 2014-02-24,32.06,32.25,31.55,31.57,811200,31.57
8 | 2014-02-21,32.00,32.70,31.65,31.84,1183500,31.84
9 | 2014-02-20,30.66,31.91,30.33,31.65,848500,31.65
10 | 2014-02-19,31.58,32.46,30.50,30.88,1249700,30.88
11 | 2014-02-18,30.24,31.43,29.82,31.26,1198900,31.26
12 | 2014-02-14,29.96,30.39,29.40,29.97,720500,29.97
13 | 2014-02-13,28.64,29.96,27.81,29.90,1141300,29.90
14 | 2014-02-12,29.93,30.80,28.68,28.91,1159400,28.91
15 | 2014-02-11,28.64,29.87,28.40,29.46,1870000,29.46
16 | 2014-02-10,27.40,28.46,27.32,28.11,1485800,28.11
17 | 2014-02-07,25.76,28.58,25.75,27.27,1866600,27.27
18 | 2014-02-06,27.10,27.15,25.50,25.95,1708900,25.95
19 | 2014-02-05,29.40,29.46,24.69,27.09,4840200,27.09
20 | 2014-02-04,30.50,30.78,29.27,29.54,1106400,29.54
21 | 2014-02-03,32.11,32.48,30.06,30.38,1116200,30.38
22 | 2014-01-31,31.29,32.65,31.06,32.03,718800,32.03
23 | 2014-01-30,32.47,33.10,32.20,32.41,832200,32.41
24 | 2014-01-29,31.65,32.48,30.75,31.87,1015600,31.87
25 | 2014-01-28,31.37,31.89,30.76,31.37,794100,31.37
26 | 2014-01-27,29.61,31.60,29.29,31.20,1275600,31.20
27 | 2014-01-24,30.87,31.05,29.55,29.79,1060100,29.79
28 | 2014-01-23,31.58,31.92,30.53,31.06,1063600,31.06
29 | 2014-01-22,32.50,32.50,31.51,32.01,751000,32.01
30 | 2014-01-21,32.75,32.84,31.44,32.25,1229300,32.25
31 | 2014-01-17,32.70,33.48,31.37,31.90,1806300,31.90
32 | 2014-01-16,32.12,33.20,32.09,32.42,1823200,32.42
33 | 2014-01-15,32.51,33.00,30.72,32.03,1981900,32.03
34 | 2014-01-14,29.60,32.40,29.60,31.71,2543100,31.71
35 | 2014-01-13,30.01,30.38,28.77,28.99,1962000,28.99
36 | 2014-01-10,31.34,31.98,28.13,29.31,4259400,29.31
37 | 2014-01-09,32.63,33.28,31.76,32.17,1874800,32.17
38 | 2014-01-08,34.73,34.85,30.88,32.46,5697700,32.46
39 | 2014-01-07,34.56,36.49,34.10,35.61,2232000,35.61
40 | 2014-01-06,34.94,35.02,33.94,34.06,1983000,34.06
41 | 2014-01-03,33.11,34.45,33.09,34.21,1618900,34.21
42 | 2014-01-02,33.98,34.00,32.25,33.07,2018700,33.07
--------------------------------------------------------------------------------
/test/patternScan/CELG_20140501_20140813_Daily.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/patternScan/CELG_20140501_20140813_Daily.png
--------------------------------------------------------------------------------
/test/patternScan/CupWithoutHandle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | #include "TestHelper.h"
7 | #include "MultiPatternScanner.h"
8 | #include "PatternMatchFilter.h"
9 | #include "InvertedVScanner.h"
10 | #include "VScanner.h"
11 | #include "DoubleBottomScanner.h"
12 | #include "CupScanner.h"
13 | #include "CupWithoutHandleScanner.h"
14 |
15 | using namespace boost::posix_time;
16 | using namespace boost::gregorian;
17 | using namespace testHelper;
18 |
19 | BOOST_AUTO_TEST_CASE( CupWithoutHandle_GBX )
20 | {
21 |
22 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/GBX_Daily_2014.csv");
23 |
24 | PatternScannerPtr cupWithoutHandleScanner(new CupWithoutHandleScanner());
25 | MultiPatternScanner multiCupWithoutHandleScanner(cupWithoutHandleScanner);
26 | PatternMatchListPtr cupWithoutHandleMatches = multiCupWithoutHandleScanner.scanUniquePatternMatches(chartData);
27 |
28 | // This data includes a well-formed cup without handle, but also one which is more V-like and
29 | // should be disqualified using the CupScanners constraints on the ratio for the length of the
30 | // flat bottom versus the LHS downtrend.
31 |
32 | verifyMatchList("CupWithoutHandle_GBX",cupWithoutHandleMatches,1);
33 |
34 | verifyPatternMatch("CupWithoutHandle_GBX match",
35 | ptime(date(2014,4,2)),ptime(date(2014,4,22)),3,cupWithoutHandleMatches,0);
36 |
37 | BOOST_TEST_MESSAGE("CupWithoutHandle_GBX");
38 | }
39 |
40 | BOOST_AUTO_TEST_CASE( CupWithoutHandle_AMBA )
41 | {
42 |
43 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/AMBA_Daily_2014.csv");
44 |
45 | PatternScannerPtr cupWithoutHandleScanner(new CupWithoutHandleScanner());
46 | MultiPatternScanner multiCupWithoutHandleScanner(cupWithoutHandleScanner);
47 | PatternMatchListPtr cupWithoutHandleMatches = multiCupWithoutHandleScanner.scanUniquePatternMatches(chartData);
48 |
49 | // This data includes a mal-formed cup without handle, one which is V-like and
50 | // should be disqualified using the CupScanners constraints on the ratio for the length of the
51 | // flat bottom versus the LHS downtrend.
52 | //
53 | // In particular: Scanning was identifying the following as a valid cup without handle, when it shouldn't:
54 | // CupWithoutHandle_AMBA: pattern match: start = 2014-01-30, end = 2014-02-27,
55 | // num segments = 3, depth % = 27.5741, last close = 33.91
56 |
57 | verifyMatchList("CupWithoutHandle_AMBA",cupWithoutHandleMatches,0);
58 |
59 |
60 | BOOST_TEST_MESSAGE("CupWithoutHandle_AMBA");
61 | }
62 |
--------------------------------------------------------------------------------
/test/patternScan/GBX_Daily.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2013-11-06,31.66,31.90,30.42,31.04,950700,30.97
3 | 2013-11-05,30.95,31.61,30.32,31.42,717200,31.35
4 | 2013-11-04,29.93,31.41,29.93,31.15,634000,31.08
5 | 2013-11-01,27.80,30.00,27.37,29.77,1472500,29.70
6 | 2013-10-31,26.66,28.00,25.85,26.54,1065300,26.48
7 | 2013-10-30,25.90,25.96,24.79,24.98,236200,24.92
8 | 2013-10-29,26.30,26.51,25.81,25.91,162100,25.85
9 | 2013-10-28,26.79,26.96,26.00,26.28,218500,26.22
10 | 2013-10-25,26.72,26.81,26.20,26.74,167600,26.68
11 | 2013-10-24,25.60,26.73,25.38,26.61,302100,26.55
12 | 2013-10-23,25.72,25.83,25.35,25.62,172700,25.56
13 | 2013-10-22,25.37,25.99,25.30,25.83,341400,25.77
14 | 2013-10-21,25.26,25.55,24.99,25.12,249000,25.06
15 | 2013-10-18,25.70,25.73,25.12,25.29,299500,25.23
16 | 2013-10-17,25.65,25.95,25.59,25.70,188600,25.64
17 | 2013-10-16,25.97,26.22,25.76,25.84,207900,25.78
18 | 2013-10-15,26.17,26.30,25.62,25.80,130200,25.74
--------------------------------------------------------------------------------
/test/patternScan/PivotScanner.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "TestHelper.h"
3 | #include "SymetricTriangleScanner.h"
4 | #include "MultiPatternScanner.h"
5 | #include "PivotHighScanner.h"
6 | #include "PivotLowScanner.h"
7 | #include "CupScanner.h"
8 | #include "EndWithinPercentOfStart.h"
9 | #include "ORPatternMatchValidator.h"
10 | #include "PatternMatchValidator.h"
11 | #include "PivotHighScanner.h"
12 | #include "PivotLowScanner.h"
13 |
14 | using namespace boost::posix_time;
15 | using namespace boost::gregorian;
16 | using namespace testHelper;
17 |
18 |
19 | BOOST_AUTO_TEST_CASE( PivotScanner_VZ_SymetricTriangle )
20 | {
21 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/VZ_SymTriangle_Weekly_2013_2014.csv");
22 |
23 | double maxDistanceToTrendLine = 10.0;
24 | PatternMatchListPtr pivotHighs = PivotHighScanner(maxDistanceToTrendLine).scanPatternMatches(chartData);
25 | PatternMatchListPtr pivotLows = PivotLowScanner(maxDistanceToTrendLine).scanPatternMatches(chartData);
26 |
27 | genPivotHighInfo(pivotHighs);
28 | genPivotLowInfo(pivotLows);
29 |
30 | }
31 |
32 | BOOST_AUTO_TEST_CASE( PivotScanner_VZ_SymetricTriangle_lastPivotLow )
33 | {
34 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/VZ_Weekly_Nov2013_May2014.csv");
35 |
36 | double maxDistanceToTrendLine = 20.0;
37 | PatternMatchListPtr pivotLows = PivotLowScanner(maxDistanceToTrendLine).scanPatternMatches(chartData);
38 |
39 | genPivotLowInfo(pivotLows);
40 |
41 | /*
42 | CupScanner scanner;
43 | PatternMatchListPtr uShapedPivots = scanner.scanPatternMatches(chartData);
44 |
45 | genPivotLowInfo(uShapedPivots);
46 | */
47 |
48 | }
49 |
50 |
51 | BOOST_AUTO_TEST_CASE( PivotScanner_SynthesizedPivotLows )
52 | {
53 | // The synthesized period data below is the same as WedgeScannerEngine_SynthesizedPattern
54 | // test case, but isolates the pivot scanning.
55 |
56 | TestPerValRangeList ranges;
57 | ranges.push_back(TestPerValRange(4,92.0,100.0)); // up-trend to first pivot high at 100
58 | ranges.push_back(TestPerValRange(4,98.0,92.0)); // down-trend to first pivot low at 92
59 | ranges.push_back(TestPerValRange(4,92.5,98.0)); // up-trend to 2nd pivot high at 98 (lower than 1st)
60 | ranges.push_back(TestPerValRange(4,97.5,94.0)); // down-trend to 2nd pivot low at 94 (higher than 1st)
61 | ranges.push_back(TestPerValRange(4,94.5,104.0)); // up-trend after 2nd pivot low, including up-side break-out
62 | PeriodValSegmentPtr chartData = synthesizePeriodValSegment(date(2014,1,1),ranges);
63 |
64 | double maxDistanceToTrendLine = 10.0;
65 | PatternMatchListPtr pivotLows = PivotLowScanner(maxDistanceToTrendLine).scanPatternMatches(chartData);
66 | genPivotLowInfo(pivotLows);
67 | BOOST_CHECK_EQUAL(pivotLows->size(),2);
68 |
69 | PatternMatchListPtr pivotHighs = PivotHighScanner(maxDistanceToTrendLine).scanPatternMatches(chartData);
70 | genPivotHighInfo(pivotHighs);
71 | BOOST_CHECK_EQUAL(pivotHighs->size(),2);
72 |
73 | }
74 |
75 |
76 |
--------------------------------------------------------------------------------
/test/patternScan/QCOR_DoubleBottom_Weekly.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2014-02-18,70.37,76.46,69.73,75.83,3770100,75.54
3 | 2014-02-10,65.66,71.00,64.60,69.28,1646300,69.01
4 | 2014-02-03,67.11,67.74,61.25,65.01,1675200,64.76
5 | 2014-01-27,63.73,67.81,60.81,67.01,2078900,66.75
6 | 2014-01-21,59.43,65.40,58.87,63.73,2291600,63.49
7 | 2014-01-13,53.15,63.30,52.53,59.32,2833500,59.09
8 | 2014-01-06,52.80,53.71,47.71,52.95,2033000,52.46
9 | 2013-12-30,54.84,55.24,52.30,52.66,1012300,52.17
10 | 2013-12-23,53.62,55.82,53.33,54.70,958300,54.19
11 | 2013-12-16,53.47,55.20,52.03,53.26,2161800,52.77
12 | 2013-12-09,51.36,54.77,49.37,53.31,2326600,52.82
13 | 2013-12-02,58.26,59.66,52.56,52.63,2442500,52.14
14 | 2013-11-25,59.62,59.75,55.38,58.01,2226800,57.47
15 | 2013-11-18,61.28,62.30,56.80,59.12,1919200,58.57
16 | 2013-11-11,61.60,63.49,59.62,61.29,1362900,60.72
17 | 2013-11-04,60.03,62.92,57.61,61.60,1891000,61.03
18 | 2013-10-28,68.36,70.17,56.25,60.85,4161200,60.29
19 | 2013-10-21,64.31,69.40,58.25,68.40,2474000,67.77
20 | 2013-10-14,59.78,67.70,59.51,65.80,1732000,65.19
21 | 2013-10-07,58.50,61.09,53.33,60.20,1821600,59.37
22 | 2013-09-30,56.63,60.34,55.61,59.03,1713700,58.22
23 | 2013-09-23,55.81,58.34,54.00,56.90,1883400,56.12
24 | 2013-09-16,63.10,66.45,54.36,55.33,2646100,54.57
25 | 2013-09-09,67.15,68.94,60.31,63.07,1215300,62.20
26 | 2013-09-03,67.42,68.90,66.08,66.79,1132300,65.87
27 | 2013-08-26,72.41,74.76,66.01,66.68,1469600,65.76
--------------------------------------------------------------------------------
/test/patternScan/QCOR_DoubleBottom_Weekly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/patternScan/QCOR_DoubleBottom_Weekly.png
--------------------------------------------------------------------------------
/test/patternScan/SAVE_Cup_Weekly_20130722_20131028.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2013-10-28,41.98,42.75,41.91,42.36,588200,42.36
3 | 2013-10-21,43.29,45.18,41.84,41.91,888000,41.91
4 | 2013-10-14,39.11,44.24,38.68,43.05,1113900,43.05
5 | 2013-10-07,34.59,39.88,32.50,39.11,1083000,39.11
6 | 2013-09-30,34.01,35.54,33.58,34.80,745700,34.80
7 | 2013-09-23,34.94,34.97,33.13,34.40,621600,34.40
8 | 2013-09-16,33.84,35.16,33.30,34.90,729600,34.90
9 | 2013-09-09,31.39,33.56,31.39,33.14,1167600,33.14
10 | 2013-09-03,31.57,32.28,30.92,31.19,480500,31.19
11 | 2013-08-26,31.57,31.81,29.65,31.17,607100,31.17
12 | 2013-08-19,31.18,31.65,30.25,31.59,609800,31.59
13 | 2013-08-12,34.30,35.22,30.42,31.23,976000,31.23
14 | 2013-08-05,34.17,35.00,33.46,34.35,734700,34.35
15 | 2013-07-29,35.62,35.75,31.91,34.10,1581800,34.10
16 | 2013-07-22,34.75,36.83,34.52,35.57,724200,35.57
17 |
--------------------------------------------------------------------------------
/test/patternScan/SAVE_Cup_Weekly_20130722_20131028.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/patternScan/SAVE_Cup_Weekly_20130722_20131028.png
--------------------------------------------------------------------------------
/test/patternScan/SAVE_Weekly_2013.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2013-12-30,44.72,46.12,44.25,45.41,514000,45.41
3 | 2013-12-23,47.20,47.62,44.44,44.88,549600,44.88
4 | 2013-12-16,43.14,46.78,42.50,46.06,832400,46.06
5 | 2013-12-09,44.37,45.10,42.25,43.04,652300,43.04
6 | 2013-12-02,45.87,46.05,43.12,44.17,534100,44.17
7 | 2013-11-25,44.95,46.92,44.70,45.87,599600,45.87
8 | 2013-11-18,44.78,44.95,43.09,44.62,683600,44.62
9 | 2013-11-11,43.50,45.25,42.55,44.53,745100,44.53
10 | 2013-11-04,42.89,45.30,41.41,43.30,862700,43.30
11 | 2013-10-28,41.98,46.40,39.36,42.89,1395200,42.89
12 | 2013-10-21,43.29,45.18,41.84,41.91,888000,41.91
13 | 2013-10-14,39.11,44.24,38.68,43.05,1113900,43.05
14 | 2013-10-07,34.59,39.88,32.50,39.11,1083000,39.11
15 | 2013-09-30,34.01,35.54,33.58,34.80,745700,34.80
16 | 2013-09-23,34.94,34.97,33.13,34.40,621600,34.40
17 | 2013-09-16,33.84,35.16,33.30,34.90,729600,34.90
18 | 2013-09-09,31.39,33.56,31.39,33.14,1167600,33.14
19 | 2013-09-03,31.57,32.28,30.92,31.19,480500,31.19
20 | 2013-08-26,31.57,31.81,29.65,31.17,607100,31.17
21 | 2013-08-19,31.18,31.65,30.25,31.59,609800,31.59
22 | 2013-08-12,34.30,35.22,30.42,31.23,976000,31.23
23 | 2013-08-05,34.17,35.00,33.46,34.35,734700,34.35
24 | 2013-07-29,35.62,35.75,31.91,34.10,1581800,34.10
25 | 2013-07-22,34.75,36.83,34.52,35.57,724200,35.57
26 | 2013-07-15,33.69,34.76,33.39,34.71,481100,34.71
27 | 2013-07-08,32.51,34.22,31.73,33.45,451400,33.45
28 | 2013-07-01,31.80,33.12,31.42,32.35,393700,32.35
29 | 2013-06-24,32.09,33.00,29.20,31.72,1599700,31.72
30 | 2013-06-17,32.45,33.75,32.13,32.60,480000,32.60
31 | 2013-06-10,31.39,32.66,31.15,32.12,434000,32.12
32 | 2013-06-03,30.01,31.15,29.29,31.07,815800,31.07
33 | 2013-05-28,30.00,31.66,29.73,30.43,533500,30.43
34 | 2013-05-20,28.50,29.95,28.50,29.78,611100,29.78
35 | 2013-05-13,29.21,29.41,28.01,28.50,514400,28.50
36 | 2013-05-06,27.64,29.93,27.64,29.18,510100,29.18
37 | 2013-04-29,25.87,28.32,25.33,27.72,1106600,27.72
38 | 2013-04-22,26.57,26.58,25.77,25.85,418000,25.85
39 | 2013-04-15,26.23,26.84,25.30,26.57,596900,26.57
40 | 2013-04-08,25.38,26.32,24.99,26.23,468900,26.23
41 | 2013-04-01,25.13,25.52,24.30,25.30,855700,25.30
42 | 2013-03-25,26.59,26.74,25.03,25.36,717400,25.36
43 | 2013-03-18,24.50,26.87,24.30,26.34,838000,26.34
44 | 2013-03-11,23.52,25.64,23.04,24.73,974200,24.73
45 | 2013-03-04,20.36,24.04,20.36,23.80,694800,23.80
46 | 2013-02-25,21.11,21.33,20.01,20.70,422600,20.70
47 | 2013-02-19,19.50,21.08,19.50,21.01,649800,21.01
48 | 2013-02-11,19.55,19.88,19.04,19.38,305300,19.38
49 | 2013-02-04,19.07,19.61,18.51,19.51,323900,19.51
50 | 2013-01-28,19.71,19.77,19.05,19.21,262900,19.21
51 | 2013-01-22,19.25,19.96,19.12,19.75,406400,19.75
52 | 2013-01-14,18.52,19.30,18.42,19.25,592000,19.25
53 | 2013-01-07,18.08,18.66,18.00,18.27,306400,18.27
54 | 2013-01-02,18.00,18.17,17.40,18.10,625900,18.10
55 |
--------------------------------------------------------------------------------
/test/patternScan/SAVE_Weekly_2013.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/patternScan/SAVE_Weekly_2013.png
--------------------------------------------------------------------------------
/test/patternScan/VScanner.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | #include "PeriodVal.h"
7 | #include "PatternScannerEngine.h"
8 | #include "SegmentConstraint.h"
9 | #include "SegmentValsCloseToLinearEq.h"
10 | #include "SegmentListConstraint.h"
11 | #include "SlopeIncreasesConstraint.h"
12 | #include "PatternMatchValidator.h"
13 | #include "EndWithinPercentOfStart.h"
14 | #include "PeriodValSegment.h"
15 | #include "VScanner.h"
16 | #include "TestHelper.h"
17 | #include "RecoverPercentOfDepth.h"
18 | #include "BreakoutAboveFirstHighValidatorFactory.h"
19 |
20 | using namespace boost::posix_time;
21 | using namespace boost::gregorian;
22 | using namespace testHelper;
23 |
24 | BOOST_AUTO_TEST_CASE( VScanner_QCOR_20130819_LHSofDoubleBottom )
25 | {
26 | PeriodValSegmentPtr allPerSegment = PeriodValSegment::readFromFile("./patternScan/QCOR_DoubleBottom_Weekly.csv");
27 |
28 | PeriodValSegmentPair splitSeg = allPerSegment->split(11);
29 | PeriodValSegmentPtr vData = splitSeg.first;
30 | genPeriodValSegmentInfo("V segment data",*vData);
31 |
32 | VScanner scanner;
33 | scanner.upTrendValidatorFactory().addFactory(
34 | PatternMatchValidatorFactoryPtr(new RecoverPercentOfDepth(60.0)));
35 |
36 | PatternMatchListPtr patternMatches = scanner.scanPatternMatches(vData);
37 |
38 | verifyMatchList("VScanner_QCOR_20130819_LHSofDoubleBottom",patternMatches,1);
39 |
40 | PatternMatchPtr thePatternMatch = patternMatches->front();
41 |
42 | verifyPatternMatch("V Match on LHS",
43 | ptime(date(2013,8,26)),ptime(date(2013,10,21)),2,thePatternMatch);
44 |
45 | }
46 |
47 |
48 | BOOST_AUTO_TEST_CASE( VScanner_QCOR_20130819_RHSofDoubleBottom )
49 | {
50 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/QCOR_DoubleBottom_Weekly.csv");
51 |
52 | BOOST_TEST_MESSAGE("Testing V sub-patterns for RHS of double bottom of QCOR");
53 | PeriodValSegmentPair splitQCORdata = chartData->split(8);
54 | PeriodValSegmentPtr rhsSegData = splitQCORdata.second;
55 |
56 | genPeriodValSegmentInfo("V RHS segment data",*rhsSegData);
57 |
58 | VScanner scanner;
59 | scanner.upTrendValidatorFactory().addFactory(
60 | PatternMatchValidatorFactoryPtr(new RecoverPercentOfDepth(50.0)));
61 | scanner.upTrendValidatorFactory().addFactory(PatternMatchValidatorFactoryPtr(new BreakoutAboveFirstHighValidatorFactory()));
62 |
63 | PatternMatchListPtr patternMatches = scanner.scanPatternMatches(rhsSegData);
64 |
65 | verifyMatchList("VScanner_QCOR_20130819_RHSofDoubleBottom",patternMatches,1);
66 |
67 | PatternMatchPtr thePatternMatch = patternMatches->front();
68 |
69 | verifyPatternMatch("V Match on RHS",
70 | ptime(date(2013,10,21)),ptime(date(2014,2,10)),2,thePatternMatch);
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/test/patternScan/VZ_SymTriangle_2013_2014_Weekly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/patternScan/VZ_SymTriangle_2013_2014_Weekly.png
--------------------------------------------------------------------------------
/test/patternScan/VZ_Weekly_Nov2013_May2014.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2014-05-27,49.97,50.01,49.43,49.96,11633600,49.43
3 | 2014-05-19,49.13,49.74,48.62,49.74,14567600,49.21
4 | 2014-05-12,48.59,49.30,47.64,49.07,17594000,48.55
5 | 2014-05-05,47.14,48.68,47.03,48.48,16425500,47.96
6 | 2014-04-28,46.22,47.41,46.15,47.12,19014400,46.62
7 | 2014-04-21,47.77,48.37,45.85,45.94,27678100,45.45
8 | 2014-04-14,47.26,47.70,46.70,47.60,20512500,47.09
9 | 2014-04-07,47.70,48.46,47.02,47.07,31304800,46.57
10 | 2014-03-31,47.66,48.35,47.20,48.04,21141100,47.00
11 | 2014-03-24,46.81,47.93,46.38,47.42,28228900,46.40
12 | 2014-03-17,46.22,47.41,46.10,46.91,31632600,45.90
13 | 2014-03-10,46.79,47.06,45.83,46.08,36718200,45.09
14 | 2014-03-03,47.30,48.39,46.82,47.15,44893000,46.13
15 | 2014-02-24,47.02,47.78,45.89,47.58,213369600,46.55
16 | 2014-02-18,46.47,48.34,45.45,47.27,44697900,46.25
17 | 2014-02-10,46.81,47.46,46.18,46.51,19434700,45.51
18 | 2014-02-03,48.02,48.02,46.11,46.81,21898500,45.80
19 | 2014-01-27,47.71,48.50,46.69,48.02,19141600,46.99
20 | 2014-01-21,48.84,48.90,46.76,47.63,24861200,46.60
21 | 2014-01-13,47.65,48.69,46.58,48.35,17991700,47.31
22 | 2014-01-06,48.77,49.40,47.43,47.75,14554600,46.72
23 | 2013-12-30,49.05,49.33,48.22,48.42,8577300,46.87
24 | 2013-12-23,48.38,49.35,48.37,49.17,6815500,47.59
25 | 2013-12-16,48.34,49.41,47.45,48.08,14655700,46.54
26 | 2013-12-09,49.07,49.63,47.52,47.84,13087300,46.31
27 | 2013-12-02,49.66,49.79,48.43,49.48,11521300,47.89
28 | 2013-11-25,50.29,50.36,49.54,49.62,6702000,48.03
--------------------------------------------------------------------------------
/test/patternScan/WedgeScanners.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "TestHelper.h"
3 | #include "MultiPatternScanner.h"
4 | #include "FallingWedgeScanner.h"
5 | #include "RisingWedgeScanner.h"
6 | #include "RectangleScanner.h"
7 |
8 | using namespace boost::posix_time;
9 | using namespace boost::gregorian;
10 | using namespace testHelper;
11 |
12 | BOOST_AUTO_TEST_CASE( WedgeScanners_GMCR_Falling_Wedge )
13 | {
14 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/GMCR_Daily_2014.csv");
15 |
16 | FallingWedgeScanner fallingWedgeScanner;
17 | PatternMatchListPtr fallingWedges = fallingWedgeScanner.scanPatternMatches(chartData);
18 |
19 | verifyMatchList("WedgeScanners_GMCR_Falling_Wedge: falling wedges",fallingWedges,2);
20 |
21 | }
22 |
23 |
24 | BOOST_AUTO_TEST_CASE( WedgeScanners_CMG_Falling_Wedge )
25 | {
26 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/CMG_Daily.csv");
27 |
28 | FallingWedgeScanner fallingWedgeScanner;
29 | PatternMatchListPtr fallingWedges = fallingWedgeScanner.scanPatternMatches(chartData);
30 |
31 | verifyMatchList("WedgeScanners_CMG_Falling_Wedge: falling wedges",fallingWedges,1);
32 |
33 | }
34 |
35 | BOOST_AUTO_TEST_CASE( WedgeScanners_VZ_IncompleteRectanglePattern)
36 | {
37 | PeriodValSegmentPtr chartData = PeriodValSegment::readFromFile("./patternScan/VZ_SymTriangle_Weekly_2013_2014.csv");
38 |
39 | RectangleScanner rectangleScanner;
40 | PatternMatchListPtr rectangles = rectangleScanner.scanPatternMatches(chartData);
41 |
42 | verifyMatchList("WedgeScanners_VZ_IncompletePattern: rectangles",rectangles,1);
43 |
44 | verifyPatternMatch("WedgeScanners_VZ_IncompletePattern match",
45 | ptime(date(2013,7,29)),ptime(date(2014,5,27)),1,rectangles,0);
46 |
47 | BOOST_CHECK_EQUAL(rectangles->front()->isConfirmedMatch(),false);
48 |
49 |
50 | }
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/test/quoteData/CorruptDate.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | BADDATE,70.37,76.46,69.73,75.83,3770100,75.54
3 | 2014-02-10,65.66,71.00,64.60,69.28,1646300,69.01
4 |
--------------------------------------------------------------------------------
/test/quoteData/CorruptVal.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2014-02-18,70.37,76.46,69.73,75.83,3770100,75.54
3 | 2014-02-10,65.66,71.00,64.60,69.28,1646300,69.01
4 | 2014-02-03,67.11,BADVAL,61.25,65.01,1675200,64.76
5 | 2014-01-27,63.73,67.81,60.81,67.01,2078900,66.75
6 | 2014-01-21,59.43,65.40,58.87,63.73,2291600,63.49
7 |
--------------------------------------------------------------------------------
/test/quoteData/GoogleFormatAAPL-Short.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume
2 | 10-Nov-14,109.02,109.33,108.67,108.83,27195547
3 | 7-Nov-14,108.75,109.32,108.55,109.01,33691535
--------------------------------------------------------------------------------
/test/quoteData/MalformedHeader.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,BadCloseHeader,Volume,Adj Close
2 | 2014-10-30,106.96,107.35,105.90,106.98,40589700,106.98
3 | 2014-10-29,106.65,107.37,106.36,107.34,52586100,107.34
4 | 2014-10-28,105.40,106.74,105.35,106.74,47939900,106.74
5 |
--------------------------------------------------------------------------------
/test/quoteData/MalformedHeaderNoCloseField.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Volume,Adj Close
2 | 2014-10-30,106.96,107.35,105.90,106.98,40589700,106.98
3 | 2014-10-29,106.65,107.37,106.36,107.34,52586100,107.34
4 | 2014-10-28,105.40,106.74,105.35,106.74,47939900,106.74
5 |
--------------------------------------------------------------------------------
/test/quoteData/MissingField.csv:
--------------------------------------------------------------------------------
1 | Date,Open,High,Low,Close,Volume,Adj Close
2 | 2014-02-18,70.37,76.46,69.73,75.83,3770100,75.54
3 | 2014-02-10,65.66,71.00,64.60,69.28,1646300
4 |
--------------------------------------------------------------------------------
/test/quoteData/MissingHeader.csv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sroehling/ChartPatternRecognitionLib/d9bd25c0fc5a8942bb98c74c42ab52db80f680c1/test/quoteData/MissingHeader.csv
--------------------------------------------------------------------------------