├── .gitignore
├── .jazzy.yaml
├── Changelog.md
├── LICENSE
├── Package.swift
├── README.md
├── Sources
├── libindicators
│ ├── include
│ │ ├── indicators-wrapping.h
│ │ └── indicators.h
│ ├── module.modulemap
│ ├── tiamalgamation.c
│ └── wrapping.c
└── tulipindicators
│ ├── Function.swift
│ ├── Info.plist
│ ├── Quotable.swift
│ ├── Tulip.swift
│ └── tulipindicators.h
├── Tests
├── Info.plist
├── LinuxMain.swift
└── tulipindicatorsTests
│ ├── AssertHelper.swift
│ ├── FunctionTests.swift
│ └── XCTestManifests.swift
├── docs
├── Enums.html
├── Enums
│ └── IndicatorKind.html
├── Functions.html
├── Protocols.html
├── Protocols
│ └── Quotable.html
├── Structs.html
├── Structs
│ ├── ArroonResult.html
│ ├── BBandResult.html
│ ├── Bindings.html
│ ├── Direction.html
│ ├── FisherResult.html
│ ├── IndicatorInfo.html
│ ├── MACDResult.html
│ ├── MSWResult.html
│ ├── StochResult.html
│ └── Tulip.html
├── badge.svg
├── css
│ ├── highlight.css
│ └── jazzy.css
├── docsets
│ ├── tulipindicators.docset
│ │ └── Contents
│ │ │ ├── Info.plist
│ │ │ └── Resources
│ │ │ ├── Documents
│ │ │ ├── Enums.html
│ │ │ ├── Enums
│ │ │ │ └── IndicatorKind.html
│ │ │ ├── Functions.html
│ │ │ ├── Protocols.html
│ │ │ ├── Protocols
│ │ │ │ └── Quotable.html
│ │ │ ├── Structs.html
│ │ │ ├── Structs
│ │ │ │ ├── ArroonResult.html
│ │ │ │ ├── BBandResult.html
│ │ │ │ ├── Bindings.html
│ │ │ │ ├── Direction.html
│ │ │ │ ├── FisherResult.html
│ │ │ │ ├── IndicatorInfo.html
│ │ │ │ ├── MACDResult.html
│ │ │ │ ├── MSWResult.html
│ │ │ │ ├── StochResult.html
│ │ │ │ └── Tulip.html
│ │ │ ├── badge.svg
│ │ │ ├── css
│ │ │ │ ├── highlight.css
│ │ │ │ └── jazzy.css
│ │ │ ├── img
│ │ │ │ ├── carat.png
│ │ │ │ ├── dash.png
│ │ │ │ ├── gh.png
│ │ │ │ └── spinner.gif
│ │ │ ├── index.html
│ │ │ ├── js
│ │ │ │ ├── jazzy.js
│ │ │ │ ├── jazzy.search.js
│ │ │ │ ├── jquery.min.js
│ │ │ │ ├── lunr.min.js
│ │ │ │ └── typeahead.jquery.js
│ │ │ ├── search.json
│ │ │ └── undocumented.json
│ │ │ └── docSet.dsidx
│ ├── tulipindicators.tgz
│ └── tulipindicators.xml
├── img
│ ├── carat.png
│ ├── dash.png
│ ├── gh.png
│ └── spinner.gif
├── index.html
├── js
│ ├── jazzy.js
│ ├── jazzy.search.js
│ ├── jquery.min.js
│ ├── lunr.min.js
│ └── typeahead.jquery.js
├── search.json
└── undocumented.json
├── tulipindicators-swift.podspec
└── tulipindicators-swift.xcodeproj
├── project.pbxproj
├── project.xcworkspace
└── contents.xcworkspacedata
└── xcshareddata
└── xcschemes
├── tulipindicators-iOS.xcscheme
├── tulipindicators-macOS.xcscheme
├── tulipindicators-tvOS.xcscheme
└── tulipindicators-watchOS.xcscheme
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | .swiftpm/*
5 | .vscode/*
6 | Carthage/*
7 |
--------------------------------------------------------------------------------
/.jazzy.yaml:
--------------------------------------------------------------------------------
1 | author: Yannick Heinrich
2 | author_url: https://blog.yageek.net
3 | github_url: https://github.com/yageek/tulipindicators-swift
4 | root_url: https://yageek.github.io/tulipindicators-swift/
5 | module_version: 1.0.0
6 | module: tulipindicators
7 | framework_root: .
8 | xcodebuild_arguments: ["-scheme", "tulipindicators-macOS"]
9 | theme: apple
10 |
--------------------------------------------------------------------------------
/Changelog.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 1.0.1
4 |
5 | - Fix crash on using the `stoch` indicator (#4)
6 |
7 | ## 1.0.0
8 |
9 | Initial release. Based on tulip 0.8.0
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:4.2
2 | import PackageDescription
3 |
4 | let package = Package(
5 | name: "tulipindicators",
6 | products: [
7 | .library(
8 | name: "tulipindicators",
9 | targets: ["tulipindicators"]),
10 | ],
11 | targets: [
12 | .target(
13 | name: "tulipindicators",
14 | dependencies: ["libindicators"]),
15 | .target(
16 | name: "libindicators",
17 | dependencies: []),
18 | .testTarget(
19 | name: "tulipindicatorsTests",
20 | dependencies: ["tulipindicators"]),
21 | ]
22 | )
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # tulipindicators-swift
2 |
3 | [](LICENSE)
4 | [](https://github.com/Carthage/Carthage)
5 | [](https://img.shields.io/cocoapods/v/tulipindicators-swift.svg)
6 |
7 | This swift package offers a technical analysis function by wrapping the [tulipindicators C library](https://tulipindicators.org)
8 |
9 | ## Installation
10 |
11 | You can access the documentation [here](https://yageek.github.io/tulipindicators-swift/)
12 |
13 | ### Swift package manager
14 |
15 | ```swift
16 | import PackageDescription
17 |
18 | let package = Package(
19 | dependencies: [
20 | .package(url: "https://github.com/yageek/tulipindicators-swift.git", from: "1.0.1"),
21 | ]
22 | )
23 | ```
24 |
25 | ### Carthage
26 |
27 | ```
28 | github "yageek/tulipindicators-swift" ~> 1.0.1
29 | ```
30 |
31 | ### Cocoapods
32 |
33 | ```
34 | pod 'tulipindicators-swift' ~> 1.0.1
35 | ```
36 |
37 | ## Usage
38 |
39 | ```swift
40 | import tulipindicators
41 |
42 | let inputs: [Double] = [81.59, 81.06, 82.87, 83.00, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29]
43 | let (beginIdx, outputs) = msw(inputs, period: 5)
44 |
45 | print("Relative Input offset: \(beginIdx)")
46 | print("MSW values: \(outputs)")
47 | ```
48 |
--------------------------------------------------------------------------------
/Sources/libindicators/include/indicators-wrapping.h:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | #ifndef __TULIP_WRAPPING
25 | #define __TULIP_WRAPPING
26 |
27 | struct ti_indicator_info;
28 | extern struct ti_indicator_info *ti_indicators_ptr;
29 |
30 | char **ti_indicator_info_get_input_names(struct ti_indicator_info *info);
31 | char **ti_indicator_info_get_option_names(struct ti_indicator_info *info);
32 | char **ti_indicator_info_get_output_names(struct ti_indicator_info *info);
33 | #endif
34 |
--------------------------------------------------------------------------------
/Sources/libindicators/module.modulemap:
--------------------------------------------------------------------------------
1 | module libindicators {
2 | header "include/indicators.h"
3 | header "include/indicators-wrapping.h"
4 | export *
5 | }
6 |
--------------------------------------------------------------------------------
/Sources/libindicators/wrapping.c:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | #include "indicators.h"
25 |
26 | struct ti_indicator_info *ti_indicators_ptr = &ti_indicators[0];
27 |
28 | char **ti_indicator_info_get_input_names(struct ti_indicator_info *info) {
29 | return &info->input_names[0];
30 | }
31 |
32 | char **ti_indicator_info_get_option_names(struct ti_indicator_info *info){
33 | return &info->option_names[0];
34 | }
35 |
36 | char **ti_indicator_info_get_output_names(struct ti_indicator_info *info){
37 | return &info->output_names[0];
38 | }
39 |
--------------------------------------------------------------------------------
/Sources/tulipindicators/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Sources/tulipindicators/Quotable.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | import Foundation
25 |
26 | /// An element representing a Quote
27 | ///
28 | /// For the sake of convenience, the protocol provides
29 | /// default implementation for all values that equal zero.
30 | public protocol Quotable {
31 |
32 | /// The high value
33 | var high: Double { get }
34 |
35 | /// The low value
36 | var low: Double { get }
37 |
38 | /// The open value
39 | var open: Double { get }
40 |
41 | /// The close value
42 | var close: Double { get }
43 |
44 | /// The volume value
45 | var volume: Int { get }
46 | }
47 |
48 | public extension Quotable {
49 | var high: Double { return 0.0 }
50 | var low: Double { return 0.0 }
51 | var open: Double { return 0.0 }
52 | var close: Double { return 0.0 }
53 | var volume: Int { return 0 }
54 | }
55 |
56 | func HL(_ inputs: [T]) -> [Double] {
57 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*2)
58 |
59 | for i in 0..(_ inputs: [T]) -> [Double] {
67 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*2)
68 |
69 | for i in 0..(_ inputs: [T]) -> [Double] {
77 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*2)
78 |
79 | for i in 0..(_ inputs: [T]) -> [Double] {
87 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*3)
88 | for i in 0..(_ inputs: [T]) -> [Double] {
97 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*3)
98 | for i in 0..(_ inputs: [T]) -> [Double] {
107 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*4)
108 | for i in 0..(_ inputs: [T]) -> [Double] {
118 | var raw_inputs = [Double](repeating: 0.0, count: inputs.count*4)
119 | for i in 0...
21 | *
22 | */
23 |
24 | import libindicators
25 |
26 | /// The kind of the indicator
27 | public enum IndicatorKind {
28 | /// The indicator is an overlay
29 | case overlay
30 | /// The indicator is simple math
31 | case math
32 | /// The indicator is a simple indicator
33 | case simple
34 | /// The indicator is a comparative indicator
35 | case comparative
36 | }
37 |
38 | private func arguments(array: UnsafeMutablePointer?>?, count: Int32) -> [String] {
39 |
40 | var args: [String] = [String](repeating: "", count: Int(count))
41 | for i in 0.. (Int, [Double]) {
119 | return Tulip.shared.call_indicator(name: name, inputs: inputs, options: options)
120 | }
121 |
122 | /// Get the information about one indicator
123 | /// - Parameter name: The name of the indicator
124 | public static func indicator_info(name: String) -> IndicatorInfo {
125 | let indicator = Tulip.shared.indicator_info(by: name)
126 | return IndicatorInfo(tulip_info: indicator)
127 | }
128 |
129 | static let shared = Tulip()
130 |
131 | private init() { }
132 |
133 | private static var list: [String: ti_indicator_info] = {
134 | var entry_ptr = ti_indicators_ptr
135 | var indicators = [String: ti_indicator_info]()
136 | while let info = entry_ptr?.pointee, info.name != nil {
137 | indicators[String(cString: info.name)] = info
138 | entry_ptr = entry_ptr?.advanced(by: 1)
139 | }
140 | return indicators
141 | }()
142 |
143 | func indicator_info(by name: String) -> ti_indicator_info {
144 | return Tulip.list[name]!
145 | }
146 |
147 | func call_indicator(name: String, inputs: [Double], options: [Double]) -> (Int, [Double]) {
148 | return call_indicator(indicator_info(by: name), inputs: inputs, options: options)
149 | }
150 |
151 | private func call_indicator(_ indicator: ti_indicator_info, inputs: [Double], options: [Double]) -> (Int, [Double]) {
152 |
153 | let in_size = inputs.count/Int(indicator.inputs)
154 | let beginIdx = Int(indicator.start(options))
155 | let count = in_size - beginIdx
156 | var outputs = [Double](repeating: 0.0, count: Int(indicator.outputs) * count)
157 |
158 | var result: Int32 = TI_OKAY
159 |
160 | inputs.withUnsafeBufferPointer { (inputs_ptr) in
161 | outputs.withUnsafeMutableBufferPointer { (outputs_ptr) in
162 |
163 | let in_range = 0...
21 | *
22 | */
23 | #import
24 |
25 | //! Project version number for tulipindicators.
26 | FOUNDATION_EXPORT double tulipindicatorsVersionNumber;
27 |
28 | //! Project version string for tulipindicators.
29 | FOUNDATION_EXPORT const unsigned char tulipindicatorsVersionString[];
30 |
31 | // In this header, you should import all the public headers of your framework using statements like #import
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Tests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Tests/LinuxMain.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | import XCTest
25 |
26 | import tulipindicatorsTests
27 |
28 | var tests = [XCTestCaseEntry]()
29 | tests += tulipindicatorsTests.allTests()
30 | XCTMain(tests)
31 |
--------------------------------------------------------------------------------
/Tests/tulipindicatorsTests/AssertHelper.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | import XCTest
25 |
26 | func TIAssert(_ left: @autoclosure () -> [Double], _ right: @autoclosure () -> [Double], _ delta: Double, file: StaticString = #file, line: UInt = #line) {
27 |
28 | let lhs = left()
29 | let rhs = right()
30 |
31 | XCTAssertEqual(lhs.count, rhs.count, "Both elements should have the same length", file: file, line: line)
32 |
33 | for i in 0.. delta => abs(\(lhs[i]) - \(rhs[i])) = \(abs(lhs[i] - rhs[i]))> \(delta)", file: file, line: line)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Tests/tulipindicatorsTests/FunctionTests.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | import XCTest
25 | @testable import tulipindicators
26 |
27 | final class FunctionTests: XCTestCase {
28 |
29 | private struct Quote: Quotable {
30 | let high: Double
31 | let low: Double
32 | let open: Double
33 | let close: Double
34 | let volume: Int
35 |
36 | init(high: Double = 0.0, low: Double = 0.0, open: Double = 0.0, close: Double = 0.0, volume: Int = 0) {
37 | self.high = high
38 | self.low = low
39 | self.open = open
40 | self.close = close
41 | self.volume = volume
42 | }
43 | }
44 |
45 |
46 | // MARK: - Moving Average
47 | private let inputs: [Double] = [81.59,81.06,82.87,83.00,83.61,83.15,82.84,83.99,84.55,84.36,85.53,86.54,86.89,87.77,87.29]
48 | private let period = 5
49 | private let delta: Double = 1e-3
50 |
51 | func runAVGTest(_ fn: (_ inputs: [Double], _ period: Int) -> (Int, [Double]), _ expected: [Double], file: StaticString = #file, line: UInt = #line) {
52 | let (_, res) = fn(inputs, period)
53 | TIAssert(expected, res, delta, file: file, line: line)
54 | }
55 |
56 | func testSMA() {
57 | let expected: [Double] = [82.426,82.738,83.094,83.318,83.628,83.778,84.254,84.994,85.574,86.218,86.804]
58 | runAVGTest(sma, expected)
59 | }
60 |
61 | func testWMA() {
62 | let expected: [Double] = [82.825,83.066,83.100,83.399,83.809,84.053,84.637,85.399,86.031,86.763,87.121]
63 | runAVGTest(wma, expected)
64 | }
65 |
66 | func testEMA() {
67 | let expected: [Double] = [81.590,81.413,81.899,82.266,82.714,82.859,82.853,83.232,83.671,83.901,84.444,85.143,85.725,86.407,86.701]
68 | runAVGTest(ema, expected)
69 | }
70 |
71 | func testDEMA() {
72 | let expected: [Double] = [84.159,84.379,85.125,86.062,86.727,87.529,87.646]
73 | runAVGTest(dema, expected)
74 | }
75 |
76 | func testTEMA() {
77 | let expected: [Double] = [87.042,87.819,87.721]
78 | runAVGTest(tema, expected)
79 | }
80 |
81 | func testTRIMA() {
82 | let expected: [Double] = [82.437,82.908,83.204,83.260,83.440,83.807,84.302,84.863,85.537,86.288,86.901]
83 | runAVGTest(trima, expected)
84 | }
85 |
86 | func testKAMA() {
87 | let expected: [Double] = [83.610,83.560,83.452,83.506,83.647,83.686,84.126,85.026,85.690,86.447,86.673]
88 | runAVGTest(kama, expected)
89 | }
90 |
91 | func testBBANDS() {
92 | let inputs: [Double] = [81.59,81.06,82.87,83.00,83.61,83.15,82.84,83.99,84.55,84.36,85.53,86.54,86.89,87.77,87.29]
93 | let exp_lower: [Double] = [80.530,80.987,82.533,82.472,82.418,82.435,82.511,83.143,83.536,83.870,85.289]
94 | let exp_middle: [Double] = [82.426,82.738,83.094,83.318,83.628,83.778,84.254,84.994,85.574,86.218,86.804]
95 | let exp_upper: [Double] = [84.322,84.489,83.655,84.164,84.838,85.121,85.997,86.845,87.612,88.566,88.319]
96 |
97 |
98 | let stddev: Double = 2
99 | let delta: Double = 1e-3
100 | let (_,res) = bbands(inputs, period: period, stddev: stddev);
101 | TIAssert(res.lower, exp_lower, delta);
102 | TIAssert(res.middle, exp_middle, delta);
103 | TIAssert(res.upper, exp_upper, delta);
104 | }
105 |
106 | func testFisher() {
107 | let high: [Double] = [82.15, 81.89, 83.03, 83.30, 83.85, 83.90, 83.33, 84.30, 84.84, 85.00, 85.90, 86.58, 86.98, 88.00, 87.87]
108 | let low: [Double] = [81.29, 80.64, 81.31, 82.65, 83.07, 83.11, 82.49, 82.30, 84.15, 84.11, 84.03, 85.39, 85.76, 87.17, 87.01]
109 | let exp_fisher = [0.34, 0.79, 0.83, 0.81, 1.07, 1.44, 1.85, 2.28, 2.70, 3.12, 3.19]
110 | let exp_signal = [0.00, 0.34, 0.79, 0.83, 0.81, 1.07, 1.44, 1.85, 2.28, 2.70, 3.12]
111 |
112 | let delta: Double = 1e-2
113 | let period: Int = 5
114 | let quotes = zip(high, low).map { Quote(high: $0.0, low: $0.1) }
115 |
116 | let (_, res) = fisher(quotes, period: period)
117 | TIAssert(res.fisher, exp_fisher, delta)
118 | TIAssert(res.signal, exp_signal, delta)
119 | }
120 |
121 | func testMSW() {
122 | let inputs: [Double] = [81.59, 81.06, 82.87, 83.00, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29]
123 | let exp_sine: [Double] = [-0.06, -0.72, 0.61, 1.00, 0.52, 0.43, 0.86, 0.67, 0.44, 0.22]
124 | let exp_lead: [Double] = [-0.75, -1.00, 0.99, 0.64, -0.24, -0.33, 0.25, -0.05, -0.32, -0.53]
125 |
126 | let delta: Double = 1e-2
127 | let period: Int = 5
128 | let (_, res) = msw(inputs, period: period)
129 | TIAssert(res.sine, exp_sine, delta)
130 | TIAssert(res.lead, exp_lead, delta)
131 | }
132 |
133 | func testStochCrash() {
134 | let inputs: [Quote] = [
135 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
136 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
137 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
138 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
139 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
140 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
141 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
142 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
143 | Quote(high: 0, low: 0, open: 0, close: 0, volume: 0),
144 | ]
145 | let _ = stoch(inputs, kPeriod: 2, kSlowingPeriod: 2, dPeriod: 2)
146 | }
147 |
148 | // MARK: - Info
149 | func testInfo() {
150 | let info = Tulip.indicator_info(name: "sma")
151 | XCTAssertEqual("sma", info.name)
152 | XCTAssertEqual("Simple Moving Average", info.fullName)
153 | XCTAssertEqual(.overlay, info.kind)
154 | XCTAssertEqual(["period"], info.options)
155 | XCTAssertEqual(["sma"], info.outputs)
156 | XCTAssertEqual(["real"], info.inputs)
157 | }
158 |
159 | // MARK: - All tests
160 | static var allTests = [
161 | ("testSMA", testSMA),
162 | ("testWMA", testWMA),
163 | ("testEMA", testEMA),
164 | ("testDEMA", testDEMA),
165 | ("testTEMA", testTEMA),
166 | ("testTRIMA", testTRIMA),
167 | ("testTRIMA", testKAMA),
168 | ("testBollinger", testBBANDS),
169 | ("testInfo", testInfo)
170 | ]
171 | }
172 |
--------------------------------------------------------------------------------
/Tests/tulipindicatorsTests/XCTestManifests.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * tulipindicators-swfit
3 | * https://tulipindicators.org/
4 | * Copyright (c) 2019 Yannick Heinrich
5 | * Yannick Heinrich (me@yageek.net)
6 | *
7 | * This file is part of tulipindicators-swfit.
8 | *
9 | * Tulip Indicators is free software: you can redistribute it and/or modify it
10 | * under the terms of the GNU Lesser General Public License as published by the
11 | * Free Software Foundation, either version 3 of the License, or (at your
12 | * option) any later version.
13 | *
14 | * Tulip Indicators is distributed in the hope that it will be useful, but
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 | * for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License
20 | * along with Tulip Indicators. If not, see .
21 | *
22 | */
23 |
24 | import XCTest
25 |
26 | #if !os(macOS) && !os(iOS) && !os(tvOS) && !os(watchOS)
27 | public func allTests() -> [XCTestCaseEntry] {
28 | return [
29 | testCase(FunctionTests.allTests)
30 | ]
31 | }
32 | #endif
33 |
--------------------------------------------------------------------------------
/docs/Enums.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Enumerations Reference
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
Call the tulip library directly. See the tulip indicator list","parent_name":"Tulip"},"Structs/Tulip.html#/s:15tulipindicators5TulipV14indicator_info4nameAA13IndicatorInfoVSS_tFZ":{"name":"indicator_info(name:)","abstract":"
Call the tulip library directly. See the tulip indicator list","parent_name":"Tulip"},"Structs/Tulip.html#/s:15tulipindicators5TulipV14indicator_info4nameAA13IndicatorInfoVSS_tFZ":{"name":"indicator_info(name:)","abstract":"