Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.ahmadmo:math-time-series

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.ahmadmo:math-time-series

Mathematics for Time Series

  • 0.0.5
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Mathematics for Time Series

The goal of this library is to contain a bunch of common time-series analysis tools and indicators mostly used in technical analysis in finance.

List of contents

Build Instructions

You can use Maven or Gradle to add the library to your project.

Maven
<dependency>
    <groupId>com.github.ahmadmo</groupId>
    <artifactId>math-time-series</artifactId>
    <version>0.0.4</version>
</dependency>
Gradle
dependencies {
    compile 'com.github.ahmadmo:math-time-series:0.0.4'
}

Linear Trend Line

Imports
import ir.ahmadmo.math.timeseries.trend.*
import org.knowm.xchart.SwingWrapper
import org.knowm.xchart.XYChartBuilder
import org.knowm.xchart.style.Styler
import org.knowm.xchart.style.markers.SeriesMarkers
import kotlin.math.abs
import kotlin.math.min

You need to add the dependency for xchart to run the sample code:

<dependency>
    <groupId>org.knowm.xchart</groupId>
    <artifactId>xchart</artifactId>
    <version>3.6.5</version>
</dependency>
Sample Code
val trend = generateRandomTrend(size = 120)
val smoothingFactors = doubleArrayOf(0.01, 0.02, 0.05, 0.1, 0.15, 0.25)

val (resistance, support, average) = trend.linearTrendLines(smoothingFactors)

val resistanceData = DoubleArray(trend.size, resistance::value)
val supportData = DoubleArray(trend.size, support::value)
val averageData = DoubleArray(trend.size, average::value)

Notice that this is the user's responsibility to choose the rigth values for smoothingFactors from 0.0 to 1.0 to achieve better results. Choosing higher values results in smoother trends and consequently tighter trend lines. An empty smoothingFactors disables smoothing.

The function for generating a random trend (time-series):

fun generateRandomTrend(size: Int): Trend {
    val trend = Trend(size)
    var min = Double.MAX_VALUE
    for (x in trend.indices.drop(1)) {
        trend[x] = trend[x - 1] + Math.random() - 0.5
        min = min(min, trend[x])
    }
    val shift = abs(min(min, 0.0))
    return if (shift == 0.0) trend
    else Trend(size) { x -> trend[x] + shift }
}

Finally, to visualize the computed trend lines using xchart: (learn more)

val chart = XYChartBuilder()
    .width(1280).height(720)
    .theme(Styler.ChartTheme.Matlab)
    .title("Trend Lines")
    .xAxisTitle("Day").yAxisTitle("Price")
    .build()

chart.styler.isPlotGridLinesVisible = false
chart.styler.xAxisTickMarkSpacingHint = 100

val xData = DoubleArray(trend.size, Int::toDouble)

chart.addSeries("Trend", xData, trend)
chart.addSeries("Resistance", xData, resistanceData)
chart.addSeries("Support", xData, supportData)
chart.addSeries("Average", xData, averageData)

chart.seriesMap.values.forEach { it.marker = SeriesMarkers.NONE }

SwingWrapper(chart).displayChart()

Here is the complete sample code demonstrating how to draw linear trend lines for a time-series.

Sample Results
1.png2.png
3.png4.png
5.png6.png

Relative Strength Index (RSI)

TODO

Moving Average Convergence Divergence (MACD)

TODO

Bollinger Bands

TODO

Ichimoku Cloud

TODO

Fibonacci Retracement

TODO

Fibonacci Fan

TODO

Fibonacci Arc

TODO

Fibonacci Time Zones

TODO

FAQs

Package last updated on 04 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc