├── CNAME
├── _config.yml
├── ta4j-core
├── src
│ ├── test
│ │ ├── resources
│ │ │ ├── org
│ │ │ │ └── ta4j
│ │ │ │ │ └── core
│ │ │ │ │ ├── criteria
│ │ │ │ │ └── LTC.xls
│ │ │ │ │ └── indicators
│ │ │ │ │ ├── ATR.xls
│ │ │ │ │ ├── EMA.xls
│ │ │ │ │ ├── MMA.xls
│ │ │ │ │ ├── RSI.xls
│ │ │ │ │ ├── SMA.xls
│ │ │ │ │ ├── RWIHL.xls
│ │ │ │ │ ├── adx
│ │ │ │ │ └── ADX.xls
│ │ │ │ │ ├── ichi_test.ods
│ │ │ │ │ └── AAPL_StochRSI.xls
│ │ │ └── logback-test.xml
│ │ └── java
│ │ │ └── org
│ │ │ └── ta4j
│ │ │ └── core
│ │ │ ├── CriterionFactory.java
│ │ │ ├── IndicatorFactory.java
│ │ │ ├── num
│ │ │ └── DoubleNumTest.java
│ │ │ ├── rules
│ │ │ ├── NotRuleTest.java
│ │ │ ├── BooleanIndicatorRuleTest.java
│ │ │ ├── IsEqualRuleTest.java
│ │ │ ├── BooleanRuleTest.java
│ │ │ ├── FixedRuleTest.java
│ │ │ ├── OrRuleTest.java
│ │ │ ├── AndRuleTest.java
│ │ │ └── XorRuleTest.java
│ │ │ ├── ExternalIndicatorTest.java
│ │ │ ├── indicators
│ │ │ ├── helpers
│ │ │ │ ├── ConstantIndicatorTest.java
│ │ │ │ ├── AmountIndicatorTest.java
│ │ │ │ ├── ClosePriceIndicatorTest.java
│ │ │ │ ├── TradeCountIndicatorTest.java
│ │ │ │ ├── LowPriceIndicatorTest.java
│ │ │ │ ├── OpenPriceIndicatorTest.java
│ │ │ │ ├── NumndicatorTest.java
│ │ │ │ └── HighPriceIndicatorTest.java
│ │ │ ├── RWILowIndicatorTest.java
│ │ │ └── RWIHighIndicatorTest.java
│ │ │ ├── mocks
│ │ │ └── MockTradingRecord.java
│ │ │ └── ExternalCriterionTest.java
│ └── main
│ │ └── java
│ │ └── org
│ │ └── ta4j
│ │ └── core
│ │ ├── package-info.java
│ │ ├── indicators
│ │ ├── candles
│ │ │ └── package-info.java
│ │ ├── helpers
│ │ │ ├── package-info.java
│ │ │ ├── FixedBooleanIndicator.java
│ │ │ ├── TradeCountIndicator.java
│ │ │ ├── AmountIndicator.java
│ │ │ ├── LowPriceIndicator.java
│ │ │ ├── OpenPriceIndicator.java
│ │ │ ├── ClosePriceIndicator.java
│ │ │ ├── HighPriceIndicator.java
│ │ │ ├── ConstantIndicator.java
│ │ │ ├── MedianPriceIndicator.java
│ │ │ ├── FixedDecimalIndicator.java
│ │ │ └── SumIndicator.java
│ │ ├── volume
│ │ │ ├── package-info.java
│ │ │ └── MVWAPIndicator.java
│ │ ├── adx
│ │ │ └── package-info.java
│ │ ├── bollinger
│ │ │ └── package-info.java
│ │ ├── keltner
│ │ │ └── package-info.java
│ │ ├── statistics
│ │ │ ├── package-info.java
│ │ │ └── StandardErrorIndicator.java
│ │ ├── pivotpoints
│ │ │ ├── TimeLevel.java
│ │ │ ├── package-info.java
│ │ │ └── PivotLevel.java
│ │ ├── ichimoku
│ │ │ ├── package-info.java
│ │ │ ├── IchimokuKijunSenIndicator.java
│ │ │ └── IchimokuTenkanSenIndicator.java
│ │ ├── package-info.java
│ │ ├── EMAIndicator.java
│ │ ├── MMAIndicator.java
│ │ └── AbstractIndicator.java
│ │ ├── reports
│ │ ├── package-info.java
│ │ ├── ReportGenerator.java
│ │ └── PositionStatsReportGenerator.java
│ │ ├── aggregator
│ │ ├── package-info.java
│ │ ├── BarAggregator.java
│ │ ├── BarSeriesAggregator.java
│ │ └── BaseBarSeriesAggregator.java
│ │ ├── BarSeriesBuilder.java
│ │ ├── analysis
│ │ ├── package-info.java
│ │ └── cost
│ │ │ └── ZeroCostModel.java
│ │ ├── criteria
│ │ ├── package-info.java
│ │ ├── AbstractAnalysisCriterion.java
│ │ ├── NumberOfLosingPositionsCriterion.java
│ │ └── NumberOfWinningPositionsCriterion.java
│ │ ├── rules
│ │ ├── package-info.java
│ │ ├── BooleanIndicatorRule.java
│ │ ├── AbstractRule.java
│ │ ├── BooleanRule.java
│ │ ├── FixedRule.java
│ │ └── NotRule.java
│ │ ├── num
│ │ └── package-info.java
│ │ └── backtest
│ │ ├── TradeExecutionModel.java
│ │ ├── TradeOnCurrentCloseModel.java
│ │ └── TradeOnNextOpenModel.java
└── pom.xml
├── .github
├── PULL_REQUEST_TEMPLATE.md
├── ISSUE_TEMPLATE
│ ├── general-question.md
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── check.yml
│ ├── validate.yml
│ ├── test.yml
│ └── deploy_snapshot.yml
├── ta4j-examples
├── src
│ ├── test
│ │ ├── resources
│ │ │ └── logback-test.xml
│ │ └── java
│ │ │ └── ta4jexamples
│ │ │ ├── QuickstartTest.java
│ │ │ ├── analysis
│ │ │ ├── TradeCostTest.java
│ │ │ ├── CashFlowToChartTest.java
│ │ │ ├── StrategyAnalysisTest.java
│ │ │ └── BuyAndSellSignalsToChartTest.java
│ │ │ ├── num
│ │ │ └── CompareNumTypesTest.java
│ │ │ ├── loaders
│ │ │ ├── CsvBarsLoaderTest.java
│ │ │ └── CsvTradesLoaderTest.java
│ │ │ ├── strategies
│ │ │ ├── RSI2StrategyTest.java
│ │ │ ├── CCICorrectionStrategyTest.java
│ │ │ ├── GlobalExtremaStrategyTest.java
│ │ │ └── MovingMomentumStrategyTest.java
│ │ │ ├── walkforward
│ │ │ └── WalkForwardTest.java
│ │ │ ├── barSeries
│ │ │ └── BuildBarSeriesTest.java
│ │ │ ├── indicators
│ │ │ ├── IndicatorsToCsvTest.java
│ │ │ ├── CandlestickChartTest.java
│ │ │ └── IndicatorsToChartTest.java
│ │ │ ├── logging
│ │ │ └── StrategyExecutionLoggingTest.java
│ │ │ ├── bots
│ │ │ └── TradingBotOnMovingBarSeriesTest.java
│ │ │ └── backtesting
│ │ │ ├── SimpleMovingAverageBacktestTest.java
│ │ │ └── SimpleMovingAverageRangeBacktestTest.java
│ └── main
│ │ ├── resources
│ │ └── logback-traces.xml
│ │ └── java
│ │ └── ta4jexamples
│ │ └── loaders
│ │ └── jsonhelper
│ │ └── GsonBarSeries.java
└── pom.xml
├── AUTHORS
├── .gitignore
└── LICENSE
/CNAME:
--------------------------------------------------------------------------------
1 | ta4j.org
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-minimal
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/criteria/LTC.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/criteria/LTC.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/ATR.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/ATR.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/EMA.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/EMA.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/MMA.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/MMA.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/RSI.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/RSI.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/SMA.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/SMA.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/RWIHL.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/RWIHL.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/adx/ADX.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/adx/ADX.xls
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/ichi_test.ods:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/ichi_test.ods
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/org/ta4j/core/indicators/AAPL_StochRSI.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Petersoj/ta4j/master/ta4j-core/src/test/resources/org/ta4j/core/indicators/AAPL_StochRSI.xls
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 | Fixes #.
3 |
4 | Changes proposed in this pull request:
5 | -
6 | -
7 | -
8 |
9 | - [ ] added an entry with related ticket number(s) to the unreleased section of `CHANGES.md`
10 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ta4j-examples/src/main/resources/logback-traces.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | Maintainer / Lead developer
2 |
3 | team172011 (Simon-Justus Wimmer)
4 |
5 | Contributors
6 |
7 | mdeverdelhan (Marc de Verdelhan)
8 | Bastien Bonard
9 | dkcm (Daniel Kuan)
10 | dan-lind (Daniel Lindberg)
11 | lequer (Michel Le Quer)
12 | ElMoe (Bastian Engelmann)
13 | gcauchis (Gabriel Cauchis)
14 | bukefalos
15 | TheCookieLab
16 | team172011 (Simon-Justus Wimmer)
17 | nimo23
18 | edlins
19 | milczarekIT (Bartosz Milczarek)
20 | kennethjor (Kenneth Jørgensen)
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/general-question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: General question
3 | about: A general question about how to use ta4j
4 | title: ''
5 | labels: question
6 | assignees: ''
7 |
8 | ---
9 |
10 | **I have checked existing issues and wiki**
11 | - [ ] I could not find similar [issues](https://github.com/ta4j/ta4j/issues?utf8=%E2%9C%93&q=)
12 | - [ ] I could not find a solution in the [wiki](https://ta4j.github.io/ta4j-wiki/) or [faq section](https://ta4j.github.io/ta4j-wiki/FAQ.html)
13 |
14 | If possible provide a **[minimal working example](https://stackoverflow.com/help/mcve)**!
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings/
4 | .idea/
5 | .vscode/
6 | .svn/
7 | nb-configuration.xml
8 | nbactions.xml
9 | *.iml
10 | .DS_Store
11 | log/
12 | bin/
13 | target/
14 | out/
15 |
16 | # Compiled class file
17 | *.class
18 |
19 | # Log file
20 | *.log
21 |
22 | # BlueJ files
23 | *.ctxt
24 |
25 | # Package Files #
26 | *.jar
27 | *.war
28 | *.nar
29 | *.ear
30 | *.zip
31 | *.tar.gz
32 | *.rar
33 |
34 | # temp files #
35 | ta4j-examples/indicators.csv
36 |
37 | # Mobile Tools for Java (J2ME)
38 | .mtj.tmp/
39 |
40 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
41 | hs_err_pid*
42 | /html/
43 |
--------------------------------------------------------------------------------
/.github/workflows/check.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Check license header
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 |
15 | steps:
16 | - uses: actions/checkout@v2
17 | - name: Set up JDK 11
18 | uses: actions/setup-java@v2
19 | with:
20 | distribution: 'zulu'
21 | java-version: '11'
22 | - name: Build with Maven
23 | run: xvfb-run mvn -B license:check
24 |
--------------------------------------------------------------------------------
/.github/workflows/validate.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Validate source code
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 |
15 | steps:
16 | - uses: actions/checkout@v2
17 | - name: Set up JDK 11
18 | uses: actions/setup-java@v2
19 | with:
20 | distribution: 'zulu'
21 | java-version: '11'
22 | - name: Build with Maven
23 | run: xvfb-run mvn -B formatter:validate
24 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Test
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - master
10 | push:
11 | branches:
12 | - master
13 |
14 | jobs:
15 | build:
16 | runs-on: ubuntu-latest
17 |
18 | steps:
19 | - name: Checkout repository
20 | uses: actions/checkout@v2
21 | - name: Set up JDK 11
22 | uses: actions/setup-java@v2
23 | with:
24 | distribution: 'zulu'
25 | java-version: '11'
26 | - name: Build with Maven
27 | run: xvfb-run mvn -B test
28 |
--------------------------------------------------------------------------------
/.github/workflows/deploy_snapshot.yml:
--------------------------------------------------------------------------------
1 | name: Deploy Snapshot
2 |
3 | on:
4 | push:
5 | branches:
6 | - 'master'
7 |
8 | jobs:
9 | deploy:
10 | name: Deploy Snapshot
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - name: Checkout
15 | uses: actions/checkout@v3
16 | with:
17 | ref: 'master'
18 | fetch-depth: 0
19 |
20 | - name: Setup Java
21 | uses: actions/setup-java@v3
22 | with:
23 | java-version: 11
24 | distribution: 'zulu'
25 | server-id: sonatype-nexus-snapshots
26 | server-username: MAVEN_USERNAME
27 | server-password: MAVEN_CENTRAL_TOKEN
28 |
29 | - name: Deploy to Maven Central
30 | env:
31 | MAVEN_USERNAME: ${{ secrets.MAVEN_USER }}
32 | MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_PASSWORD }}
33 | run: xvfb-run mvn -B deploy
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: "[BUG]"
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **I have checked existing issues and wiki**
11 | - [ ] I could not find similar [issues](https://github.com/ta4j/ta4j/issues?utf8=%E2%9C%93&q=)
12 | - [ ] I could not find a solution in the [wiki](https://ta4j.github.io/ta4j-wiki/) or [faq section](https://ta4j.github.io/ta4j-wiki/FAQ.html)
13 |
14 | **Describe the bug**
15 | A clear and concise description of what the bug is. If possible provide a **[minimal working example](https://stackoverflow.com/help/mcve)**!
16 |
17 | **To Reproduce**
18 | Steps to reproduce the behavior:
19 | 1. Go to '...'
20 | 2. Click on '....'
21 | 3. Scroll down to '....'
22 | 4. See error
23 |
24 | **Expected behavior**
25 | A clear and concise description of what you expected to happen.
26 |
27 | **Screenshots**
28 | If applicable, add screenshots to help explain your problem.
29 |
30 | **Additional context**
31 | Add any other context about the problem here.
32 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **I have checked existing issues and wiki**
11 | - [ ] I could not find similar [issues](https://github.com/ta4j/ta4j/issues?utf8=%E2%9C%93&q=)
12 | - [ ] I could not find a solution in the [wiki](https://ta4j.github.io/ta4j-wiki/) or [faq section](https://ta4j.github.io/ta4j-wiki/FAQ.html)
13 |
14 | **Is your feature request related to a problem? Please describe.**
15 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
16 |
17 | **Describe the solution you'd like**
18 | A clear and concise description of what you want to happen. If possible provide a **[minimal working example](https://stackoverflow.com/help/mcve)**!
19 |
20 | **Describe alternatives you've considered**
21 | A clear and concise description of any alternative solutions or features you've considered.
22 |
23 | **Additional context**
24 | Add any other context or screenshots about the feature request here.
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017-2023 Ta4j Organization & respective
4 | authors (see AUTHORS)
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of
7 | this software and associated documentation files (the "Software"), to deal in
8 | the Software without restriction, including without limitation the rights to
9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 | the Software, and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * The core module of the ta4j library.
26 | */
27 | package org.ta4j.core;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/candles/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators analyzing candle sticks and patterns.
26 | */
27 | package org.ta4j.core.indicators.candles;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators that can be helpful (for other indicators).
26 | */
27 | package org.ta4j.core.indicators.helpers;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/volume/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of volume based analysis.
26 | */
27 | package org.ta4j.core.indicators.volume;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/adx/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of the 'Directional Movement System'
26 | */
27 | package org.ta4j.core.indicators.adx;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/bollinger/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of the 'Bollinger Bands'
26 | */
27 | package org.ta4j.core.indicators.bollinger;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/keltner/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of the 'Keltner Channel'.
26 | */
27 | package org.ta4j.core.indicators.keltner;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/statistics/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of statistical analysis.
26 | */
27 | package org.ta4j.core.indicators.statistics;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/pivotpoints/TimeLevel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.pivotpoints;
25 |
26 | public enum TimeLevel {
27 | BARBASED, DAY, WEEK, MONTH, YEAR;
28 | }
29 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/pivotpoints/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of different 'Pivot Points'.
26 | */
27 | package org.ta4j.core.indicators.pivotpoints;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/ichimoku/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Indicators for the realization of the 'Ichimoku cloud trading strategy'.
26 | */
27 | package org.ta4j.core.indicators.ichimoku;
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/pivotpoints/PivotLevel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.pivotpoints;
25 |
26 | public enum PivotLevel {
27 | RESISTANCE_3, RESISTANCE_2, RESISTANCE_1, SUPPORT_1, SUPPORT_2, SUPPORT_3;
28 | }
29 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/QuickstartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples;
25 |
26 | import org.junit.Test;
27 |
28 | public class QuickstartTest {
29 |
30 | @Test
31 | public void test() {
32 | Quickstart.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/analysis/TradeCostTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.analysis;
25 |
26 | import org.junit.Test;
27 |
28 | public class TradeCostTest {
29 |
30 | @Test
31 | public void test() {
32 | TradeCost.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/num/CompareNumTypesTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.num;
25 |
26 | import org.junit.Test;
27 |
28 | public class CompareNumTypesTest {
29 |
30 | @Test
31 | public void test() {
32 | CompareNumTypes.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/loaders/CsvBarsLoaderTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.loaders;
25 |
26 | import org.junit.Test;
27 |
28 | public class CsvBarsLoaderTest {
29 |
30 | @Test
31 | public void test() {
32 | CsvBarsLoader.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/strategies/RSI2StrategyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.strategies;
25 |
26 | import org.junit.Test;
27 |
28 | public class RSI2StrategyTest {
29 |
30 | @Test
31 | public void test() {
32 | RSI2Strategy.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/walkforward/WalkForwardTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.walkforward;
25 |
26 | import org.junit.Test;
27 |
28 | public class WalkForwardTest {
29 |
30 | @Test
31 | public void test() {
32 | WalkForward.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/reports/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * This package can be used to generate
26 | * {@link org.ta4j.core.reports.PerformanceReport performance} and
27 | * {@link org.ta4j.core.reports.TradingStatement trading} reports.
28 | */
29 | package org.ta4j.core.reports;
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/analysis/CashFlowToChartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.analysis;
25 |
26 | import org.junit.Test;
27 |
28 | public class CashFlowToChartTest {
29 |
30 | @Test
31 | public void test() {
32 | CashFlowToChart.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/barSeries/BuildBarSeriesTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.barSeries;
25 |
26 | import org.junit.Test;
27 |
28 | public class BuildBarSeriesTest {
29 |
30 | @Test
31 | public void test() {
32 | BuildBarSeries.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/loaders/CsvTradesLoaderTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.loaders;
25 |
26 | import org.junit.Test;
27 |
28 | public class CsvTradesLoaderTest {
29 |
30 | @Test
31 | public void test() {
32 | CsvTradesLoader.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/analysis/StrategyAnalysisTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.analysis;
25 |
26 | import org.junit.Test;
27 |
28 | public class StrategyAnalysisTest {
29 |
30 | @Test
31 | public void test() {
32 | StrategyAnalysis.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/indicators/IndicatorsToCsvTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.indicators;
25 |
26 | import org.junit.Test;
27 |
28 | public class IndicatorsToCsvTest {
29 |
30 | @Test
31 | public void test() {
32 | IndicatorsToCsv.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/indicators/CandlestickChartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.indicators;
25 |
26 | import org.junit.Test;
27 |
28 | public class CandlestickChartTest {
29 |
30 | @Test
31 | public void test() {
32 | CandlestickChart.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/indicators/IndicatorsToChartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.indicators;
25 |
26 | import org.junit.Test;
27 |
28 | public class IndicatorsToChartTest {
29 |
30 | @Test
31 | public void test() {
32 | IndicatorsToChart.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/logging/StrategyExecutionLoggingTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.logging;
25 |
26 | import org.junit.Test;
27 |
28 | public class StrategyExecutionLoggingTest {
29 |
30 | @Test
31 | public void test() {
32 | StrategyExecutionLogging.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/strategies/CCICorrectionStrategyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.strategies;
25 |
26 | import org.junit.Test;
27 |
28 | public class CCICorrectionStrategyTest {
29 |
30 | @Test
31 | public void test() {
32 | CCICorrectionStrategy.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/strategies/GlobalExtremaStrategyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.strategies;
25 |
26 | import org.junit.Test;
27 |
28 | public class GlobalExtremaStrategyTest {
29 |
30 | @Test
31 | public void test() {
32 | GlobalExtremaStrategy.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/strategies/MovingMomentumStrategyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.strategies;
25 |
26 | import org.junit.Test;
27 |
28 | public class MovingMomentumStrategyTest {
29 |
30 | @Test
31 | public void test() {
32 | MovingMomentumStrategy.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/analysis/BuyAndSellSignalsToChartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.analysis;
25 |
26 | import org.junit.Test;
27 |
28 | public class BuyAndSellSignalsToChartTest {
29 | @Test
30 | public void test() {
31 | BuyAndSellSignalsToChart.main(null);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/aggregator/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Aggregator.
26 | *
27 | *
28 | * This package can be used to aggregate {@link org.ta4j.core.Bar bars} by
29 | * various conditions, e.g. by
30 | * {@link org.ta4j.core.aggregator.DurationBarAggregator duration}.
31 | */
32 | package org.ta4j.core.aggregator;
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/bots/TradingBotOnMovingBarSeriesTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.bots;
25 |
26 | import org.junit.Test;
27 |
28 | public class TradingBotOnMovingBarSeriesTest {
29 |
30 | @Test
31 | public void test() throws InterruptedException {
32 | TradingBotOnMovingBarSeries.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/BarSeriesBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core;
25 |
26 | /**
27 | * Interface to build a bar series.
28 | */
29 | public interface BarSeriesBuilder {
30 |
31 | /**
32 | * Builds the bar series with corresponding parameters.
33 | *
34 | * @return bar series
35 | */
36 | BarSeries build();
37 | }
38 |
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/backtesting/SimpleMovingAverageBacktestTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.backtesting;
25 |
26 | import org.junit.Test;
27 |
28 | public class SimpleMovingAverageBacktestTest {
29 |
30 | @Test
31 | public void test() throws InterruptedException {
32 | SimpleMovingAverageBacktest.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/analysis/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Analysis.
26 | *
27 | *
28 | * This package contains instruments to inspect backtesting results like the
29 | * {@link org.ta4j.core.analysis.CashFlow CashFlow} and to calculate
30 | * {@link org.ta4j.core.analysis.cost.CostModel trading costs}.
31 | */
32 | package org.ta4j.core.analysis;
--------------------------------------------------------------------------------
/ta4j-examples/src/test/java/ta4jexamples/backtesting/SimpleMovingAverageRangeBacktestTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.backtesting;
25 |
26 | import org.junit.Test;
27 |
28 | public class SimpleMovingAverageRangeBacktestTest {
29 |
30 | @Test
31 | public void test() throws InterruptedException {
32 | SimpleMovingAverageRangeBacktest.main(null);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/criteria/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Analysis criteria.
26 | *
27 | *
28 | * This package contains different criteria which can be used to calculate the
29 | * performance of a {@link org.ta4j.core.Strategy trading strategy} and to
30 | * compare two {@link org.ta4j.core.Strategy trading strategies} to each other.
31 | */
32 | package org.ta4j.core.criteria;
33 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Trading rules for trading strategies.
26 | *
27 | *
28 | * A {@link org.ta4j.core.Rule rule} can be combined and set as entry/exit
29 | * signals for a {@link org.ta4j.core.Strategy trading strategy}. A trading
30 | * strategy is designed to achieve a profitable return by going long or short
31 | * over a {@link org.ta4j.core.BarSeries series}.
32 | */
33 | package org.ta4j.core.rules;
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/CriterionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core;
25 |
26 | @FunctionalInterface
27 | public interface CriterionFactory {
28 |
29 | /**
30 | * Applies parameters to a CriterionFactory and returns the AnalysisCriterion.
31 | *
32 | * @param params criteria parameters
33 | * @return AnalysisCriterion with the parameters applied
34 | */
35 | AnalysisCriterion getCriterion(Object... params);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/aggregator/BarAggregator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.aggregator;
25 |
26 | import java.util.List;
27 |
28 | import org.ta4j.core.Bar;
29 |
30 | /**
31 | * Aggregates a list of {@link Bar bars} into another one.
32 | */
33 | public interface BarAggregator {
34 |
35 | /**
36 | * Aggregates the {@code bars} into another one.
37 | *
38 | * @param bars the bars to be aggregated
39 | * @return aggregated bars
40 | */
41 | List aggregate(List bars);
42 | }
43 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * Technical indicators.
26 | *
27 | *
28 | * Market indicators are mathematical transformations. They are used to assess
29 | * whether an asset is trending and, if so, the probability of its direction and
30 | * continuation.
31 | *
32 | * @see http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators
34 | */
35 | package org.ta4j.core.indicators;
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/IndicatorFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core;
25 |
26 | @FunctionalInterface
27 | public interface IndicatorFactory {
28 |
29 | /**
30 | * Applies parameters and data to an IndicatorFactory and returns the Indicator.
31 | *
32 | * @param data source data for building the indicator
33 | * @param params indicator parameters
34 | * @return Indicator with the indicator parameters applied
35 | */
36 | Indicator getIndicator(D data, Object... params);
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/analysis/cost/ZeroCostModel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.analysis.cost;
25 |
26 | /**
27 | * With this cost model there are no trading costs.
28 | */
29 | public class ZeroCostModel extends FixedTransactionCostModel {
30 |
31 | private static final double ZERO_FEE_PER_TRADE = 0.0;
32 |
33 | /**
34 | * Constructor with {@code feePerTrade = 0}.
35 | *
36 | * @see FixedTransactionCostModel
37 | */
38 | public ZeroCostModel() {
39 | super(ZERO_FEE_PER_TRADE);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/ta4j-examples/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.ta4j
5 | ta4j-parent
6 | 0.17-SNAPSHOT
7 |
8 | ta4j-examples
9 |
10 | Ta4j Examples
11 | Provides examples that demonstrate how to use ta4j
12 |
13 |
14 |
15 |
16 |
17 | junit
18 | junit
19 | 4.13.2
20 | test
21 |
22 |
23 |
24 | org.ta4j
25 | ta4j-core
26 | 0.17-SNAPSHOT
27 |
28 |
29 |
30 | com.opencsv
31 | opencsv
32 | 5.7.1
33 |
34 |
35 |
36 | org.jfree
37 | jfreechart
38 | 1.5.3
39 |
40 |
41 |
42 | ch.qos.logback
43 | logback-classic
44 |
45 |
46 |
47 | com.google.code.gson
48 | gson
49 | 2.10
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/criteria/AbstractAnalysisCriterion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.criteria;
25 |
26 | import org.ta4j.core.AnalysisCriterion;
27 |
28 | /**
29 | * An abstract analysis criterion.
30 | */
31 | public abstract class AbstractAnalysisCriterion implements AnalysisCriterion {
32 |
33 | @Override
34 | public String toString() {
35 | String[] tokens = getClass().getSimpleName().split("(?=\\p{Lu})", -1);
36 | StringBuilder sb = new StringBuilder();
37 | for (int i = 0; i < tokens.length - 1; i++) {
38 | sb.append(tokens[i]).append(' ');
39 | }
40 | return sb.toString().trim();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/FixedBooleanIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 |
28 | /**
29 | * A fixed boolean indicator.
30 | *
31 | *
32 | * Returns constant {@link Boolean} values for a bar.
33 | */
34 | public class FixedBooleanIndicator extends FixedIndicator {
35 |
36 | /**
37 | * Constructor.
38 | *
39 | * @param series the bar series
40 | * @param values the values to be returned by this indicator
41 | */
42 | public FixedBooleanIndicator(BarSeries series, Boolean... values) {
43 | super(series, values);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/reports/ReportGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.reports;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.Strategy;
28 | import org.ta4j.core.TradingRecord;
29 |
30 | /**
31 | * Generic interface for generating trading reports.
32 | *
33 | * @param type of report to be generated
34 | */
35 | public interface ReportGenerator {
36 |
37 | /**
38 | * Generates a report based on the {@code tradingRecord}.
39 | *
40 | * @param tradingRecord the trading record (not null)
41 | * @param series the bar series (not null)
42 | * @return generated report
43 | */
44 | T generate(Strategy strategy, TradingRecord tradingRecord, BarSeries series);
45 | }
46 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/num/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | /**
25 | * {@link org.ta4j.core.num.Num Num} interface and implementations of
26 | * {@link org.ta4j.core.num.NaN NaN}, {@link org.ta4j.core.num.DoubleNum
27 | * DoubleNum} and {@link org.ta4j.core.num.DecimalNum PrecisionNum}.
28 | *
29 | *
30 | * The {@link org.ta4j.core.num.Num Num interface} enables the use of different
31 | * delegates (Double, {@link java.math.BigDecimal BigDecimal}, ...) for storage
32 | * and calculations in {@link org.ta4j.core.BarSeries BarSeries},
33 | * {@link org.ta4j.core.Bar Bars}, {@link org.ta4j.core.Indicator Indicators}
34 | * and {@link org.ta4j.core.criteria.AbstractAnalysisCriterion
35 | * AnalysisCriterions}.
36 | */
37 | package org.ta4j.core.num;
38 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/num/DoubleNumTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.num;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Test;
30 |
31 | public class DoubleNumTest {
32 |
33 | @Test
34 | public void testEqualsDoubleNumWithDecimalNum() {
35 | final DecimalNum decimalNum = DecimalNum.valueOf(3.0);
36 | final DoubleNum doubleNum = DoubleNum.valueOf(3.0);
37 |
38 | assertFalse(doubleNum.equals(decimalNum));
39 | }
40 |
41 | @Test
42 | public void testZeroEquals() {
43 | final Num num1 = DoubleNum.valueOf(-0.0);
44 | final Num num2 = DoubleNum.valueOf(0.0);
45 |
46 | assertTrue(num1.isEqual(num2));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/EMAIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.num.Num;
28 |
29 | /**
30 | * Exponential moving average indicator.
31 | *
32 | * @see https://www.investopedia.com/terms/e/ema.asp
34 | */
35 | public class EMAIndicator extends AbstractEMAIndicator {
36 |
37 | /**
38 | * Constructor.
39 | *
40 | * @param indicator an indicator
41 | * @param barCount the EMA time frame
42 | */
43 | public EMAIndicator(Indicator indicator, int barCount) {
44 | super(indicator, barCount, (2.0 / (barCount + 1)));
45 | }
46 |
47 | @Override
48 | public int getUnstableBars() {
49 | return getBarCount();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/MMAIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.num.Num;
28 |
29 | /**
30 | * Modified moving average indicator.
31 | *
32 | *
33 | * It is similar to exponential moving average but smooths more slowly. Used in
34 | * Welles Wilder's indicators like ADX, RSI.
35 | */
36 | public class MMAIndicator extends AbstractEMAIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param indicator the {@link Indicator}
42 | * @param barCount the MMA time frame
43 | */
44 | public MMAIndicator(Indicator indicator, int barCount) {
45 | super(indicator, barCount, 1.0 / barCount);
46 | }
47 |
48 | @Override
49 | public int getUnstableBars() {
50 | return getBarCount();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/TradeCountIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.CachedIndicator;
28 |
29 | /**
30 | * Trade count indicator.
31 | *
32 | *
33 | * Returns the number of trades of a bar.
34 | */
35 | public class TradeCountIndicator extends CachedIndicator {
36 |
37 | /**
38 | * Constructor.
39 | *
40 | * @param series the bar series
41 | */
42 | public TradeCountIndicator(BarSeries series) {
43 | super(series);
44 | }
45 |
46 | @Override
47 | protected Long calculate(int index) {
48 | return getBarSeries().getBar(index).getTrades();
49 | }
50 |
51 | /** @return {@code 0} */
52 | @Override
53 | public int getUnstableBars() {
54 | return 0;
55 | }
56 | }
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/AmountIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.CachedIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Amount indicator.
32 | *
33 | *
34 | * Returns the amount of a bar.
35 | */
36 | public class AmountIndicator extends CachedIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param series the bar series
42 | */
43 | public AmountIndicator(BarSeries series) {
44 | super(series);
45 | }
46 |
47 | @Override
48 | protected Num calculate(int index) {
49 | return getBarSeries().getBar(index).getAmount();
50 | }
51 |
52 | /** @return {@code 0} */
53 | @Override
54 | public int getUnstableBars() {
55 | return 0;
56 | }
57 | }
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/backtest/TradeExecutionModel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.backtest;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.TradingRecord;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * An execution model for {@link BarSeriesManager} objects.
32 | *
33 | * Used for backtesting. Instructs {@link BarSeriesManager} on how to execute
34 | * trades.
35 | */
36 | public interface TradeExecutionModel {
37 |
38 | /**
39 | * Executes a trade in the given {@code tradingRecord}.
40 | *
41 | * @param index the trade index from {@code barSeries}
42 | * @param tradingRecord the trading record to place the trade
43 | * @param barSeries the bar series
44 | * @param amount the trade amount
45 | */
46 | void execute(int index, TradingRecord tradingRecord, BarSeries barSeries, Num amount);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/LowPriceIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.AbstractIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Low price indicator.
32 | *
33 | *
34 | * Returns the low price of a bar.
35 | */
36 | public class LowPriceIndicator extends AbstractIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param series the bar series
42 | */
43 | public LowPriceIndicator(BarSeries series) {
44 | super(series);
45 | }
46 |
47 | @Override
48 | public Num getValue(int index) {
49 | return getBarSeries().getBar(index).getLowPrice();
50 | }
51 |
52 | /** @return {@code 0} */
53 | @Override
54 | public int getUnstableBars() {
55 | return 0;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/OpenPriceIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.AbstractIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Open price indicator.
32 | *
33 | *
34 | * Returns the open price of a bar.
35 | */
36 | public class OpenPriceIndicator extends AbstractIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param series the bar series
42 | */
43 | public OpenPriceIndicator(BarSeries series) {
44 | super(series);
45 | }
46 |
47 | @Override
48 | public Num getValue(int index) {
49 | return getBarSeries().getBar(index).getOpenPrice();
50 | }
51 |
52 | /** @return {@code 0} */
53 | @Override
54 | public int getUnstableBars() {
55 | return 0;
56 | }
57 | }
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/ClosePriceIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.AbstractIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Close price indicator.
32 | *
33 | *
34 | * Returns the close price of a bar.
35 | */
36 | public class ClosePriceIndicator extends AbstractIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param series the bar series
42 | */
43 | public ClosePriceIndicator(BarSeries series) {
44 | super(series);
45 | }
46 |
47 | @Override
48 | public Num getValue(int index) {
49 | return getBarSeries().getBar(index).getClosePrice();
50 | }
51 |
52 | /** @return {@code 0} */
53 | @Override
54 | public int getUnstableBars() {
55 | return 0;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/HighPriceIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.AbstractIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * The high price indicator.
32 | *
33 | *
34 | * Returns the high price of a bar.
35 | */
36 | public class HighPriceIndicator extends AbstractIndicator {
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param series the bar series
42 | */
43 | public HighPriceIndicator(BarSeries series) {
44 | super(series);
45 | }
46 |
47 | @Override
48 | public Num getValue(int index) {
49 | return getBarSeries().getBar(index).getHighPrice();
50 | }
51 |
52 | /** @return {@code 0} */
53 | @Override
54 | public int getUnstableBars() {
55 | return 0;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/NotRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.Rule;
32 |
33 | public class NotRuleTest {
34 |
35 | private Rule satisfiedRule;
36 | private Rule unsatisfiedRule;
37 |
38 | @Before
39 | public void setUp() {
40 | satisfiedRule = new BooleanRule(true);
41 | unsatisfiedRule = new BooleanRule(false);
42 | }
43 |
44 | @Test
45 | public void isSatisfied() {
46 | assertFalse(satisfiedRule.negation().isSatisfied(0));
47 | assertTrue(unsatisfiedRule.negation().isSatisfied(0));
48 |
49 | assertFalse(satisfiedRule.negation().isSatisfied(10));
50 | assertTrue(unsatisfiedRule.negation().isSatisfied(10));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/backtest/TradeOnCurrentCloseModel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.backtest;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.TradingRecord;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * An execution model for {@link BarSeriesManager} objects.
32 | *
33 | * Executes trades on the current bar being considered using the closing price.
34 | *
35 | * This is used for strategies that explicitly trade just before the bar closes
36 | * at index `t`, in order to execute new or close existing trades as close as
37 | * possible to the closing price.
38 | */
39 | public class TradeOnCurrentCloseModel implements TradeExecutionModel {
40 |
41 | @Override
42 | public void execute(int index, TradingRecord tradingRecord, BarSeries barSeries, Num amount) {
43 | tradingRecord.operate(index, barSeries.getBar(index).getClosePrice(), amount);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/ExternalIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core;
25 |
26 | import org.ta4j.core.num.Num;
27 |
28 | public interface ExternalIndicatorTest {
29 |
30 | /**
31 | * Gets the BarSeries used by an external indicator calculator.
32 | *
33 | * @return BarSeries from the external indicator calculator
34 | * @throws Exception if the external calculator throws an Exception
35 | */
36 | BarSeries getSeries() throws Exception;
37 |
38 | /**
39 | * Sends indicator parameters to an external indicator calculator and returns
40 | * the externally calculated indicator.
41 | *
42 | * @param params indicator parameters
43 | * @return Indicator from the external indicator calculator
44 | * @throws Exception if the external calculator throws an Exception
45 | */
46 | Indicator getIndicator(Object... params) throws Exception;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/aggregator/BarSeriesAggregator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.aggregator;
25 |
26 | import org.ta4j.core.BarSeries;
27 |
28 | /**
29 | * Aggregates a {@link BarSeries} into another one.
30 | */
31 | public interface BarSeriesAggregator {
32 |
33 | /**
34 | * Aggregates the {@code series} into another one.
35 | *
36 | * @param series the series to be aggregated
37 | * @return aggregated series
38 | */
39 | default BarSeries aggregate(BarSeries series) {
40 | return aggregate(series, series.getName());
41 | }
42 |
43 | /**
44 | * Aggregates the {@code series} into another one.
45 | *
46 | * @param series the series to be aggregated
47 | * @param aggregatedSeriesName the name for the aggregated series
48 | * @return aggregated series with specified name
49 | */
50 | BarSeries aggregate(BarSeries series, String aggregatedSeriesName);
51 | }
52 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/AbstractIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators;
25 |
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.ta4j.core.BarSeries;
29 | import org.ta4j.core.Indicator;
30 |
31 | /**
32 | * Abstract {@link Indicator indicator}.
33 | */
34 | public abstract class AbstractIndicator implements Indicator {
35 |
36 | /** The logger. */
37 | protected final Logger log = LoggerFactory.getLogger(getClass());
38 |
39 | private final BarSeries series;
40 |
41 | /**
42 | * Constructor.
43 | *
44 | * @param series the bar series
45 | */
46 | protected AbstractIndicator(BarSeries series) {
47 | this.series = series;
48 | }
49 |
50 | @Override
51 | public BarSeries getBarSeries() {
52 | return series;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return getClass().getSimpleName();
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/BooleanIndicatorRule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.TradingRecord;
28 |
29 | /**
30 | * Satisfied when the value of the boolean {@link Indicator indicator} is
31 | * {@code true}.
32 | */
33 | public class BooleanIndicatorRule extends AbstractRule {
34 |
35 | private final Indicator indicator;
36 |
37 | /**
38 | * Constructor.
39 | *
40 | * @param indicator the boolean indicator
41 | */
42 | public BooleanIndicatorRule(Indicator indicator) {
43 | this.indicator = indicator;
44 | }
45 |
46 | /** This rule does not use the {@code tradingRecord}. */
47 | @Override
48 | public boolean isSatisfied(int index, TradingRecord tradingRecord) {
49 | final boolean satisfied = indicator.getValue(index);
50 | traceIsSatisfied(index, satisfied);
51 | return satisfied;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/AbstractRule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.ta4j.core.Rule;
29 |
30 | /**
31 | * An abstract trading {@link Rule rule}.
32 | */
33 | public abstract class AbstractRule implements Rule {
34 |
35 | /** The logger */
36 | protected final transient Logger log = LoggerFactory.getLogger(getClass());
37 |
38 | /** The class name */
39 | private final String className = getClass().getSimpleName();
40 |
41 | /**
42 | * Traces the {@code isSatisfied()} method calls.
43 | *
44 | * @param index the bar index
45 | * @param isSatisfied true if the rule is satisfied, false otherwise
46 | */
47 | protected void traceIsSatisfied(int index, boolean isSatisfied) {
48 | if (log.isTraceEnabled()) {
49 | log.trace("{}#isSatisfied({}): {}", className, index, isSatisfied);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/ConstantIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static org.ta4j.core.TestUtils.assertNumEquals;
27 |
28 | import org.junit.Before;
29 | import org.junit.Test;
30 | import org.ta4j.core.BarSeries;
31 | import org.ta4j.core.BaseBarSeries;
32 | import org.ta4j.core.num.Num;
33 |
34 | public class ConstantIndicatorTest {
35 | private ConstantIndicator constantIndicator;
36 |
37 | @Before
38 | public void setUp() {
39 | BarSeries series = new BaseBarSeries();
40 | constantIndicator = new ConstantIndicator(series, series.numOf(30.33));
41 | }
42 |
43 | @Test
44 | public void constantIndicator() {
45 | assertNumEquals("30.33", constantIndicator.getValue(0));
46 | assertNumEquals("30.33", constantIndicator.getValue(1));
47 | assertNumEquals("30.33", constantIndicator.getValue(10));
48 | assertNumEquals("30.33", constantIndicator.getValue(30));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/mocks/MockTradingRecord.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.mocks;
25 |
26 | import java.util.List;
27 |
28 | import org.ta4j.core.BaseTradingRecord;
29 | import org.ta4j.core.num.Num;
30 |
31 | public class MockTradingRecord extends BaseTradingRecord {
32 |
33 | private static final long serialVersionUID = 6220278197931451635L;
34 |
35 | /*
36 | * Constructor. Builds a TradingRecord from a list of states. Initial state
37 | * value is zero. Then at each index where the state value changes, the
38 | * TradingRecord operates at that index.
39 | *
40 | * @param states List of state values
41 | */
42 | public MockTradingRecord(List states) {
43 | double lastState = 0d;
44 | for (int i = 0; i < states.size(); i++) {
45 | double state = states.get(i).doubleValue();
46 | if (state != lastState) {
47 | this.operate(i);
48 | }
49 | lastState = state;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/BooleanIndicatorRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.BaseBarSeries;
32 | import org.ta4j.core.Indicator;
33 | import org.ta4j.core.indicators.helpers.FixedIndicator;
34 |
35 | public class BooleanIndicatorRuleTest {
36 |
37 | private BooleanIndicatorRule rule;
38 |
39 | @Before
40 | public void setUp() {
41 | Indicator indicator = new FixedIndicator(new BaseBarSeries(), true, true, false, false, true);
42 | rule = new BooleanIndicatorRule(indicator);
43 | }
44 |
45 | @Test
46 | public void isSatisfied() {
47 | assertTrue(rule.isSatisfied(0));
48 | assertTrue(rule.isSatisfied(1));
49 | assertFalse(rule.isSatisfied(2));
50 | assertFalse(rule.isSatisfied(3));
51 | assertTrue(rule.isSatisfied(4));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/aggregator/BaseBarSeriesAggregator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.aggregator;
25 |
26 | import java.util.List;
27 |
28 | import org.ta4j.core.Bar;
29 | import org.ta4j.core.BarSeries;
30 | import org.ta4j.core.BaseBarSeries;
31 |
32 | /**
33 | * Aggregates a {@link BaseBarSeries} into another one using a
34 | * {@link BarAggregator}.
35 | */
36 | public class BaseBarSeriesAggregator implements BarSeriesAggregator {
37 |
38 | private final BarAggregator barAggregator;
39 |
40 | /**
41 | * Constructor.
42 | *
43 | * @param barAggregator the {@link BarAggregator}
44 | */
45 | public BaseBarSeriesAggregator(BarAggregator barAggregator) {
46 | this.barAggregator = barAggregator;
47 | }
48 |
49 | @Override
50 | public BarSeries aggregate(BarSeries series, String aggregatedSeriesName) {
51 | final List aggregatedBars = barAggregator.aggregate(series.getBarData());
52 | return new BaseBarSeries(aggregatedSeriesName, aggregatedBars);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/backtest/TradeOnNextOpenModel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.backtest;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.TradingRecord;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * An execution model for {@link BarSeriesManager} objects.
32 | *
33 | * Executes trades on the next bar at the open price.
34 | *
35 | * This is used for strategies that explicitly trade just after a new bar opens
36 | * at bar index `t + 1`, in order to execute new or close existing trades as
37 | * close as possible to the opening price.
38 | */
39 | public class TradeOnNextOpenModel implements TradeExecutionModel {
40 |
41 | @Override
42 | public void execute(int index, TradingRecord tradingRecord, BarSeries barSeries, Num amount) {
43 | int indexOfExecutedBar = index + 1;
44 | if (indexOfExecutedBar <= barSeries.getEndIndex()) {
45 | tradingRecord.operate(indexOfExecutedBar, barSeries.getBar(indexOfExecutedBar).getOpenPrice(), amount);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/IsEqualRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.BarSeries;
32 | import org.ta4j.core.BaseBarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.helpers.FixedDecimalIndicator;
35 | import org.ta4j.core.num.Num;
36 |
37 | public class IsEqualRuleTest {
38 |
39 | private IsEqualRule rule;
40 |
41 | @Before
42 | public void setUp() {
43 | BarSeries series = new BaseBarSeries();
44 | Indicator indicator = new FixedDecimalIndicator(series, 20, 10, 0, -20);
45 | rule = new IsEqualRule(indicator, series.numOf(20));
46 | }
47 |
48 | @Test
49 | public void isSatisfied() {
50 | assertTrue(rule.isSatisfied(0));
51 | assertFalse(rule.isSatisfied(1));
52 | assertFalse(rule.isSatisfied(2));
53 | assertFalse(rule.isSatisfied(3));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/BooleanRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 |
32 | public class BooleanRuleTest {
33 |
34 | private BooleanRule satisfiedRule;
35 | private BooleanRule unsatisfiedRule;
36 |
37 | @Before
38 | public void setUp() {
39 | satisfiedRule = new BooleanRule(true);
40 | unsatisfiedRule = new BooleanRule(false);
41 | }
42 |
43 | @Test
44 | public void isSatisfied() {
45 | assertTrue(satisfiedRule.isSatisfied(0));
46 | assertTrue(satisfiedRule.isSatisfied(1));
47 | assertTrue(satisfiedRule.isSatisfied(2));
48 | assertTrue(satisfiedRule.isSatisfied(10));
49 |
50 | assertFalse(unsatisfiedRule.isSatisfied(0));
51 | assertFalse(unsatisfiedRule.isSatisfied(1));
52 | assertFalse(unsatisfiedRule.isSatisfied(2));
53 | assertFalse(unsatisfiedRule.isSatisfied(10));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/ConstantIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.indicators.AbstractIndicator;
28 |
29 | /**
30 | * Constant indicator.
31 | *
32 | *
33 | * Returns a constant value for a bar.
34 | */
35 | public class ConstantIndicator extends AbstractIndicator {
36 |
37 | private final T value;
38 |
39 | /**
40 | * Constructor.
41 | *
42 | * @param series the bar series
43 | * @param t the constant value
44 | */
45 | public ConstantIndicator(BarSeries series, T t) {
46 | super(series);
47 | this.value = t;
48 | }
49 |
50 | @Override
51 | public T getValue(int index) {
52 | return value;
53 | }
54 |
55 | /** @return {@code 0} */
56 | @Override
57 | public int getUnstableBars() {
58 | return 0;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return getClass().getSimpleName() + " Value: " + value;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/ichimoku/IchimokuKijunSenIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.ichimoku;
25 |
26 | import org.ta4j.core.BarSeries;
27 |
28 | /**
29 | * Ichimoku clouds: Kijun-sen (Base line) indicator.
30 | *
31 | * @see
33 | * http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ichimoku_cloud
34 | */
35 | public class IchimokuKijunSenIndicator extends IchimokuLineIndicator {
36 |
37 | /**
38 | * Constructor with {@code barCount} = 26.
39 | *
40 | * @param series the bar series
41 | */
42 | public IchimokuKijunSenIndicator(BarSeries series) {
43 | super(series, 26);
44 | }
45 |
46 | /**
47 | * Constructor.
48 | *
49 | * @param series the bar series
50 | * @param barCount the time frame (usually 26)
51 | */
52 | public IchimokuKijunSenIndicator(BarSeries series, int barCount) {
53 | super(series, barCount);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/ichimoku/IchimokuTenkanSenIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.ichimoku;
25 |
26 | import org.ta4j.core.BarSeries;
27 |
28 | /**
29 | * Ichimoku clouds: Tenkan-sen (Conversion line) indicator.
30 | *
31 | * @see
33 | * http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ichimoku_cloud
34 | */
35 | public class IchimokuTenkanSenIndicator extends IchimokuLineIndicator {
36 |
37 | /**
38 | * Constructor with {@code barCount} = 9.
39 | *
40 | * @param series the bar series
41 | */
42 | public IchimokuTenkanSenIndicator(BarSeries series) {
43 | this(series, 9);
44 | }
45 |
46 | /**
47 | * Constructor.
48 | *
49 | * @param series the bar series
50 | * @param barCount the time frame (usually 9)
51 | */
52 | public IchimokuTenkanSenIndicator(BarSeries series, int barCount) {
53 | super(series, barCount);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/BooleanRule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import org.ta4j.core.TradingRecord;
27 |
28 | /**
29 | * Satisfied when the rule has been initialized with {@code true}.
30 | */
31 | public class BooleanRule extends AbstractRule {
32 |
33 | /** An always-true rule. */
34 | public static final BooleanRule TRUE = new BooleanRule(true);
35 |
36 | /** An always-false rule. */
37 | public static final BooleanRule FALSE = new BooleanRule(false);
38 |
39 | private final boolean satisfied;
40 |
41 | /**
42 | * Constructor.
43 | *
44 | * @param satisfied true for the rule to be always satisfied, false to be never
45 | * satisfied
46 | */
47 | public BooleanRule(boolean satisfied) {
48 | this.satisfied = satisfied;
49 | }
50 |
51 | /** This rule does not use the {@code tradingRecord}. */
52 | @Override
53 | public boolean isSatisfied(int index, TradingRecord tradingRecord) {
54 | traceIsSatisfied(index, satisfied);
55 | return satisfied;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/FixedRule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import java.util.Arrays;
27 |
28 | import org.ta4j.core.TradingRecord;
29 |
30 | /**
31 | * Satisfied when any of the specified {@code indexes} match the current bar
32 | * index.
33 | */
34 | public class FixedRule extends AbstractRule {
35 |
36 | private final int[] indexes;
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param indexes a sequence of indices to be compared to the current bar index
42 | */
43 | public FixedRule(int... indexes) {
44 | this.indexes = Arrays.copyOf(indexes, indexes.length);
45 | }
46 |
47 | /** This rule does not use the {@code tradingRecord}. */
48 | @Override
49 | public boolean isSatisfied(int index, TradingRecord tradingRecord) {
50 | boolean satisfied = false;
51 | for (int idx : indexes) {
52 | if (idx == index) {
53 | satisfied = true;
54 | break;
55 | }
56 | }
57 | traceIsSatisfied(index, satisfied);
58 | return satisfied;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/criteria/NumberOfLosingPositionsCriterion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.criteria;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.Position;
28 | import org.ta4j.core.TradingRecord;
29 | import org.ta4j.core.num.Num;
30 |
31 | /**
32 | * Number of closed losing positions criterion.
33 | */
34 | public class NumberOfLosingPositionsCriterion extends AbstractAnalysisCriterion {
35 |
36 | @Override
37 | public Num calculate(BarSeries series, Position position) {
38 | return position.hasLoss() ? series.one() : series.zero();
39 | }
40 |
41 | @Override
42 | public Num calculate(BarSeries series, TradingRecord tradingRecord) {
43 | long numberOfLosingPositions = tradingRecord.getPositions().stream().filter(Position::hasLoss).count();
44 | return series.numOf(numberOfLosingPositions);
45 | }
46 |
47 | /** The lower the criterion value, the better. */
48 | @Override
49 | public boolean betterThan(Num criterionValue1, Num criterionValue2) {
50 | return criterionValue1.isLessThan(criterionValue2);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/criteria/NumberOfWinningPositionsCriterion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.criteria;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.Position;
28 | import org.ta4j.core.TradingRecord;
29 | import org.ta4j.core.num.Num;
30 |
31 | /**
32 | * Number of closed winning positions criterion.
33 | */
34 | public class NumberOfWinningPositionsCriterion extends AbstractAnalysisCriterion {
35 |
36 | @Override
37 | public Num calculate(BarSeries series, Position position) {
38 | return position.hasProfit() ? series.one() : series.zero();
39 | }
40 |
41 | @Override
42 | public Num calculate(BarSeries series, TradingRecord tradingRecord) {
43 | long numberOfWinningPositions = tradingRecord.getPositions().stream().filter(Position::hasProfit).count();
44 | return series.numOf(numberOfWinningPositions);
45 | }
46 |
47 | /** The higher the criterion value, the better. */
48 | @Override
49 | public boolean betterThan(Num criterionValue1, Num criterionValue2) {
50 | return criterionValue1.isGreaterThan(criterionValue2);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/MedianPriceIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.Bar;
27 | import org.ta4j.core.BarSeries;
28 | import org.ta4j.core.indicators.CachedIndicator;
29 | import org.ta4j.core.num.Num;
30 |
31 | /**
32 | * Average high-low indicator.
33 | *
34 | *
35 | * Returns the median price of a bar using the following formula:
36 | *
37 | *
38 | * MedianPrice = (highPrice + lowPrice) / 2
39 | *
40 | */
41 | public class MedianPriceIndicator extends CachedIndicator {
42 |
43 | /**
44 | * Constructor.
45 | *
46 | * @param series the bar series
47 | */
48 | public MedianPriceIndicator(BarSeries series) {
49 | super(series);
50 | }
51 |
52 | @Override
53 | protected Num calculate(int index) {
54 | final Bar bar = getBarSeries().getBar(index);
55 | return bar.getHighPrice().plus(bar.getLowPrice()).dividedBy(numOf(2));
56 | }
57 |
58 | /** @return {@code 0} */
59 | @Override
60 | public int getUnstableBars() {
61 | return 0;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ta4j-examples/src/main/java/ta4jexamples/loaders/jsonhelper/GsonBarSeries.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package ta4jexamples.loaders.jsonhelper;
25 |
26 | import java.util.LinkedList;
27 | import java.util.List;
28 |
29 | import org.ta4j.core.Bar;
30 | import org.ta4j.core.BarSeries;
31 | import org.ta4j.core.BaseBarSeries;
32 | import org.ta4j.core.BaseBarSeriesBuilder;
33 |
34 | public class GsonBarSeries {
35 |
36 | private String name;
37 | private List ohlc = new LinkedList<>();
38 |
39 | public static GsonBarSeries from(BarSeries series) {
40 | GsonBarSeries result = new GsonBarSeries();
41 | result.name = series.getName();
42 | List barData = series.getBarData();
43 | for (Bar bar : barData) {
44 | GsonBarData exportableBarData = GsonBarData.from(bar);
45 | result.ohlc.add(exportableBarData);
46 | }
47 | return result;
48 | }
49 |
50 | public BarSeries toBarSeries() {
51 | BaseBarSeries result = new BaseBarSeriesBuilder().withName(this.name).build();
52 | for (GsonBarData data : ohlc) {
53 | data.addTo(result);
54 | }
55 | return result;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/rules/NotRule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import org.ta4j.core.Rule;
27 | import org.ta4j.core.TradingRecord;
28 |
29 | /**
30 | * An opposite (logical operator: NOT) rule (i.e. a rule that is the negation of
31 | * another rule).
32 | *
33 | *
34 | * Satisfied when the rule is not satisfied.
35 | * Not satisfied when the rule is satisfied.
36 | */
37 | public class NotRule extends AbstractRule {
38 |
39 | /** The trading rule to negate. */
40 | private final Rule ruleToNegate;
41 |
42 | /**
43 | * Constructor.
44 | *
45 | * @param ruleToNegate the trading rule to negate
46 | */
47 | public NotRule(Rule ruleToNegate) {
48 | this.ruleToNegate = ruleToNegate;
49 | }
50 |
51 | @Override
52 | public boolean isSatisfied(int index, TradingRecord tradingRecord) {
53 | final boolean satisfied = !ruleToNegate.isSatisfied(index, tradingRecord);
54 | traceIsSatisfied(index, satisfied);
55 | return satisfied;
56 | }
57 |
58 | /** @return {@link #ruleToNegate} */
59 | public Rule getRuleToNegate() {
60 | return ruleToNegate;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/FixedRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Test;
30 |
31 | public class FixedRuleTest {
32 |
33 | @Test
34 | public void isSatisfied() {
35 | FixedRule fixedRule = new FixedRule();
36 | assertFalse(fixedRule.isSatisfied(0));
37 | assertFalse(fixedRule.isSatisfied(1));
38 | assertFalse(fixedRule.isSatisfied(2));
39 | assertFalse(fixedRule.isSatisfied(9));
40 |
41 | fixedRule = new FixedRule(1, 2, 3);
42 | assertFalse(fixedRule.isSatisfied(0));
43 | assertTrue(fixedRule.isSatisfied(1));
44 | assertTrue(fixedRule.isSatisfied(2));
45 | assertTrue(fixedRule.isSatisfied(3));
46 | assertFalse(fixedRule.isSatisfied(4));
47 | assertFalse(fixedRule.isSatisfied(5));
48 | assertFalse(fixedRule.isSatisfied(6));
49 | assertFalse(fixedRule.isSatisfied(7));
50 | assertFalse(fixedRule.isSatisfied(8));
51 | assertFalse(fixedRule.isSatisfied(9));
52 | assertFalse(fixedRule.isSatisfied(10));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ta4j-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.ta4j
5 | ta4j-parent
6 | 0.17-SNAPSHOT
7 |
8 | ta4j-core
9 |
10 | Ta4j Core
11 | ta4j is a Java library providing a simple API for technical analysis.
12 |
13 |
14 |
15 |
16 |
17 | org.slf4j
18 | slf4j-api
19 | 2.0.7
20 |
21 |
22 |
23 |
24 | junit
25 | junit
26 | 4.13.2
27 | test
28 |
29 |
30 | org.apache.commons
31 | commons-math3
32 | 3.6.1
33 | test
34 |
35 |
36 | org.apache.poi
37 | poi
38 | 5.2.3
39 | test
40 |
41 |
42 | ch.qos.logback
43 | logback-classic
44 | test
45 |
46 |
47 |
48 |
49 |
50 | org.apache.maven.plugins
51 | maven-jar-plugin
52 | 3.3.0
53 |
54 |
55 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
56 |
57 |
58 |
59 |
60 | biz.aQute.bnd
61 | bnd-maven-plugin
62 | 3.3.0
63 |
64 |
65 | default-bnd-process
66 |
67 | bnd-process
68 |
69 |
70 |
71 |
72 |
73 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/FixedDecimalIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import java.math.BigDecimal;
27 |
28 | import org.ta4j.core.BarSeries;
29 | import org.ta4j.core.num.Num;
30 |
31 | /**
32 | * A fixed {@code Num} indicator.
33 | *
34 | *
35 | * Returns constant {@link Num} values for a bar.
36 | */
37 | public class FixedDecimalIndicator extends FixedIndicator {
38 |
39 | /**
40 | * Constructor.
41 | *
42 | * @param series the bar series
43 | * @param values the values to be returned by this indicator
44 | */
45 | public FixedDecimalIndicator(BarSeries series, double... values) {
46 | super(series);
47 | for (double value : values) {
48 | addValue(numOf(value));
49 | }
50 | }
51 |
52 | /**
53 | * Constructor.
54 | *
55 | * @param series the bar series
56 | * @param values the values to be returned by this indicator
57 | */
58 | public FixedDecimalIndicator(BarSeries series, String... values) {
59 | super(series);
60 | for (String value : values) {
61 | addValue(numOf(new BigDecimal(value)));
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/helpers/SumIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.indicators.CachedIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Calculates the sum of all indicator values.
32 | *
33 | *
34 | * Sum = summand0 + summand1 + ... + summandN
35 | *
36 | */
37 | public class SumIndicator extends CachedIndicator {
38 |
39 | private final Indicator[] summands;
40 |
41 | /**
42 | * Constructor.
43 | *
44 | * @param summands the indicators to be summed
45 | */
46 | @SafeVarargs
47 | public SumIndicator(Indicator... summands) {
48 | // TODO: check if first series is equal to the other ones
49 | super(summands[0]);
50 | this.summands = summands;
51 | }
52 |
53 | @Override
54 | protected Num calculate(int index) {
55 | Num sum = zero();
56 | for (Indicator summand : summands) {
57 | sum = sum.plus(summand.getValue(index));
58 | }
59 | return sum;
60 | }
61 |
62 | @Override
63 | public int getUnstableBars() {
64 | return 0;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/volume/MVWAPIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.volume;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.indicators.CachedIndicator;
28 | import org.ta4j.core.indicators.SMAIndicator;
29 | import org.ta4j.core.num.Num;
30 |
31 | /**
32 | * The Moving volume weighted average price (MVWAP) Indicator.
33 | *
34 | * @see
36 | * http://www.investopedia.com/articles/trading/11/trading-with-vwap-mvwap.asp
37 | */
38 | public class MVWAPIndicator extends CachedIndicator {
39 |
40 | private final Indicator sma;
41 |
42 | /**
43 | * Constructor.
44 | *
45 | * @param vwap the vwap
46 | * @param barCount the time frame
47 | */
48 | public MVWAPIndicator(VWAPIndicator vwap, int barCount) {
49 | super(vwap);
50 | this.sma = new SMAIndicator(vwap, barCount);
51 | }
52 |
53 | @Override
54 | protected Num calculate(int index) {
55 | return sma.getValue(index);
56 | }
57 |
58 | @Override
59 | public int getUnstableBars() {
60 | return 0;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/AmountIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class AmountIndicatorTest extends AbstractIndicatorTest, Num> {
39 |
40 | private AmountIndicator amountIndicator;
41 |
42 | BarSeries barSeries;
43 |
44 | public AmountIndicatorTest(Function numFunction) {
45 | super(numFunction);
46 | }
47 |
48 | @Before
49 | public void setUp() {
50 | barSeries = new MockBarSeries(numFunction);
51 | amountIndicator = new AmountIndicator(barSeries);
52 | }
53 |
54 | @Test
55 | public void indicatorShouldRetrieveBarAmountPrice() {
56 | for (int i = 0; i < 10; i++) {
57 | assertEquals(amountIndicator.getValue(i), barSeries.getBar(i).getAmount());
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/ClosePriceIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class ClosePriceIndicatorTest extends AbstractIndicatorTest, Num> {
39 | private ClosePriceIndicator closePrice;
40 |
41 | BarSeries barSeries;
42 |
43 | public ClosePriceIndicatorTest(Function numFunction) {
44 | super(numFunction);
45 | }
46 |
47 | @Before
48 | public void setUp() {
49 | barSeries = new MockBarSeries(numFunction);
50 | closePrice = new ClosePriceIndicator(barSeries);
51 | }
52 |
53 | @Test
54 | public void indicatorShouldRetrieveBarClosePrice() {
55 | for (int i = 0; i < 10; i++) {
56 | assertEquals(closePrice.getValue(i), barSeries.getBar(i).getClosePrice());
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/TradeCountIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static org.junit.Assert.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class TradeCountIndicatorTest extends AbstractIndicatorTest, Num> {
39 | private TradeCountIndicator tradeIndicator;
40 |
41 | BarSeries barSeries;
42 |
43 | public TradeCountIndicatorTest(Function numFunction) {
44 | super(numFunction);
45 | }
46 |
47 | @Before
48 | public void setUp() {
49 | barSeries = new MockBarSeries(numFunction);
50 | tradeIndicator = new TradeCountIndicator(barSeries);
51 | }
52 |
53 | @Test
54 | public void indicatorShouldRetrieveBarTrade() {
55 | for (int i = 0; i < 10; i++) {
56 | assertEquals((long) tradeIndicator.getValue(i), barSeries.getBar(i).getTrades());
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/ExternalCriterionTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core;
25 |
26 | import org.ta4j.core.num.Num;
27 |
28 | public interface ExternalCriterionTest {
29 |
30 | /**
31 | * Gets the BarSeries used by an external criterion calculator.
32 | *
33 | * @return BarSeries from the external criterion calculator
34 | * @throws Exception if the external calculator throws an Exception
35 | */
36 | BarSeries getSeries() throws Exception;
37 |
38 | /**
39 | * Sends criterion parameters to an external criterion calculator and returns
40 | * the final value of the externally calculated criterion.
41 | *
42 | * @param params criterion parameters
43 | * @return Num final criterion value
44 | * @throws Exception if the external calculator throws an Exception
45 | */
46 | Num getFinalCriterionValue(Object... params) throws Exception;
47 |
48 | /**
49 | * Gets the trading record used by an external criterion calculator.
50 | *
51 | * @return TradingRecord from the external criterion calculator
52 | * @throws Exception if the external calculator throws an Exception
53 | */
54 | TradingRecord getTradingRecord() throws Exception;
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/LowPriceIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class LowPriceIndicatorTest extends AbstractIndicatorTest, Num> {
39 | private LowPriceIndicator lowPriceIndicator;
40 |
41 | private BarSeries barSeries;
42 |
43 | public LowPriceIndicatorTest(Function numFunction) {
44 | super(numFunction);
45 | }
46 |
47 | @Before
48 | public void setUp() {
49 | barSeries = new MockBarSeries(numFunction);
50 | lowPriceIndicator = new LowPriceIndicator(barSeries);
51 | }
52 |
53 | @Test
54 | public void indicatorShouldRetrieveBarLowPrice() {
55 | for (int i = 0; i < 10; i++) {
56 | assertEquals(lowPriceIndicator.getValue(i), barSeries.getBar(i).getLowPrice());
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/OpenPriceIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class OpenPriceIndicatorTest extends AbstractIndicatorTest, Num> {
39 | private OpenPriceIndicator openPriceIndicator;
40 |
41 | BarSeries barSeries;
42 |
43 | public OpenPriceIndicatorTest(Function numFunction) {
44 | super(numFunction);
45 | }
46 |
47 | @Before
48 | public void setUp() {
49 | barSeries = new MockBarSeries(numFunction);
50 | openPriceIndicator = new OpenPriceIndicator(barSeries);
51 | }
52 |
53 | @Test
54 | public void indicatorShouldRetrieveBarOpenPrice() {
55 | for (int i = 0; i < 10; i++) {
56 | assertEquals(openPriceIndicator.getValue(i), barSeries.getBar(i).getOpenPrice());
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/OrRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.Rule;
32 |
33 | public class OrRuleTest {
34 |
35 | private Rule satisfiedRule;
36 | private Rule unsatisfiedRule;
37 |
38 | @Before
39 | public void setUp() {
40 | satisfiedRule = new BooleanRule(true);
41 | unsatisfiedRule = new BooleanRule(false);
42 | }
43 |
44 | @Test
45 | public void isSatisfied() {
46 | assertTrue(satisfiedRule.or(BooleanRule.FALSE).isSatisfied(0));
47 | assertTrue(BooleanRule.FALSE.or(satisfiedRule).isSatisfied(0));
48 | assertFalse(unsatisfiedRule.or(BooleanRule.FALSE).isSatisfied(0));
49 | assertFalse(BooleanRule.FALSE.or(unsatisfiedRule).isSatisfied(0));
50 |
51 | assertTrue(satisfiedRule.or(BooleanRule.TRUE).isSatisfied(10));
52 | assertTrue(BooleanRule.TRUE.or(satisfiedRule).isSatisfied(10));
53 | assertTrue(unsatisfiedRule.or(BooleanRule.TRUE).isSatisfied(10));
54 | assertTrue(BooleanRule.TRUE.or(unsatisfiedRule).isSatisfied(10));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/NumndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.Bar;
33 | import org.ta4j.core.BarSeries;
34 | import org.ta4j.core.Indicator;
35 | import org.ta4j.core.indicators.AbstractIndicatorTest;
36 | import org.ta4j.core.mocks.MockBarSeries;
37 | import org.ta4j.core.num.Num;
38 |
39 | public class NumndicatorTest extends AbstractIndicatorTest, Num> {
40 |
41 | private NumIndicator closePrice;
42 | private BarSeries barSeries;
43 |
44 | public NumndicatorTest(Function numFunction) {
45 | super(numFunction);
46 | }
47 |
48 | @Before
49 | public void setUp() {
50 | barSeries = new MockBarSeries(numFunction);
51 | closePrice = new NumIndicator(barSeries, Bar::getClosePrice);
52 | }
53 |
54 | @Test
55 | public void indicatorShouldRetrieveBarClosePrice() {
56 | for (int i = 0; i < 10; i++) {
57 | assertEquals(closePrice.getValue(i), barSeries.getBar(i).getClosePrice());
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/RWILowIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators;
25 |
26 | import static org.ta4j.core.TestUtils.assertIndicatorEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Test;
31 | import org.ta4j.core.BarSeries;
32 | import org.ta4j.core.ExternalIndicatorTest;
33 | import org.ta4j.core.num.Num;
34 |
35 | /**
36 | * Testing the RWILowIndicator
37 | */
38 | public class RWILowIndicatorTest extends AbstractIndicatorTest {
39 |
40 | /**
41 | * TODO: Just graphically Excel-Sheet validation with hard coded results. Excel
42 | * formula needed
43 | */
44 | private final ExternalIndicatorTest xls;
45 |
46 | public RWILowIndicatorTest(Function numFunction) {
47 | super((data, params) -> new RWILowIndicator(data, (int) params[0]), numFunction);
48 | xls = new XLSIndicatorTest(this.getClass(), "RWIHL.xls", 9, numFunction);
49 | }
50 |
51 | @Test
52 | public void randomWalkIndexHigh() throws Exception {
53 | BarSeries series = xls.getSeries();
54 | RWILowIndicator rwih = (RWILowIndicator) getIndicator(series, 20);
55 | assertIndicatorEquals(getIndicator(series, 20), rwih);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/helpers/HighPriceIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.helpers;
25 |
26 | import static junit.framework.TestCase.assertEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.ta4j.core.BarSeries;
33 | import org.ta4j.core.Indicator;
34 | import org.ta4j.core.indicators.AbstractIndicatorTest;
35 | import org.ta4j.core.mocks.MockBarSeries;
36 | import org.ta4j.core.num.Num;
37 |
38 | public class HighPriceIndicatorTest extends AbstractIndicatorTest, Num> {
39 | private HighPriceIndicator highPriceIndicator;
40 |
41 | private BarSeries barSeries;
42 |
43 | public HighPriceIndicatorTest(Function numFunction) {
44 | super(numFunction);
45 | }
46 |
47 | @Before
48 | public void setUp() {
49 | barSeries = new MockBarSeries(numFunction);
50 | highPriceIndicator = new HighPriceIndicator(barSeries);
51 |
52 | }
53 |
54 | @Test
55 | public void indicatorShouldRetrieveBarHighPrice() {
56 | for (int i = 0; i < 10; i++) {
57 | assertEquals(highPriceIndicator.getValue(i), barSeries.getBar(i).getHighPrice());
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/AndRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.Rule;
32 |
33 | public class AndRuleTest {
34 |
35 | private Rule satisfiedRule;
36 | private Rule unsatisfiedRule;
37 |
38 | @Before
39 | public void setUp() {
40 | satisfiedRule = new BooleanRule(true);
41 | unsatisfiedRule = new BooleanRule(false);
42 | }
43 |
44 | @Test
45 | public void isSatisfied() {
46 | assertFalse(satisfiedRule.and(BooleanRule.FALSE).isSatisfied(0));
47 | assertFalse(BooleanRule.FALSE.and(satisfiedRule).isSatisfied(0));
48 | assertFalse(unsatisfiedRule.and(BooleanRule.FALSE).isSatisfied(0));
49 | assertFalse(BooleanRule.FALSE.and(unsatisfiedRule).isSatisfied(0));
50 |
51 | assertTrue(satisfiedRule.and(BooleanRule.TRUE).isSatisfied(10));
52 | assertTrue(BooleanRule.TRUE.and(satisfiedRule).isSatisfied(10));
53 | assertFalse(unsatisfiedRule.and(BooleanRule.TRUE).isSatisfied(10));
54 | assertFalse(BooleanRule.TRUE.and(unsatisfiedRule).isSatisfied(10));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/rules/XorRuleTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.rules;
25 |
26 | import static org.junit.Assert.assertFalse;
27 | import static org.junit.Assert.assertTrue;
28 |
29 | import org.junit.Before;
30 | import org.junit.Test;
31 | import org.ta4j.core.Rule;
32 |
33 | public class XorRuleTest {
34 |
35 | private Rule satisfiedRule;
36 | private Rule unsatisfiedRule;
37 |
38 | @Before
39 | public void setUp() {
40 | satisfiedRule = new BooleanRule(true);
41 | unsatisfiedRule = new BooleanRule(false);
42 | }
43 |
44 | @Test
45 | public void isSatisfied() {
46 | assertTrue(satisfiedRule.xor(BooleanRule.FALSE).isSatisfied(0));
47 | assertTrue(BooleanRule.FALSE.xor(satisfiedRule).isSatisfied(0));
48 | assertFalse(unsatisfiedRule.xor(BooleanRule.FALSE).isSatisfied(0));
49 | assertFalse(BooleanRule.FALSE.xor(unsatisfiedRule).isSatisfied(0));
50 |
51 | assertFalse(satisfiedRule.xor(BooleanRule.TRUE).isSatisfied(10));
52 | assertFalse(BooleanRule.TRUE.xor(satisfiedRule).isSatisfied(10));
53 | assertTrue(unsatisfiedRule.xor(BooleanRule.TRUE).isSatisfied(10));
54 | assertTrue(BooleanRule.TRUE.xor(unsatisfiedRule).isSatisfied(10));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ta4j-core/src/test/java/org/ta4j/core/indicators/RWIHighIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators;
25 |
26 | import static org.ta4j.core.TestUtils.assertIndicatorEquals;
27 |
28 | import java.util.function.Function;
29 |
30 | import org.junit.Test;
31 | import org.ta4j.core.BarSeries;
32 | import org.ta4j.core.ExternalIndicatorTest;
33 | import org.ta4j.core.num.Num;
34 |
35 | /**
36 | * Testing the RWIHighIndicator
37 | */
38 | public class RWIHighIndicatorTest extends AbstractIndicatorTest {
39 |
40 | /**
41 | * TODO: Just graphically Excel-Sheet validation with hard coded results. Excel
42 | * formula needed
43 | */
44 | private final ExternalIndicatorTest xls;
45 |
46 | public RWIHighIndicatorTest(Function numFunction) {
47 | super((data, params) -> new RWIHighIndicator(data, (int) params[0]), numFunction);
48 | xls = new XLSIndicatorTest(this.getClass(), "RWIHL.xls", 8, numFunction);
49 | }
50 |
51 | @Test
52 | public void randomWalkIndexHigh() throws Exception {
53 | BarSeries series = xls.getSeries();
54 | RWIHighIndicator rwih = (RWIHighIndicator) getIndicator(series, 20);
55 | assertIndicatorEquals(getIndicator(series, 20), rwih);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/reports/PositionStatsReportGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.reports;
25 |
26 | import org.ta4j.core.BarSeries;
27 | import org.ta4j.core.Strategy;
28 | import org.ta4j.core.TradingRecord;
29 | import org.ta4j.core.criteria.NumberOfBreakEvenPositionsCriterion;
30 | import org.ta4j.core.criteria.NumberOfLosingPositionsCriterion;
31 | import org.ta4j.core.criteria.NumberOfWinningPositionsCriterion;
32 | import org.ta4j.core.num.Num;
33 |
34 | /**
35 | * Generates a {@link PositionStatsReport} based on provided trading record and
36 | * bar series.
37 | */
38 | public class PositionStatsReportGenerator implements ReportGenerator {
39 |
40 | @Override
41 | public PositionStatsReport generate(Strategy strategy, TradingRecord tradingRecord, BarSeries series) {
42 | final Num winningPositions = new NumberOfWinningPositionsCriterion().calculate(series, tradingRecord);
43 | final Num losingPositions = new NumberOfLosingPositionsCriterion().calculate(series, tradingRecord);
44 | final Num breakEvenPositions = new NumberOfBreakEvenPositionsCriterion().calculate(series, tradingRecord);
45 | return new PositionStatsReport(winningPositions, losingPositions, breakEvenPositions);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ta4j-core/src/main/java/org/ta4j/core/indicators/statistics/StandardErrorIndicator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017-2023 Ta4j Organization & respective
5 | * authors (see AUTHORS)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 | * this software and associated documentation files (the "Software"), to deal in
9 | * the Software without restriction, including without limitation the rights to
10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 | * the Software, and to permit persons to whom the Software is furnished to do so,
12 | * subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | */
24 | package org.ta4j.core.indicators.statistics;
25 |
26 | import org.ta4j.core.Indicator;
27 | import org.ta4j.core.indicators.CachedIndicator;
28 | import org.ta4j.core.num.Num;
29 |
30 | /**
31 | * Standard error indicator.
32 | */
33 | public class StandardErrorIndicator extends CachedIndicator {
34 |
35 | private final int barCount;
36 | private final StandardDeviationIndicator sdev;
37 |
38 | /**
39 | * Constructor.
40 | *
41 | * @param indicator the indicator
42 | * @param barCount the time frame
43 | */
44 | public StandardErrorIndicator(Indicator indicator, int barCount) {
45 | super(indicator);
46 | this.barCount = barCount;
47 | this.sdev = new StandardDeviationIndicator(indicator, barCount);
48 | }
49 |
50 | @Override
51 | protected Num calculate(int index) {
52 | final int startIndex = Math.max(0, index - barCount + 1);
53 | final int numberOfObservations = index - startIndex + 1;
54 | return sdev.getValue(index).dividedBy(numOf(numberOfObservations).sqrt());
55 | }
56 |
57 | @Override
58 | public int getUnstableBars() {
59 | return barCount;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------