├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── code_blocks
├── check-lrma
│ ├── check-lrma.cbp
│ └── main.cpp
├── check-rshillma
│ ├── check-rshillma.cbp
│ └── main.cpp
├── check-td
│ ├── check-td.cbp
│ └── main.cpp
├── check_bb
│ ├── check_bb.cbp
│ └── main.cpp
├── check_crsi
│ ├── check_crsi.cbp
│ └── main.cpp
├── check_delay_line
│ ├── check_delay_line.cbp
│ └── main.cpp
├── check_fft
│ ├── check_fft.cbp
│ └── main.cpp
├── check_indicators
│ ├── check_indicators.cbp
│ └── main.cpp
├── check_maz
│ ├── check_maz.cbp
│ └── main.cpp
├── check_min_max
│ ├── check_min_max.cbp
│ └── main.cpp
├── check_min_max_difference
│ ├── check_min_max_difference.cbp
│ └── main.cpp
├── check_pri
│ ├── check_pri.cbp
│ └── main.cpp
├── check_sma
│ ├── check_sma.cbp
│ └── main.cpp
├── check_stochastics
│ ├── check_stochastics.cbp
│ └── main.cpp
├── check_sum
│ ├── check_sum.cbp
│ └── main.cpp
├── check_zscore
│ ├── check_zscore.cbp
│ └── main.cpp
├── checking_circular_buffer
│ ├── checking_circular_buffer.cbp
│ └── main.cpp
├── checking_delay_measurement
│ ├── checking_delay_measurement.cbp
│ └── main.cpp
├── checking_least_square_method
│ ├── checking_least_square_method.cbp
│ └── main.cpp
├── checking_normalization
│ ├── checking_normalization.cbp
│ └── main.cpp
├── checking_statistical_indicators
│ ├── checking_statistical_indicators.cbp
│ └── main.cpp
├── checking_statistics
│ ├── checking_statistics.cbp
│ └── main.cpp
├── cmp_min_max_witch_streaming_min_max
│ ├── cmp_min_max_witch_streaming_min_max.cbp
│ └── main.cpp
└── test
│ ├── atr.cpp
│ ├── body_filter.cpp
│ ├── cci.cpp
│ ├── cluster_shaper.cpp
│ ├── fractals.cpp
│ ├── period_stats.cpp
│ ├── ssa.cpp
│ ├── super_trend.cpp
│ ├── test.cbp
│ └── trend_direction_force_index.cpp
├── doc
└── example_0.png
└── include
├── backtest
└── xtechnical_winrate_statistics.hpp
├── indicators
├── ssa.hpp
├── xtechnical_atr.hpp
├── xtechnical_awesome_oscillator.hpp
├── xtechnical_body_filter.hpp
├── xtechnical_cci.hpp
├── xtechnical_cluster_shaper.hpp
├── xtechnical_crsi.hpp
├── xtechnical_delay_line.hpp
├── xtechnical_fast_min_max.hpp
├── xtechnical_fisher.hpp
├── xtechnical_fractals.hpp
├── xtechnical_fractals_level.hpp
├── xtechnical_period_stats.hpp
├── xtechnical_rsi.hpp
├── xtechnical_sma.hpp
├── xtechnical_super_trend.hpp
└── xtechnical_true_range.hpp
├── math
├── xtechnical_compare.hpp
├── xtechnical_ordinary_least_squares.hpp
└── xtechnical_smoothing.hpp
├── xtechnical_circular_buffer.hpp
├── xtechnical_circular_buffer.mqh
├── xtechnical_common.hpp
├── xtechnical_correlation.hpp
├── xtechnical_delay_meter.hpp
├── xtechnical_dft.hpp
├── xtechnical_indicators.hpp
├── xtechnical_moving_window.hpp
├── xtechnical_normalization.hpp
├── xtechnical_regression_analysis.hpp
├── xtechnical_sma.mqh
├── xtechnical_statistics.hpp
└── xtechnical_streaming_min_max.hpp
/.gitignore:
--------------------------------------------------------------------------------
1 | *.depend
2 | *.layout
3 | *.o
4 | *testing/*/bin
5 | *code_blocks/*/bin
6 |
7 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "lib/easy_plot_cpp"]
2 | path = lib/easy_plot_cpp
3 | url = https://github.com/NewYaroslav/easy_plot_cpp.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Yaroslav
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/code_blocks/check-lrma/check-lrma.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/code_blocks/check-lrma/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
8 |
9 | const size_t period = 4;
10 | xtechnical_indicators::LRMA iLRMA(period);
11 |
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | iLRMA.update(test_data[i]);
14 | std::cout
15 | << "update " << test_data[i]
16 | << " get " << iLRMA.get()
17 | << std::endl;
18 | }
19 |
20 | /* проверяем методы тест */
21 | std::cout << "test(20)" << std::endl;
22 | iLRMA.test(20);
23 | std::cout << "get " << iLRMA.get() << std::endl;
24 |
25 |
26 | std::cout << "test(21)" << std::endl;
27 | iLRMA.test(21);
28 | std::cout << "get " << iLRMA.get() << std::endl;
29 |
30 | std::cout << "test(10)" << std::endl;
31 | iLRMA.test(10);
32 | std::cout << "get " << iLRMA.get() << std::endl;
33 |
34 | for(size_t i = test_data.size() - 1; i > 0; --i) {
35 | iLRMA.update(test_data[i]);
36 | std::cout
37 | << "update " << test_data[i]
38 | << " get " << iLRMA.get()
39 | << std::endl;
40 | }
41 |
42 | for(size_t i = 0; i < test_data.size(); ++i) {
43 | iLRMA.update(test_data[i]);
44 | std::cout
45 | << "update " << test_data[i]
46 | << " get " << iLRMA.get()
47 | << std::endl;
48 | }
49 |
50 | std::system("pause");
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/code_blocks/check-rshillma/check-rshillma.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/code_blocks/check-rshillma/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
8 |
9 | xtechnical_indicators::RSHILLMA, xtechnical_indicators::SMA> iRSHILLMA(5, 10, 100, 1.5);
10 |
11 | for(size_t j = 0; j < 100; ++j)
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | iRSHILLMA.update(test_data[i]);
14 | }
15 |
16 | for(size_t i = 0; i < test_data.size(); ++i) {
17 | iRSHILLMA.update(test_data[i]);
18 | std::cout
19 | << "update " << test_data[i]
20 | << " get " << iRSHILLMA.get()
21 | << std::endl;
22 | }
23 |
24 | /* проверяем методы тест */
25 | std::cout << "test(20)" << std::endl;
26 | iRSHILLMA.test(20);
27 | std::cout << "get " << iRSHILLMA.get() << std::endl;
28 |
29 |
30 | std::cout << "test(21)" << std::endl;
31 | iRSHILLMA.test(21);
32 | std::cout << "get " << iRSHILLMA.get() << std::endl;
33 |
34 | std::cout << "test(10)" << std::endl;
35 | iRSHILLMA.test(10);
36 | std::cout << "get " << iRSHILLMA.get() << std::endl;
37 |
38 | for(size_t i = test_data.size() - 1; i > 0; --i) {
39 | iRSHILLMA.update(test_data[i]);
40 | std::cout
41 | << "update " << test_data[i]
42 | << " get " << iRSHILLMA.get()
43 | << std::endl;
44 | }
45 |
46 | for(size_t i = 0; i < test_data.size(); ++i) {
47 | iRSHILLMA.update(test_data[i]);
48 | std::cout
49 | << "update " << test_data[i]
50 | << " get " << iRSHILLMA.get()
51 | << std::endl;
52 | }
53 |
54 | std::system("pause");
55 | return 0;
56 | }
57 |
--------------------------------------------------------------------------------
/code_blocks/check-td/check-td.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/code_blocks/check-td/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include "../../include/backtest/xtechnical_winrate_statistics.hpp"
4 | #include
5 |
6 | int main() {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
9 |
10 | const size_t period = 2;
11 | xtechnical::TrendDirectionForceIndex> trend(period);
12 |
13 | for(size_t i = 0; i < test_data.size(); ++i) {
14 | trend.update(test_data[i]);
15 | std::cout
16 | << "update " << test_data[i]
17 | << " get " << trend.get()
18 | << std::endl;
19 | }
20 |
21 | /* проверяем методы тест */
22 | std::cout << "test(20)" << std::endl;
23 | trend.test(20);
24 | std::cout << "get " << trend.get() << std::endl;
25 |
26 |
27 | std::cout << "test(21)" << std::endl;
28 | trend.test(21);
29 | std::cout << "get " << trend.get() << std::endl;
30 |
31 | std::cout << "test(10)" << std::endl;
32 | trend.test(10);
33 | std::cout << "get " << trend.get() << std::endl;
34 |
35 | for(size_t i = test_data.size() - 1; i > 0; --i) {
36 | trend.update(test_data[i]);
37 | std::cout
38 | << "update " << test_data[i]
39 | << " get " << trend.get()
40 | << std::endl;
41 | }
42 |
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | trend.update(test_data[i]);
45 | std::cout
46 | << "update " << test_data[i]
47 | << " get " << trend.get()
48 | << std::endl;
49 | }
50 |
51 | std::system("pause");
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/code_blocks/check_bb/check_bb.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/code_blocks/check_bb/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 | #include "xtechnical_normalization.hpp"
5 |
6 | using namespace std;
7 |
8 | int main() {
9 | cout << "Hello world!" << endl;
10 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
11 | xtechnical_indicators::BollingerBands> bb(3,2,0);
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | bb.update(test_data[i]);
14 | std::cout
15 | << "update " << test_data[i]
16 | << " tl " << bb.get_tl()
17 | << " ml " << bb.get_ml()
18 | << " bl " << bb.get_bl()
19 | << std::endl;
20 | }
21 | for(size_t i = 0; i < test_data.size(); ++i) {
22 | bb.test(test_data[i]);
23 | std::cout
24 | << "test " << test_data[i]
25 | << " tl " << bb.get_tl()
26 | << " ml " << bb.get_ml()
27 | << " bl " << bb.get_bl()
28 | << std::endl;
29 | }
30 | for(size_t i = 0; i < test_data.size(); ++i) {
31 | bb.update(test_data[i]);
32 | std::cout
33 | << "update " << test_data[i]
34 | << " tl " << bb.get_tl()
35 | << " ml " << bb.get_ml()
36 | << " bl " << bb.get_bl()
37 | << std::endl;
38 | }
39 | bb.clear();
40 | for(size_t i = 0; i < test_data.size(); ++i) {
41 | bb.update(test_data[i]);
42 | std::cout
43 | << "update " << test_data[i]
44 | << " tl " << bb.get_tl()
45 | << " ml " << bb.get_ml()
46 | << " bl " << bb.get_bl()
47 | << std::endl;
48 | }
49 | return 0;
50 | }
51 |
--------------------------------------------------------------------------------
/code_blocks/check_crsi/check_crsi.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/code_blocks/check_crsi/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,4,8,5,6,7,8,16,10,12,14,16,14,15,16,17,18,19};
10 | xtechnical::CRSI> crsi(3,5,10);
11 | std::cout << "-0-" << std::endl;
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | crsi.update(test_data[i]);
14 | std::cout
15 | << "i " << test_data[i]
16 | << " crsi " << crsi.get()
17 | << std::endl;
18 | }
19 | std::cout << "-1-" << std::endl;
20 | for(size_t i = 0; i < test_data.size(); ++i) {
21 | crsi.test(test_data[i]);
22 | std::cout
23 | << "i " << test_data[i]
24 | << " crsi " << crsi.get()
25 | << std::endl;
26 | }
27 | std::cout << "-2-" << std::endl;
28 | for(size_t i = 0; i < test_data.size(); ++i) {
29 | crsi.update(test_data[i]);
30 | std::cout
31 | << "i " << test_data[i]
32 | << " crsi " << crsi.get()
33 | << std::endl;
34 | }
35 | std::cout << "-3-" << std::endl;
36 | crsi.clear();
37 | for(size_t i = 0; i < test_data.size(); ++i) {
38 | crsi.update(test_data[i]);
39 | std::cout
40 | << "i " << test_data[i]
41 | << " crsi " << crsi.get()
42 | << std::endl;
43 | }
44 | return 0;
45 | }
46 |
--------------------------------------------------------------------------------
/code_blocks/check_delay_line/check_delay_line.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_delay_line/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
10 | xtechnical_indicators::DelayLine delay_line(1);
11 | for(size_t i = 0; i < test_data.size(); ++i) {
12 | delay_line.update(test_data[i]);
13 | std::cout
14 | << "date " << test_data[i]
15 | << " get " << delay_line.get()
16 | << std::endl;
17 | }
18 | for(size_t i = 0; i < test_data.size(); ++i) {
19 | delay_line.test(test_data[i]);
20 | std::cout
21 | << "test date " << test_data[i]
22 | << " get test " << delay_line.get()
23 | << std::endl;
24 | }
25 | delay_line.clear();
26 | for(size_t i = 0; i < test_data.size(); ++i) {
27 | delay_line.update(test_data[i]);
28 | std::cout
29 | << "date " << test_data[i]
30 | << " get " << delay_line.get()
31 | << std::endl;
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/code_blocks/check_fft/check_fft.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/code_blocks/check_fft/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 |
4 | using namespace std;
5 |
6 | int main() {
7 | cout << "Hello world!" << endl;
8 | xtechnical_indicators::FreqHist
9 | iFreqHist(100, xtechnical_dft::RECTANGULAR_WINDOW);
10 | const double MATH_PI = 3.14159265358979323846264338327950288;
11 | for(size_t i = 0; i < 1000; ++i) {
12 | double temp = std::cos(3 * MATH_PI * 2 * (double)i / 100.0);
13 |
14 | std::vector amplitude;
15 | std::vector frequencies;
16 | iFreqHist.update(temp, amplitude, frequencies, 100);
17 |
18 | std::cout << "step: " << i << " temp " << temp << std::endl;
19 | for(size_t i = 0; i < frequencies.size(); ++i) {
20 | std::cout << "freq " << frequencies[i] << " " << amplitude[i] << std::endl;
21 | }
22 | std::cout << std::endl << std::endl;
23 | }
24 |
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/code_blocks/check_indicators/check_indicators.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/code_blocks/check_indicators/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 |
4 | using namespace std;
5 |
6 | int main() {
7 | cout << "Hello world!" << endl;
8 | xtechnical_indicators::MW iMW(30);
9 | xtechnical_indicators::MMA iMMA(5);
10 | xtechnical_indicators::SMA iSMA(5);
11 | xtechnical_indicators::AMA iAMA(10);
12 | xtechnical_indicators::NoLagMa iNoLagMa(10);
13 | xtechnical_indicators::RoC iRoC(3);
14 | xtechnical_indicators::VWMA iVWMA(20);
15 |
16 |
17 | for(int i = 1; i <= 50; ++i) {
18 | //int temp = -(i*2);//i % 4;
19 | int temp = i % 4;
20 | iMW.update(temp);
21 |
22 | double std_dev_value = 0;
23 | int err_std_dev = iMW.get_std_dev(std_dev_value, 10, 0);
24 | if(err_std_dev == 0) {
25 | double mean_value = 0;
26 | iMW.get_average(mean_value, 4, 0);
27 | double angle_value = 0;
28 | iMW.compare_data(
29 | angle_value,
30 | xtechnical_common::CALCULATE_ANGLE,
31 | true,
32 | mean_value - 2*std_dev_value,
33 | mean_value + 2*std_dev_value,
34 | 10,
35 | 0);
36 | std::cout << "ANGLE " << angle_value << std::endl;
37 | }
38 |
39 | double mma_out = 0.0;
40 | iMMA.update(temp, mma_out);
41 |
42 | double ama_out = 0.0;
43 | iAMA.update(temp, ama_out);
44 |
45 | double sma_out = 0.0;
46 | iSMA.update(temp, sma_out);
47 |
48 | double roc_out = 0.0;
49 | iRoC.update(temp, roc_out);
50 |
51 | double vwma_out = 0.0;
52 | iVWMA.update(temp,i, vwma_out);
53 |
54 | std::vector rsi;
55 | std::vector sma;
56 | std::vector std_dev;
57 | iMW.get_rsi_array(rsi, 3, 15, 3);
58 | iMW.get_average_and_std_dev_array(sma, std_dev, 10, 22, 3);
59 |
60 | std::cout << "step: " << i << " temp " << temp << " is init: " << iMW.is_init() << std::endl;
61 | for(size_t i = 0; i < sma.size(); ++i) {
62 | std::cout << "rsi: " << rsi[i] << " sma: " << sma[i] << " std_dev: " << std_dev[i] << std::endl;
63 | }
64 | std::cout << "MMA: " << mma_out << " SMA " << sma_out << " AMA " << ama_out << std::endl;
65 | std::cout << "RoC: " << roc_out << std::endl;
66 | std::cout << "VWMA: " << vwma_out << std::endl;
67 | }
68 |
69 | double rsi_value = 0;
70 | iMW.get_rsi(rsi_value, 15);
71 | std::cout << "rsi_value: " << rsi_value << std::endl;
72 | double aver_value = 0;
73 | iMW.get_average(aver_value, 22);
74 | std::cout << "aver_value: " << aver_value << std::endl;
75 | double std_dev_value = 0;
76 | iMW.get_std_dev(std_dev_value, 22);
77 | std::cout << "std_dev: " << std_dev_value << std::endl;
78 |
79 | xtechnical_indicators::VCMA iVCMA;
80 | std::cout << iVCMA.update(2,1) << std::endl;
81 | std::cout << iVCMA.update(3,0.5) << std::endl;
82 | std::cout << iVCMA.update(1,0.5) << std::endl;
83 | return 0;
84 | }
85 |
--------------------------------------------------------------------------------
/code_blocks/check_maz/check_maz.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/code_blocks/check_maz/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 |
10 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
11 | xtechnical_indicators::MAZ iMAZ(5, 20);
12 |
13 | for(size_t i = 0; i < test_data.size(); ++i) {
14 | iMAZ.update(test_data[i]);
15 | }
16 |
17 | for(size_t i = 0; i < test_data.size(); ++i) {
18 | iMAZ.update(test_data[i]);
19 | std::cout
20 | << "date " << test_data[i]
21 | << " get " << iMAZ.get()
22 | << std::endl;
23 | }
24 |
25 | for(size_t i = 0; i < test_data.size(); ++i) {
26 | iMAZ.test(test_data[i]);
27 | std::cout
28 | << "date " << test_data[i]
29 | << " get test " << iMAZ.get()
30 | << std::endl;
31 | }
32 | for(size_t i = 0; i < test_data.size(); ++i) {
33 | iMAZ.update(test_data[i]);
34 | std::cout
35 | << "date " << test_data[i]
36 | << " get " << iMAZ.get()
37 | << std::endl;
38 | }
39 | iMAZ.clear();
40 | for(size_t i = 0; i < test_data.size(); ++i) {
41 | iMAZ.update(test_data[i]);
42 | std::cout
43 | << "date " << test_data[i]
44 | << " get " << iMAZ.get()
45 | << std::endl;
46 | }
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/code_blocks/check_min_max/check_min_max.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_min_max/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
10 | xtechnical_indicators::MinMax min_max(4, 1);
11 | std::cout << "---" << std::endl;
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | min_max.update(test_data[i]);
14 | std::cout
15 | << "date " << test_data[i]
16 | << " min " << min_max.get_min()
17 | << " max " << min_max.get_max()
18 | << std::endl;
19 | }
20 | for(size_t i = 0; i < test_data.size(); ++i) {
21 | min_max.test(test_data[i]);
22 | std::cout
23 | << "date test " << test_data[i]
24 | << " min " << min_max.get_min()
25 | << " max " << min_max.get_max()
26 | << std::endl;
27 | }
28 | for(size_t i = 0; i < test_data.size(); ++i) {
29 | min_max.update(test_data[i]);
30 | std::cout
31 | << "date " << test_data[i]
32 | << " min " << min_max.get_min()
33 | << " max " << min_max.get_max()
34 | << std::endl;
35 | }
36 | min_max.clear();
37 | for(size_t i = 0; i < test_data.size(); ++i) {
38 | min_max.update(test_data[i]);
39 | std::cout
40 | << "date " << test_data[i]
41 | << " min " << min_max.get_min()
42 | << " max " << min_max.get_max()
43 | << std::endl;
44 | }
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/code_blocks/check_min_max_difference/check_min_max_difference.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_min_max_difference/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,4,8,5,6,7,8,16,10,12,14,16,14,15,16,17,18,19};
10 | xtechnical_indicators::MinMaxDiff min_max(4, 1);
11 | std::cout << "---" << std::endl;
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | min_max.update(test_data[i]);
14 | std::cout
15 | << "date " << test_data[i]
16 | << " get " << min_max.get()
17 | << " min " << min_max.get_min()
18 | << " max " << min_max.get_max()
19 | << std::endl;
20 | }
21 | for(size_t i = 0; i < test_data.size(); ++i) {
22 | min_max.test(test_data[i]);
23 | std::cout
24 | << "date test " << test_data[i]
25 | << " get " << min_max.get()
26 | << " min " << min_max.get_min()
27 | << " max " << min_max.get_max()
28 | << std::endl;
29 | }
30 | for(size_t i = 0; i < test_data.size(); ++i) {
31 | min_max.update(test_data[i]);
32 | std::cout
33 | << "date " << test_data[i]
34 | << " get " << min_max.get()
35 | << " min " << min_max.get_min()
36 | << " max " << min_max.get_max()
37 | << std::endl;
38 | }
39 | min_max.clear();
40 | for(size_t i = 0; i < test_data.size(); ++i) {
41 | min_max.update(test_data[i]);
42 | std::cout
43 | << "date " << test_data[i]
44 | << " get " << min_max.get()
45 | << " min " << min_max.get_min()
46 | << " max " << min_max.get_max()
47 | << std::endl;
48 | }
49 | return 0;
50 | }
51 |
--------------------------------------------------------------------------------
/code_blocks/check_pri/check_pri.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_pri/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,4,8,5,6,7,8,16,10,12,14,16,14,15,16,17,18,19};
10 | xtechnical_indicators::PRI pri(4);
11 | std::cout << "---" << std::endl;
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | pri.update(test_data[i]);
14 | std::cout
15 | << "date " << test_data[i]
16 | << " get " << pri.get()
17 | << std::endl;
18 | }
19 | for(size_t i = 0; i < test_data.size(); ++i) {
20 | pri.test(test_data[i]);
21 | std::cout
22 | << "date test " << test_data[i]
23 | << " get " << pri.get()
24 | << std::endl;
25 | }
26 | for(size_t i = 0; i < test_data.size(); ++i) {
27 | pri.update(test_data[i]);
28 | std::cout
29 | << "date " << test_data[i]
30 | << " get " << pri.get()
31 | << std::endl;
32 | }
33 | pri.clear();
34 | for(size_t i = 0; i < test_data.size(); ++i) {
35 | pri.update(test_data[i]);
36 | std::cout
37 | << "date " << test_data[i]
38 | << " get " << pri.get()
39 | << std::endl;
40 | }
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/code_blocks/check_sma/check_sma.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_sma/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
10 | xtechnical_indicators::SMA sma(4);
11 | for(size_t i = 0; i < test_data.size(); ++i) {
12 | sma.update(test_data[i]);
13 | std::cout
14 | << "date " << test_data[i]
15 | << " get " << sma.get()
16 | << std::endl;
17 | }
18 | for(size_t i = 0; i < test_data.size(); ++i) {
19 | sma.test(test_data[i]);
20 | std::cout
21 | << "date test " << test_data[i]
22 | << " get test " << sma.get()
23 | << std::endl;
24 | }
25 | for(size_t i = 0; i < test_data.size(); ++i) {
26 | sma.update(test_data[i]);
27 | std::cout
28 | << "date " << test_data[i]
29 | << " get " << sma.get()
30 | << std::endl;
31 | }
32 | sma.clear();
33 | for(size_t i = 0; i < test_data.size(); ++i) {
34 | sma.update(test_data[i]);
35 | std::cout
36 | << "date " << test_data[i]
37 | << " get " << sma.get()
38 | << std::endl;
39 | }
40 | return 0;
41 | }
42 |
--------------------------------------------------------------------------------
/code_blocks/check_stochastics/check_stochastics.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_stochastics/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,4,8,5,6,7,8,16,10,12,14,16,14,15,16,17,18,19};
10 | xtechnical_indicators::Stochastics> stochastics(10,3,5);
11 | std::cout << "-0-" << std::endl;
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | stochastics.update(test_data[i]);
14 | std::cout
15 | << "i " << test_data[i]
16 | << " k " << stochastics.get()
17 | << " %k " << stochastics.get_k()
18 | << " %d " << stochastics.get_d()
19 | << std::endl;
20 | }
21 | std::cout << "-1-" << std::endl;
22 | for(size_t i = 0; i < test_data.size(); ++i) {
23 | stochastics.test(test_data[i]);
24 | std::cout
25 | << "i " << test_data[i]
26 | << " k " << stochastics.get()
27 | << " %k " << stochastics.get_k()
28 | << " %d " << stochastics.get_d()
29 | << std::endl;
30 | }
31 | std::cout << "-2-" << std::endl;
32 | for(size_t i = 0; i < test_data.size(); ++i) {
33 | stochastics.update(test_data[i]);
34 | std::cout
35 | << "i " << test_data[i]
36 | << " k " << stochastics.get()
37 | << " %k " << stochastics.get_k()
38 | << " %d " << stochastics.get_d()
39 | << std::endl;
40 | }
41 | std::cout << "-3-" << std::endl;
42 | stochastics.clear();
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | stochastics.update(test_data[i]);
45 | std::cout
46 | << "i " << test_data[i]
47 | << " k " << stochastics.get()
48 | << " %k " << stochastics.get_k()
49 | << " %d " << stochastics.get_d()
50 | << std::endl;
51 | }
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/code_blocks/check_sum/check_sum.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/code_blocks/check_sum/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 |
5 | using namespace std;
6 |
7 | int main() {
8 | cout << "Hello world!" << endl;
9 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
10 | xtechnical_indicators::SUM sum(4);
11 | for(size_t i = 0; i < test_data.size(); ++i) {
12 | sum.update(test_data[i]);
13 | std::cout
14 | << "date " << test_data[i]
15 | << " get " << sum.get()
16 | << std::endl;
17 | }
18 | for(size_t i = 0; i < test_data.size(); ++i) {
19 | sum.test(test_data[i]);
20 | std::cout
21 | << "date test " << test_data[i]
22 | << " get test " << sum.get()
23 | << std::endl;
24 | }
25 | for(size_t i = 0; i < test_data.size(); ++i) {
26 | sum.update(test_data[i]);
27 | std::cout
28 | << "date " << test_data[i]
29 | << " get " << sum.get()
30 | << std::endl;
31 | }
32 | sum.clear();
33 | for(size_t i = 0; i < test_data.size(); ++i) {
34 | sum.update(test_data[i]);
35 | std::cout
36 | << "date " << test_data[i]
37 | << " get " << sum.get()
38 | << std::endl;
39 | }
40 | return 0;
41 | }
42 |
--------------------------------------------------------------------------------
/code_blocks/check_zscore/check_zscore.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/code_blocks/check_zscore/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "xtechnical_indicators.hpp"
4 | #include "xtechnical_normalization.hpp"
5 |
6 | using namespace std;
7 |
8 | int main() {
9 | cout << "Hello world!" << endl;
10 |
11 | std::array zscore_test_data = {1,2,3,4,5};
12 | std::array zscore_out;
13 | xtechnical::normalization::calculate_zscore(zscore_test_data, zscore_out, 1, 1000);
14 | for(size_t i = 0; i < zscore_out.size(); ++i) {
15 | std::cout
16 | << "zscore " << zscore_out[i]
17 | << std::endl;
18 | }
19 |
20 | std::system("pause");
21 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
22 | const size_t period = 5;
23 | xtechnical::Zscore zscore(period);
24 | for(size_t i = 0; i < test_data.size(); ++i) {
25 | zscore.update(test_data[i]);
26 | std::cout
27 | << "date " << test_data[i]
28 | << " get " << zscore.get()
29 | << std::endl;
30 | }
31 | for(size_t i = 0; i < test_data.size(); ++i) {
32 | zscore.test(test_data[i]);
33 | std::cout
34 | << "date " << test_data[i]
35 | << " get test " << zscore.get()
36 | << std::endl;
37 | }
38 | for(size_t i = 0; i < test_data.size(); ++i) {
39 | zscore.update(test_data[i]);
40 | std::cout
41 | << "date " << test_data[i]
42 | << " get " << zscore.get()
43 | << std::endl;
44 | }
45 | zscore.clear();
46 | for(size_t i = 0; i < test_data.size(); ++i) {
47 | zscore.update(test_data[i]);
48 | std::cout
49 | << "date " << test_data[i]
50 | << " get " << zscore.get()
51 | << std::endl;
52 | }
53 |
54 | zscore.clear();
55 | {
56 | double _m = 0, _sum = 0, _std = 0;
57 | for(size_t i = 0; i < period; ++i) {
58 | _m += test_data[i];
59 | zscore.update(test_data[i]);
60 | std::cout
61 | << "date " << test_data[i]
62 | << " get " << zscore.get()
63 | << std::endl;
64 | }
65 | _m /= (double)period;
66 |
67 | for(size_t i = 0; i < period; ++i) {
68 | const double temp = test_data[i] - _m;
69 | _sum += temp * temp;
70 | }
71 |
72 | _sum /= (double)(period - 1);
73 | _std = std::sqrt(_sum);
74 |
75 | }
76 | return 0;
77 | }
78 |
--------------------------------------------------------------------------------
/code_blocks/checking_circular_buffer/checking_circular_buffer.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/code_blocks/checking_circular_buffer/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_circular_buffer.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
8 |
9 | /* создадим кольцевой буфер размером 8 элементов */
10 | const size_t buffer_size = 8;
11 | xtechnical::circular_buffer circular_buffer(buffer_size);
12 |
13 | /* заполняем буфер данными и выводим на экран */
14 | for(size_t i = 0; i < test_data.size(); ++i) {
15 | circular_buffer.push_back(test_data[i]);
16 | std::cout
17 | << "push " << test_data[i]
18 | << " front " << circular_buffer.front()
19 | << " back " << circular_buffer.back()
20 | << " [0] " << circular_buffer[0]
21 | << " [" << (buffer_size - 1) << "] " << circular_buffer[buffer_size - 1]
22 | << " full " << circular_buffer.full()
23 | << std::endl;
24 | }
25 |
26 | /* выводим на экран данные буфера */
27 | for(size_t i = 0; i < buffer_size; ++i) {
28 | std::cout
29 | << " [" << i << "] " << circular_buffer[i]
30 | << std::endl;
31 | }
32 |
33 | /* флаги буфера */
34 | std::cout << "empty " << circular_buffer.empty() << std::endl;
35 | std::cout << "full " << circular_buffer.full() << std::endl;
36 |
37 | /* первый и последний эхлемент буфера */
38 | std::cout << "front " << circular_buffer.front() << std::endl;
39 | std::cout << "back " << circular_buffer.back() << std::endl;
40 |
41 | /* проверяем методы тест */
42 | std::cout << "test(20)" << std::endl;
43 | circular_buffer.test(20);
44 | std::cout << "back " << circular_buffer.back() << std::endl;
45 | std::cout << "test(21)" << std::endl;
46 | circular_buffer.test(21);
47 | std::cout << "back " << circular_buffer.back() << std::endl;
48 | std::cout << "update(20)" << std::endl;
49 | circular_buffer.update(20);
50 | std::cout << "back " << circular_buffer.back() << std::endl;
51 |
52 | /* выводим на экран данные буфера */
53 | for(size_t i = 0; i < buffer_size; ++i) {
54 | std::cout
55 | << " [" << i << "] " << circular_buffer[i]
56 | << std::endl;
57 | }
58 |
59 | /* получаем значения среднего элемента, суммы и среднего значения буфера */
60 | std::cout << "middle " << circular_buffer.middle() << std::endl;
61 | std::cout << "sum " << circular_buffer.sum() << std::endl;
62 | std::cout << "mean " << circular_buffer.mean() << std::endl;
63 |
64 | /* очищаем и повторно заполняем буфер данными и выводим на экран */
65 | circular_buffer.clear();
66 | for(size_t i = 0; i < test_data.size(); ++i) {
67 | circular_buffer.push_back(test_data[i]);
68 | std::cout
69 | << "push " << test_data[i]
70 | << " front " << circular_buffer.front()
71 | << " back " << circular_buffer.back()
72 | << " [0] " << circular_buffer[0]
73 | << " [" << (buffer_size - 1) << "] " << circular_buffer[buffer_size - 1]
74 | << " full " << circular_buffer.full()
75 | << std::endl;
76 | }
77 |
78 | std::vector temp = circular_buffer.to_vector();
79 | for(size_t i = 0; i < temp.size(); ++i) {
80 | std::cout
81 | << "temp[" << i << "] " << temp[i]
82 | << std::endl;
83 | }
84 |
85 | for(size_t i = 0; i < test_data.size(); ++i) {
86 | std::cout << "***" << std::endl;
87 | circular_buffer.push_back(test_data[i]);
88 | std::vector temp = circular_buffer.to_vector();
89 | for(size_t i = 0; i < temp.size(); ++i) {
90 | std::cout
91 | << "temp[" << i << "] " << temp[i]
92 | << std::endl;
93 | }
94 | std::system("pause");
95 | }
96 | for(size_t i = 0; i < test_data.size(); ++i) {
97 | std::cout << "***" << std::endl;
98 | circular_buffer.push_back(test_data[i]);
99 | std::vector temp = circular_buffer.to_vector();
100 | for(size_t i = 0; i < temp.size(); ++i) {
101 | std::cout
102 | << "temp[" << i << "] " << temp[i]
103 | << std::endl;
104 | }
105 | std::system("pause");
106 | }
107 |
108 | return 0;
109 | }
110 |
--------------------------------------------------------------------------------
/code_blocks/checking_delay_measurement/checking_delay_measurement.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/code_blocks/checking_least_square_method/checking_least_square_method.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/code_blocks/checking_least_square_method/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_regression_analysis.hpp"
3 | #include
4 | #include
5 |
6 | int main() {
7 | std::cout << "Hello world!" << std::endl;
8 |
9 | double coeff[3];
10 | double test_data[6][2] = {
11 | {1,2},
12 | {2,3},
13 | {3,4},
14 | {4,5},
15 | {5,6},
16 | {6,7},
17 | };
18 |
19 | std::array test_data2 = {
20 | 1,2,3,4,5,6,
21 | 2,3,4,5,6,7
22 | };
23 |
24 | std::vector> test_data3;
25 | test_data3.resize(6);
26 | test_data3[0][0] = 1;
27 | test_data3[0][1] = 2;
28 | test_data3[1][0] = 2;
29 | test_data3[1][1] = 3;
30 | test_data3[2][0] = 3;
31 | test_data3[2][1] = 4;
32 | test_data3[3][0] = 4;
33 | test_data3[3][1] = 5;
34 | test_data3[4][0] = 5;
35 | test_data3[4][1] = 6;
36 | test_data3[5][0] = 6;
37 | test_data3[5][1] = 7;
38 |
39 | xtechnical_regression_analysis::calc_least_squares_method(coeff, test_data, 6, xtechnical_regression_analysis::LSM_PARABOLA);
40 | double in_data = 7;
41 | double out_data = xtechnical_regression_analysis::calc_line(coeff, in_data, xtechnical_regression_analysis::LSM_PARABOLA);
42 | std::cout << "out_data " << out_data << std::endl;
43 |
44 | xtechnical_regression_analysis::calc_least_squares_method(coeff, test_data2, 6, xtechnical_regression_analysis::LSM_PARABOLA);
45 | out_data = xtechnical_regression_analysis::calc_line(coeff, in_data, xtechnical_regression_analysis::LSM_PARABOLA);
46 | std::cout << "out_data " << out_data << std::endl;
47 |
48 | xtechnical_regression_analysis::calc_least_squares_method(coeff, test_data3, 6, xtechnical_regression_analysis::LSM_PARABOLA);
49 | out_data = xtechnical_regression_analysis::calc_line(coeff, in_data, xtechnical_regression_analysis::LSM_PARABOLA);
50 | std::cout << "out_data " << out_data << std::endl;
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/code_blocks/checking_normalization/checking_normalization.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/code_blocks/checking_normalization/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {1,2,3,1,0.5,6,6};
8 | std::array out_data;
9 | xtechnical_normalization::calculate_min_max(test_data, out_data, xtechnical_common::MINMAX_UNSIGNED);
10 | std::cout << "calculate_min_max (MINMAX_UNSIGNED):" << std::endl;
11 | for(size_t i = 0; i < out_data.size(); ++i) {
12 | std::cout << out_data[i] << std::endl;
13 | }
14 |
15 | xtechnical_normalization::calculate_min_max(test_data, out_data, xtechnical_common::MINMAX_SIGNED);
16 | std::cout << "calculate_min_max (MINMAX_SIGNED):" << std::endl;
17 | for(size_t i = 0; i < out_data.size(); ++i) {
18 | std::cout << out_data[i] << std::endl;
19 | }
20 |
21 | xtechnical_normalization::calculate_zscore(test_data, out_data);
22 | std::cout << "calculate_zscore:" << std::endl;
23 | for(size_t i = 0; i < out_data.size(); ++i) {
24 | std::cout << out_data[i] << std::endl;
25 | }
26 |
27 | std::array out_data_2;
28 | xtechnical_normalization::calculate_difference(test_data, out_data_2);
29 | std::cout << "calculate_difference:" << std::endl;
30 | for(size_t i = 0; i < out_data_2.size(); ++i) {
31 | std::cout << out_data_2[i] << std::endl;
32 | }
33 |
34 |
35 | xtechnical_normalization::normalize_amplitudes(test_data, out_data, (double)1.0);
36 | std::cout << "normalize_amplitudes:" << std::endl;
37 | for(size_t i = 0; i < out_data.size(); ++i) {
38 | std::cout << out_data[i] << std::endl;
39 | }
40 |
41 | xtechnical_normalization::calculate_log(test_data, out_data);
42 | std::cout << "calculate_log:" << std::endl;
43 | for(size_t i = 0; i < out_data.size(); ++i) {
44 | std::cout << out_data[i] << std::endl;
45 | }
46 |
47 |
48 | xtechnical_normalization::calc_automatic_gain_control>(test_data, out_data, 3);
49 | std::cout << "automatic_gain_control:" << std::endl;
50 | for(size_t i = 0; i < out_data.size(); ++i) {
51 | std::cout << out_data[i] << std::endl;
52 | }
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/code_blocks/checking_statistical_indicators/checking_statistical_indicators.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/code_blocks/checking_statistical_indicators/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {1,2,3,1,0.5,6,6};
8 |
9 | double temp = 0;
10 | xtechnical_indicators::calculate_sma(test_data, temp, 4, 1);
11 | std::cout << "calculate_sma:" << std::endl;
12 | std::cout << temp << std::endl;
13 | xtechnical_indicators::calculate_std_dev(test_data, temp, 4, 1);
14 | std::cout << "calculate_std_dev:" << std::endl;
15 | std::cout << temp << std::endl;
16 | double temp2 = 0;
17 | xtechnical_indicators::calculate_std_dev_and_mean(test_data, temp, temp2, 4, 1);
18 | std::cout << "calculate_std_dev_and_mean:" << std::endl;
19 | std::cout << temp << std::endl;
20 | std::cout << temp2 << std::endl;
21 |
22 | std::array test_data2 = {100,101,99,97,110,105,99};
23 | std::array out_tl, out_ml, out_bl;
24 | xtechnical_indicators::calc_ring_bollinger(test_data2, out_tl, out_ml, out_bl, 4, 2);
25 | std::cout << "calc_ring_bollinger:" << std::endl;
26 | for(size_t i = 0; i < test_data2.size(); ++i) {
27 | std::cout << out_tl[i] << " " << test_data2[i] << " " << out_bl[i] << std::endl;
28 | }
29 |
30 | std::array test_data3 = {100,101,99,97,110,105,99};
31 | std::array out_rsi;
32 | xtechnical_indicators::calc_ring_rsi(test_data2, out_rsi, 4);
33 | std::cout << "calc_ring_rsi:" << std::endl;
34 | for(size_t i = 0; i < test_data3.size(); ++i) {
35 | std::cout << out_rsi[i] << " " << test_data3[i] << std::endl;
36 | }
37 |
38 | return 0;
39 | }
40 |
--------------------------------------------------------------------------------
/code_blocks/checking_statistics/checking_statistics.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/code_blocks/checking_statistics/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_statistics.hpp"
3 | #include
4 | #include
5 |
6 | int main() {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {3,8,10,17,24,27};
9 |
10 | double median_absolute_deviation_value = xtechnical_statistics::calc_median_absolute_deviation(test_data);
11 | std::cout << "median absolute deviation value: " << median_absolute_deviation_value << std::endl;
12 |
13 | double median_value = xtechnical_statistics::calc_median(test_data);
14 | std::cout << "median value: " << median_value << std::endl;
15 |
16 | double harmonic_mean = xtechnical_statistics::calc_harmonic_mean(test_data);
17 | std::cout << "harmonic mean: " << harmonic_mean << std::endl;
18 |
19 | double mean_value = xtechnical_statistics::calc_mean_value(test_data);
20 | std::cout << "mean value: " << mean_value << std::endl;
21 |
22 | double skewness = xtechnical_statistics::calc_skewness(test_data);
23 | std::cout << "skewness: " << skewness << std::endl;
24 |
25 | double snr = xtechnical_statistics::calc_signal_to_noise_ratio(test_data);
26 | std::cout << "snr: " << snr << std::endl;
27 |
28 |
29 | std::array test_data2 = {1.1,1.1,1.1,1.1,1.1,1.1};
30 | double geometric_mean = xtechnical_statistics::calc_geometric_mean(test_data2);
31 | std::cout << "geometric mean: " << geometric_mean << std::endl;
32 |
33 | std::array test_out;
34 | std::vector test_data3 = {1.1,1.1,1.1,1.1,1.1,1.1};
35 | test_out[0] = xtechnical_statistics::calc_median(test_data3);
36 | std::cout << "median: " << test_out[0] << std::endl;
37 |
38 |
39 | std::vector test_data4 = {1,1,2,2,3,3,4,5,6,7};
40 | double excess = xtechnical_statistics::calc_excess(test_data4);
41 | std::cout << "excess: " << excess << std::endl;
42 |
43 | std::vector test_data5 = {1,1,1,0,0,1};
44 | double standard_error = xtechnical_statistics::calc_standard_error(test_data5);
45 | std::cout << "standard_error: " << standard_error << std::endl;
46 |
47 | double integral_laplace = xtechnical_statistics::calc_integral_laplace(0.01, 0.00001);
48 | std::cout << "integral_laplace: " << integral_laplace << std::endl;
49 |
50 | double integral_laplace2 = xtechnical_statistics::calc_integral_laplace(1.51, 0.01);
51 | std::cout << "integral_laplace2: " << integral_laplace2 << std::endl;
52 |
53 | double p_bet = xtechnical_statistics::calc_probability_winrate(0.6, 31, 44);
54 | std::cout << "p_bet: " << p_bet << std::endl; // получим ответ 93.6
55 |
56 | p_bet = xtechnical_statistics::calc_probability_winrate(0.56, 5700, 10000);
57 | std::cout << "p_bet: " << p_bet << std::endl;
58 |
59 | p_bet = xtechnical_statistics::calc_probability_winrate(0.54, 5700, 10000);
60 | std::cout << "p_bet: " << p_bet << std::endl;
61 |
62 | p_bet = xtechnical_statistics::calc_probability_winrate(0.57, 1, 1);
63 | std::cout << "p_bet (1): " << p_bet << std::endl;
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/code_blocks/cmp_min_max_witch_streaming_min_max/cmp_min_max_witch_streaming_min_max.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/code_blocks/cmp_min_max_witch_streaming_min_max/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "xtechnical_indicators.hpp"
5 | #include "../../include/xtechnical_streaming_min_max.hpp"
6 |
7 | using namespace std;
8 |
9 | int main() {
10 | cout << "Hello world!" << endl;
11 |
12 | std::vector test_data;
13 | for(size_t i = 0; i < 100; ++i) {
14 | test_data.push_back(i);
15 | }
16 | for(size_t i = 0; i < 30; ++i) {
17 | test_data.push_back(100);
18 | }
19 | for(int i = 100; i >= 0; --i) {
20 | test_data.push_back(i);
21 | }
22 | for(size_t i = 0; i < 30; ++i) {
23 | test_data.push_back(0);
24 | }
25 |
26 | xtechnical_indicators::MinMax min_max(30, 0);
27 | xtechnical_indicators::FastMinMax fast_min_max(30, 0);
28 | xtechnical::StreamingMaximumMinimumFilter streaming_min_max(30);
29 |
30 | std::cout << "-1-" << std::endl;
31 | for(size_t n = 0; n < 1000; ++n)
32 | for(size_t i = 0; i < test_data.size(); ++i) {
33 | min_max.update(test_data[i]);
34 | streaming_min_max.update(test_data[i]);
35 | fast_min_max.update(test_data[i]);
36 | //std::cout << "in " << test_data[i] << " min " << min_max.get_min() << " smin " << streaming_min_max.get_min() << std::endl;
37 | if (!std::isnan(min_max.get_min()) && !std::isnan(streaming_min_max.get_min()) && min_max.get_min() != streaming_min_max.get_min()) {
38 | std::cout << "error! index " << i << " in " << test_data[i] << " min " << min_max.get_min() << " s min " << streaming_min_max.get_min() << std::endl;
39 | return 0;
40 | }
41 | if (!std::isnan(min_max.get_max()) && !std::isnan(streaming_min_max.get_max()) && min_max.get_max() != streaming_min_max.get_max()) {
42 | std::cout << "error! index " << i << " in " << test_data[i] << " max " << min_max.get_min() << " s max " << streaming_min_max.get_max() << std::endl;
43 | return 0;
44 | }
45 | if (!std::isnan(min_max.get_min()) && !std::isnan(fast_min_max.get_min()) && min_max.get_min() != fast_min_max.get_min()) {
46 | std::cout << "error! index " << i << " in " << test_data[i] << " min " << min_max.get_min() << " s min " << fast_min_max.get_min() << std::endl;
47 | return 0;
48 | }
49 | }
50 | std::cout << "ok" << std::endl;
51 |
52 | {
53 | xtechnical_indicators::MinMax min_max(30, 2);
54 | xtechnical_indicators::FastMinMax fast_min_max(30, 2);
55 | std::cout << "-2-" << std::endl;
56 | for(size_t n = 0; n < 1000; ++n)
57 | for(size_t i = 0; i < test_data.size(); ++i) {
58 | min_max.update(test_data[i]);
59 | fast_min_max.update(test_data[i]);
60 | if (!std::isnan(min_max.get_min()) && !std::isnan(fast_min_max.get_min()) && min_max.get_min() != fast_min_max.get_min()) {
61 | std::cout << "error! index " << i << " in " << test_data[i] << " min " << min_max.get_min() << " s min " << fast_min_max.get_min() << std::endl;
62 | return 0;
63 | }
64 | }
65 | std::cout << "ok" << std::endl;
66 | }
67 |
68 | {
69 | xtechnical_indicators::MinMax min_max(60, 0);
70 | auto begin = std::chrono::steady_clock::now();
71 | for(size_t n = 0; n < 100000; ++n)
72 | for(size_t i = 0; i < test_data.size(); ++i) {
73 | min_max.update(test_data[i]);
74 | }
75 | auto end = std::chrono::steady_clock::now();
76 | auto elapsed_ms = std::chrono::duration_cast(end - begin);
77 | std::cout << "min max time: " << elapsed_ms.count() << " ms\n";
78 | }
79 | {
80 | xtechnical::StreamingMaximumMinimumFilter streaming_min_max(60);
81 | auto begin = std::chrono::steady_clock::now();
82 | for(size_t n = 0; n < 100000; ++n)
83 | for(size_t i = 0; i < test_data.size(); ++i) {
84 | streaming_min_max.update(test_data[i]);
85 | }
86 | auto end = std::chrono::steady_clock::now();
87 | auto elapsed_ms = std::chrono::duration_cast(end - begin);
88 | std::cout << "streaming min max time: " << elapsed_ms.count() << " ms\n";
89 | }
90 | {
91 | xtechnical_indicators::FastMinMax min_max(60, 0);
92 | auto begin = std::chrono::steady_clock::now();
93 | for(size_t n = 0; n < 100000; ++n)
94 | for(size_t i = 0; i < test_data.size(); ++i) {
95 | streaming_min_max.update(test_data[i]);
96 | }
97 | auto end = std::chrono::steady_clock::now();
98 | auto elapsed_ms = std::chrono::duration_cast(end - begin);
99 | std::cout << "fast min max time: " << elapsed_ms.count() << " ms\n";
100 | }
101 | return 0;
102 | }
103 |
--------------------------------------------------------------------------------
/code_blocks/test/atr.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
9 |
10 | const size_t period = 2;
11 | xtechnical::ATR> atr(period);
12 |
13 | for(size_t i = 0; i < test_data.size(); ++i) {
14 | atr.update(test_data[i]);
15 | std::cout
16 | << "update " << test_data[i]
17 | << " get " << atr.get()
18 | << std::endl;
19 | }
20 |
21 | /* проверяем методы тест */
22 | std::cout << "test(20)" << std::endl;
23 | atr.test(20);
24 | std::cout << "get " << atr.get() << std::endl;
25 |
26 |
27 | std::cout << "test(21)" << std::endl;
28 | atr.test(21);
29 | std::cout << "get " << atr.get() << std::endl;
30 |
31 | std::cout << "test(10)" << std::endl;
32 | atr.test(10);
33 | std::cout << "get " << atr.get() << std::endl;
34 |
35 | for(size_t i = test_data.size() - 1; i > 0; --i) {
36 | atr.update(test_data[i]);
37 | std::cout
38 | << "update " << test_data[i]
39 | << " get " << atr.get()
40 | << std::endl;
41 | }
42 |
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | atr.update(test_data[i]);
45 | std::cout
46 | << "update " << test_data[i]
47 | << " get " << atr.get()
48 | << std::endl;
49 | }
50 |
51 | std::system("pause");
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/code_blocks/test/body_filter.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 |
9 | {
10 | xtechnical::BodyFilter> body_filter(1);
11 | body_filter.update(2,5,1,3);
12 | std::cout << body_filter.get() << std::endl;
13 | }
14 | {
15 | xtechnical::BodyFilter> body_filter(3);
16 | body_filter.update(2,5,1,3);
17 | body_filter.update(3,5,1,3);
18 | body_filter.update(2,4,2,4);
19 | body_filter.update(2,4,2,4);
20 | std::cout << body_filter.get() << std::endl;
21 | }
22 | std::system("pause");
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/code_blocks/test/cci.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {0,1,2,9,4,5,8,7,8,9,10,11,12,13,14,15,16,17,18,19};
9 |
10 | const size_t period = 4;
11 | xtechnical::CCI> cci(period);
12 |
13 | for(size_t i = 0; i < test_data.size(); ++i) {
14 | cci.update(test_data[i]);
15 | std::cout
16 | << "update " << test_data[i]
17 | << " get " << cci.get()
18 | << std::endl;
19 | }
20 |
21 | /* проверяем методы тест */
22 | std::cout << "test(20)" << std::endl;
23 | cci.test(20);
24 | std::cout << "get " << cci.get() << std::endl;
25 |
26 |
27 | std::cout << "test(21)" << std::endl;
28 | cci.test(21);
29 | std::cout << "get " << cci.get() << std::endl;
30 |
31 | std::cout << "test(10)" << std::endl;
32 | cci.test(10);
33 | std::cout << "get " << cci.get() << std::endl;
34 |
35 | for(size_t i = test_data.size() - 1; i > 0; --i) {
36 | cci.update(test_data[i]);
37 | std::cout
38 | << "update " << test_data[i]
39 | << " get " << cci.get()
40 | << std::endl;
41 | }
42 |
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | cci.update(test_data[i]);
45 | std::cout
46 | << "update " << test_data[i]
47 | << " get " << cci.get()
48 | << std::endl;
49 | }
50 |
51 | std::system("pause");
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/code_blocks/test/cluster_shaper.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include "easy_plot.hpp"
4 | #include
5 | #include
6 | #include
7 |
8 | void print_map(const std::map &distribution) {
9 | for (auto it = distribution.begin(); it != distribution.end(); ++it) {
10 | std::cout << it->first << " " << it->second << std::endl;
11 | }
12 | }
13 |
14 | int main(int argc, char* argv[]) {
15 | ep::init(&argc, argv);
16 | std::cout << "Hello world!" << std::endl;
17 | // 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
18 | xtechnical::ClusterShaper cluster_shaper(60, 0.0001d);
19 | cluster_shaper.on_close_bar = [&](const xtechnical::ClusterShaper::Cluster &cluster) {
20 | auto normalized_cluster = cluster.get_normalized_array();
21 | auto no_normalized_cluster = cluster.get_array();
22 |
23 | if (false) {
24 | std::copy(normalized_cluster.begin(), normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
25 | std::cout << std::endl;
26 | std::copy(no_normalized_cluster.begin(), no_normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
27 | std::cout << std::endl;
28 | print_map(cluster.distribution);
29 | }
30 |
31 | std::cout << "o: " << cluster.open << " c: " << cluster.close << " m: " << cluster.get_center_mass() << std::endl;
32 | const double center = cluster.get_center_mass_norm();
33 | std::cout << "center: " << center << std::endl;
34 | if (center < 0.38) {
35 | std::copy(no_normalized_cluster.begin(), no_normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
36 | std::cout << std::endl;
37 | ep::WindowSpec wstyle;
38 | ep::plot("center", wstyle, (int)1,
39 | normalized_cluster, ep::LineSpec(0,1,0));
40 | std::system("pause");
41 | }
42 |
43 | //auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(normalized_cluster.size(), normalized_cluster.size()/2);
44 |
45 | auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(normalized_cluster.size(), normalized_cluster.size() * 0.0);
46 | double similarity = xtechnical::ClusterShaper::get_cosine_similarity(normalized_cluster, triangular_distribution);
47 | double dist = xtechnical::ClusterShaper::get_euclidean_distance(normalized_cluster, triangular_distribution);
48 | std::cout << "similarity: " << similarity << std::endl;
49 | if (similarity > 0.55) {
50 | std::copy(no_normalized_cluster.begin(), no_normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
51 | std::cout << std::endl;
52 | ep::WindowSpec wstyle;
53 | ep::plot("similarity", wstyle, (int)2,
54 | normalized_cluster, ep::LineSpec(0,1,0),
55 | triangular_distribution, ep::LineSpec(0,0,1));
56 | std::system("pause");
57 | }
58 | std::cout << "dist: " << dist << std::endl;
59 | if (dist < 0.02) {
60 | std::copy(no_normalized_cluster.begin(), no_normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
61 | std::cout << std::endl;
62 | ep::WindowSpec wstyle;
63 | ep::plot("euclidean", wstyle, (int)2,
64 | normalized_cluster, ep::LineSpec(0,1,0),
65 | triangular_distribution, ep::LineSpec(0,0,1));
66 | std::system("pause");
67 | }
68 |
69 | };
70 | cluster_shaper.on_unformed_bar = [&](const xtechnical::ClusterShaper::Cluster &cluster) {
71 | auto normalized_cluster = cluster.get_normalized_array();
72 | //std::copy(normalized_cluster.begin(), normalized_cluster.end(), std::ostream_iterator(std::cout, " "));
73 | };
74 |
75 | std::mt19937 gen(time(0));
76 | //std::normal_distribution<> urd(-0.5, 1.0);
77 | //std::lognormal_distribution<> urd(-0.5, 1.0);
78 |
79 | std::uniform_real_distribution<> urd(-0.5, 1.0);
80 |
81 | const std::size_t price_size = 5000000;
82 | std::vector prices(price_size);
83 | double last_price = 10 + urd(gen);
84 | std::generate(prices.begin(), prices.begin() + price_size, [&]() -> double {
85 | last_price = last_price + 0.001d* urd(gen);
86 | return last_price;
87 | });
88 |
89 | for (size_t i = 0; i < price_size; ++i) {
90 | //std::cout << "price " << prices[i] << " " << i << std::endl;
91 | cluster_shaper.update(prices[i], i/2);
92 | }
93 |
94 | {
95 | auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(10, 5);
96 | std::copy(triangular_distribution.begin(), triangular_distribution.end(), std::ostream_iterator(std::cout, " "));
97 | std::cout << std::endl;
98 | std::system("pause");
99 | }
100 | {
101 | auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(3, 1);
102 | std::copy(triangular_distribution.begin(), triangular_distribution.end(), std::ostream_iterator(std::cout, " "));
103 | std::cout << std::endl;
104 | std::system("pause");
105 | }
106 | {
107 | auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(5, 0);
108 | std::copy(triangular_distribution.begin(), triangular_distribution.end(), std::ostream_iterator(std::cout, " "));
109 | std::cout << std::endl;
110 | std::system("pause");
111 | }
112 | {
113 | auto triangular_distribution = xtechnical::ClusterShaper::get_triangular_distribution(5, 4);
114 | std::copy(triangular_distribution.begin(), triangular_distribution.end(), std::ostream_iterator(std::cout, " "));
115 | std::cout << std::endl;
116 | std::system("pause");
117 | }
118 |
119 | std::system("pause");
120 | return 0;
121 | }
122 |
--------------------------------------------------------------------------------
/code_blocks/test/fractals.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {0,12,2,91,42,54,84,74,88,98,101,111,122,132,143,153,126,117,118,119};
9 |
10 | xtechnical::Fractals fractals;
11 |
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | fractals.update(test_data[i], test_data[i] - 1);
14 | std::cout
15 | << "update " << test_data[i]
16 | << " up " << fractals.get_up()
17 | << " dn " << fractals.get_dn()
18 | << std::endl;
19 | }
20 |
21 | /* проверяем методы тест */
22 | std::cout << "test(20, 19)" << std::endl;
23 | fractals.test(20, 19);
24 | std::cout << "up " << fractals.get_up() << " dn " << fractals.get_dn() << std::endl;
25 |
26 | std::cout << "test(21, 18)" << std::endl;
27 | fractals.test(21, 18);
28 | std::cout << "up " << fractals.get_up() << " dn " << fractals.get_dn() << std::endl;
29 |
30 | std::cout << "test(10, 8)" << std::endl;
31 | fractals.test(10, 8);
32 | std::cout << "up " << fractals.get_up() << " dn " << fractals.get_dn() << std::endl;
33 |
34 | for(size_t i = test_data.size() - 1; i > 0; --i) {
35 | fractals.update(test_data[i], test_data[i] - 2);
36 | std::cout
37 | << "update " << test_data[i]
38 | << " up " << fractals.get_up()
39 | << " dn " << fractals.get_dn()
40 | << std::endl;
41 | }
42 |
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | fractals.update(test_data[i], test_data[i] - 1);
45 | std::cout
46 | << "update " << test_data[i]
47 | << " up " << fractals.get_up()
48 | << " dn " << fractals.get_dn()
49 | << std::endl;
50 | }
51 |
52 | std::system("pause");
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/code_blocks/test/period_stats.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 |
9 | xtechnical::PeriodStatsV1 period_stats(60);
10 |
11 | period_stats.add(10, 10000);
12 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
13 | period_stats.add(10, 10001);
14 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
15 | period_stats.add(10, 10002);
16 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
17 | period_stats.add(12, 10010);
18 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
19 | period_stats.add(15, 10020);
20 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
21 | period_stats.add(30, 10030);
22 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
23 | period_stats.add(10, 10050);
24 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
25 | period_stats.add(15, 10059);
26 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
27 | period_stats.add(12, 10089);
28 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
29 | period_stats.add(12, 10090);
30 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
31 | period_stats.add(11, 10060);
32 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
33 | period_stats.add(11, 10119);
34 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
35 | period_stats.add(5, 10120);
36 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
37 | period_stats.add(11, 10121);
38 | std::cout << "e " << period_stats.empty() << " mv " << period_stats.get_max_value() << std::endl;
39 | std::cout << "w " << period_stats.get_max_weight() << " c " << period_stats.get_center_mass() << std::endl;
40 |
41 | std::system("pause");
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/code_blocks/test/ssa.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "xtechnical_indicators.hpp"
8 | #include
9 |
10 | int main(int argc, char* argv[]) {
11 | std::cout << "Hello world!" << std::endl;
12 | Eigen::VectorXf x(11);
13 | x << 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3;
14 |
15 | int M = 6; // number of ticks to forecast after the end of the time series
16 | int K = 5; // window length
17 | //int r = 0; // rank of the Hankel matrix
18 |
19 | std::cout << "res:\n" << xtechnical::SSA::calc_ssa(x, M, K, 0, xtechnical::SSA::SSAMode::OriginalSeriesAddition) << std::endl;
20 |
21 | xtechnical::SSA SSA(11);
22 |
23 | for (size_t i = 0; i < x.size(); ++i) {
24 | SSA.update(x(i), xtechnical::common::PriceType::Close);
25 | }
26 |
27 | SSA.calc(M, K, 2, 1, xtechnical::SSA::MetricType::RSquared, true, xtechnical::SSA::SSAMode::RestoredSeriesAddition);
28 |
29 | std::cout << "get_last_forecast:\n" << SSA.get_last_forecast() << std::endl;
30 |
31 | std::cout << "get_forecast:\n";
32 | for (auto &item : SSA.get_forecast()) {
33 | std::cout << item << " ";
34 |
35 | }
36 | std::cout << std::endl;
37 |
38 | std::cout << "get_reconstructed:\n";
39 | for (auto &item : SSA.get_reconstructed()) {
40 | std::cout << item << " ";
41 |
42 | }
43 | std::cout << std::endl;
44 |
45 | std::cout << "get_metric:\n" << SSA.get_metric() << std::endl;
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/code_blocks/test/super_trend.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 | #include
5 |
6 | int main(int argc, char* argv[]) {
7 | std::cout << "Hello world!" << std::endl;
8 | std::array test_data = {0,1,2,9,4,5,8,7,8,9,10,11,12,13,14,15,16,17,18,19};
9 |
10 | xtechnical::SuperTrend> super_trend(50,5);
11 |
12 | for(size_t n = 0; n < 10; ++n)
13 | for(size_t i = 0; i < test_data.size(); ++i) {
14 | super_trend.update(test_data[i]);
15 | std::cout
16 | << "update " << test_data[i]
17 | << " get " << super_trend.get()
18 | << std::endl;
19 | }
20 |
21 | /* проверяем методы тест */
22 | std::cout << "test(20)" << std::endl;
23 | super_trend.test(20);
24 | std::cout << "get " << super_trend.get() << std::endl;
25 |
26 |
27 | std::cout << "test(21)" << std::endl;
28 | super_trend.test(21);
29 | std::cout << "get " << super_trend.get() << std::endl;
30 |
31 | std::cout << "test(10)" << std::endl;
32 | super_trend.test(10);
33 | std::cout << "get " << super_trend.get() << std::endl;
34 |
35 | for(size_t i = test_data.size() - 1; i > 0; --i) {
36 | super_trend.update(test_data[i]);
37 | std::cout
38 | << "update " << test_data[i]
39 | << " get " << super_trend.get()
40 | << std::endl;
41 | }
42 |
43 | for(size_t i = 0; i < test_data.size(); ++i) {
44 | super_trend.update(test_data[i]);
45 | std::cout
46 | << "update " << test_data[i]
47 | << " get " << super_trend.get()
48 | << std::endl;
49 | }
50 |
51 | std::system("pause");
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/code_blocks/test/trend_direction_force_index.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "xtechnical_indicators.hpp"
3 | #include
4 |
5 | int main() {
6 | std::cout << "Hello world!" << std::endl;
7 | std::array test_data = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
8 |
9 | const size_t period = 2;
10 | xtechnical::TrendDirectionForceIndex> trend(period);
11 |
12 | for(size_t i = 0; i < test_data.size(); ++i) {
13 | trend.update(test_data[i]);
14 | std::cout
15 | << "update " << test_data[i]
16 | << " get " << trend.get()
17 | << std::endl;
18 | }
19 |
20 | /* проверяем методы тест */
21 | std::cout << "test(20)" << std::endl;
22 | trend.test(20);
23 | std::cout << "get " << trend.get() << std::endl;
24 |
25 |
26 | std::cout << "test(21)" << std::endl;
27 | trend.test(21);
28 | std::cout << "get " << trend.get() << std::endl;
29 |
30 | std::cout << "test(10)" << std::endl;
31 | trend.test(10);
32 | std::cout << "get " << trend.get() << std::endl;
33 |
34 | for(size_t i = test_data.size() - 1; i > 0; --i) {
35 | trend.update(test_data[i]);
36 | std::cout
37 | << "update " << test_data[i]
38 | << " get " << trend.get()
39 | << std::endl;
40 | }
41 |
42 | for(size_t i = 0; i < test_data.size(); ++i) {
43 | trend.update(test_data[i]);
44 | std::cout
45 | << "update " << test_data[i]
46 | << " get " << trend.get()
47 | << std::endl;
48 | }
49 |
50 | std::system("pause");
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/doc/example_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NewYaroslav/xtechnical_analysis/9e24d06f904a76a6d3e2e5403a9f7910d65e9817/doc/example_0.png
--------------------------------------------------------------------------------
/include/backtest/xtechnical_winrate_statistics.hpp:
--------------------------------------------------------------------------------
1 | #ifndef XTECHNICAL_WINRATE_STATISTICS_HPP_INCLUDED
2 | #define XTECHNICAL_WINRATE_STATISTICS_HPP_INCLUDED
3 |
4 | #include
5 | #include