{"id":13460889,"url":"https://github.com/mkmarek/forex.analytics","last_synced_at":"2025-03-24T19:33:18.625Z","repository":{"id":57240124,"uuid":"52747458","full_name":"mkmarek/forex.analytics","owner":"mkmarek","description":"Node.js native library performing technical analysis over an OHLC dataset with use of genetic algorithm","archived":true,"fork":false,"pushed_at":"2019-09-10T14:18:49.000Z","size":2872,"stargazers_count":181,"open_issues_count":13,"forks_count":75,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-10-17T08:23:47.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkmarek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-28T22:16:21.000Z","updated_at":"2024-10-10T21:51:25.000Z","dependencies_parsed_at":"2022-09-05T08:21:38.501Z","dependency_job_id":null,"html_url":"https://github.com/mkmarek/forex.analytics","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkmarek%2Fforex.analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkmarek%2Fforex.analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkmarek%2Fforex.analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkmarek%2Fforex.analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkmarek","download_url":"https://codeload.github.com/mkmarek/forex.analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221675298,"owners_count":16861860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T10:00:50.286Z","updated_at":"2024-10-29T06:30:57.761Z","avatar_url":"https://github.com/mkmarek.png","language":"C","readme":"Forex analytics native module for Node.js\n==========\n[![Build Status](https://travis-ci.org/mkmarek/forex.analytics.svg?branch=master)](https://travis-ci.org/mkmarek/forex.analytics)\n[![npm version](https://badge.fury.io/js/forex.analytics.svg)](https://badge.fury.io/js/forex.analytics)\n\nNode.js native library performing technical analysis over an OHLC dataset with use of genetic algorithm. The result of technical analysis are two binary trees describing strategies for buy and sell signals\nwhich produced profit in a certain period of time specified by the input OHLC data set.\n\nRunning the source\n---------------\n\nFirst if you don't have it yet. Install node-gyp for comiling the c++ source code;\n\n```\nnpm install -g node-gyp\n```\n\nThen run the install npm command to download and install all dependencies. It also compiles\nthe ta-lib dependency and builds the source code\n\n```\nnpm install\n```\n\nTo do further builds you can use\n\n```\nnode-gyp build\n```\n\nYou can run embedded examples which are located in the examples folder\n\n```\ncd examples\nnode example\n```\n\nNPM\n---------------\nYou can install forex.analytics via npm:\n\n```\nnpm install forex.analytics\n```\n\n\nUsage\n---------------\n\nImport the the module\n\n```javascript\nvar analytics = require('forex.analytics');\n```\n\nor with ES6 modules syntax\n\n```javascript\nimport analytics from 'forex.analytics'\n```\nAnalytics object will give you several functions to use.\n\nfindStrategy(candlesticks, options, progressCallback)\n---------------\n\nFinds the optimal strategy for a certain period defined by the *candlesticks* array.\n\n**candlesticks** parameter should contain an array of objects representing one candlestick in OHLC chart.\n```javascript\n{\n  open: 1.113990,\n  high: 1.113990,\n  low: 1.113890,\n  close: 1.113890,\n  time: 1435701600\n}\n```\n\n**options** parameter lists several properties that influence the genetic algorithm\n```javascript\n{\n populationCount: 100,\n generationCount: 300,\n selectionAmount: 10,\n leafValueMutationProbability: 0.5,\n leafSignMutationProbability: 0.3,\n logicalNodeMutationProbability: 0.3,\n leafIndicatorMutationProbability: 0.2,\n crossoverProbability: 0.03,\n indicators: [ 'CCI', 'MACD', 'RSI', 'SMA15_SMA50' ],\n strategy: { buy : {...}, sell : {...} }\n}\n```\n\n**progressCallback** parameter has to be a function. This function is invoked when one generation passes.\n It contains three arguments: **strategy, fitness, generation**. Where **strategy** stands for the currently best\n strategy found in a certain generation. **Fitness** is a fitness value of a certain strategy calculated by fitness evaluation algorithm.\n **Generation** is the number of generation which was just completed. The **strategy** parameter describes which\n strategy it shall use as a referential. This parameter is not mandatory.\n\n ```javascript\n function progressCallback(strategy, fitness, generation) {\n   console.log('Fitness: ' + fitness + '; Generation: ' + generation);\n }\n ```\n\n could print\n\n ```\nFitness: 0.00010751596495091384; Generation: 285\n ```\n\nThe returning value is a promise which when it's resolved passes one argument with the best found strategy.\n\n**Full example:**\n```javascript\nanalytics.findStrategy(candlesticks, {\n  populationCount: 100,\n  generationCount: 300,\n  selectionAmount: 10,\n  leafValueMutationProbability: 0.5,\n  leafSignMutationProbability: 0.3,\n  logicalNodeMutationProbability: 0.3,\n  leafIndicatorMutationProbability: 0.2,\n  crossoverProbability: 0.03,\n  indicators: indicators\n\n}, function(strategy, fitness, generation) {\n  console.log('Fitness: ' + fitness + '; Generation: ' + generation);\n})\n.then(function(strategy) {\n  console.log('------------Strategy-------------')\n  console.log(strategy);\n});\n```\n\nThis could print something like:\n\n```\nFitness: 0.0; Generation: 1\n....\nFitness: 0.00010751596495091384; Generation: 297\nFitness: 0.00010751596495091384; Generation: 298\nFitness: 0.00010751596495091384; Generation: 299\nFitness: 0.00010751596495091384; Generation: 300\n------------Strategy-------------\n{\n   \"buy\":{\n      \"operator\":\"And\",\n      \"left\":{\n         \"operator\":\"Or\",\n         \"left\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003e\",\n           \"value\":-0.8390790893276773\n         },\n         \"right\":{\n           \"indicator\":\"RSI\",\n           \"sign\":\"\u003e\",\n           \"value\":74.22093161865811\n         }\n      },\n      \"right\":{\n         \"operator\":\"And\",\n         \"left\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003c\",\n           \"value\":-0.6815039536729026\n         },\n         \"right\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003c\",\n           \"value\":-0.32888175664540553\n         }\n      }\n   },\n   \"sell\":{\n      \"operator\":\"And\",\n      \"left\":{\n         \"operator\":\"Or\",\n         \"left\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003e\",\n           \"value\":-0.8390790893276773\n         },\n         \"right\":{\n           \"indicator\":\"RSI\",\n           \"sign\":\"\u003e\",\n           \"value\":74.22093161865811\n         }\n      },\n      \"right\":{\n         \"operator\":\"And\",\n         \"left\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003c\",\n           \"value\":-0.6815039536729026\n         },\n         \"right\":{\n           \"indicator\":\"Momentum\",\n           \"sign\":\"\u003c\",\n           \"value\":-0.32888175664540553\n         }\n      }\n   }\n}\n```\nconvertOHLC(candlesticks, targetTimeframe)\n---------------\nConverts OHLC data set to a larger timeframe\n(e.g. from 5 minute interval to 30 minute interval)\n\n**candlesticks** parameter should contain an array of objects representing one candlestick in OHLC chart.\n```javascript\n{\n  open: 1.113990,\n  high: 1.113990,\n  low: 1.113890,\n  close: 1.113890,\n  time: 1435701600\n}\n```\n\n**targetTimeframe** parameter defines the target interval in seconds\n\n**Example:**\n```javascript\n/**\n * Converts candlesticks from lower timeframe to 30 minute timeframe\n */\nfunction convertTo30MOhlc(candlesticks) {\n  return analytics.convertOHLC(candlesticks, 1800);\n}\n```\n\nThis function can be used for converting ticks to OHLC as well with a simple trick.\n\n```javascript\n/**\n * Converts ticks to one minute OHLC\n * Input could be for example: { time : 0, value : 1.225 },  { time : 10, value : 1.226 },\n *  { time : 20, value : 1.227 },  { time : 30, value : 1.228 }, ...\n */\nfunction ticksTo1MOhlc(ticks) {\n  return analytics.convertOHLC(candlesticks\n    .map(t =\u003e {\n      open: t.value,\n      high: t.value,\n      low: t.value,\n      close: t.value,\n      time: t.time\n    }), 60 /* one minute interval */);\n}\n```\n\ngetMarketStatus(candlesticks, options)\n---------------\n\nReturns suggestion whether to buy or sell current for the last candlestick in the\n**candlesticks** array passed in as a first parameter.\n\n**candlesticks** parameter should contain an array of objects representing one candlestick in OHLC chart.\n```javascript\n{\n  open: 1.113990,\n  high: 1.113990,\n  low: 1.113890,\n  close: 1.113890,\n  time: 1435701600\n}\n```\n\n**options** parameter lists one property\n```javascript\n{\n strategy: { buy : [...], sell : [...] }\n}\n```\n**strategy** is the result from the **findStrategy** function and defines when to buy and when to sell.\n\n**Example:**\n```javascript\nvar status = analytics.getMarketStatus(candlesticks, { strategy: strategy });\nconsole.log(status);\n```\nCan output:\n```\n{ shouldBuy: true, shouldSell: false }\n```\n\ngetTrades(candlesticks, options)\n---------------\n\nReturns an array of trades that were performed on a provided candlestick array\nwith given strategy\n**candlesticks** array passed in as a first parameter.\n\n**candlesticks** parameter should contain an array of objects representing one candlestick in OHLC chart.\n```javascript\n{\n  open: 1.113990,\n  high: 1.113990,\n  low: 1.113890,\n  close: 1.113890,\n  time: 1435701600\n}\n```\n\n**options** parameter lists one property\n```javascript\n{\n strategy: { buy : [...], sell : [...] }\n}\n```\n**strategy** is the result from the **findStrategy** function and defines when to buy and when to sell.\n\n**Example:**\n```javascript\nvar trades = analytics.getTrades(candlesticks, {\n  strategy: strategy\n});\nconsole.log(trades);\n```\n\nCan output:\n\n```\n[\n   {\n      \"Buy\":true,\n      \"Revenue\":0.0031200000000000117,\n      \"MaximumLoss\":0.0023200000000000998,\n      \"MaximumProfit\":0.005009999999999959,\n      \"ProfitBeforeLoss\" : true,\n      \"start\":{\n         \"open\":1.10604,\n         \"low\":1.10586,\n         \"high\":1.10762,\n         \"close\":1.10711,\n         \"time\":1435782600\n      },\n      \"end\":{\n         \"open\":1.10833,\n         \"low\":1.10833,\n         \"high\":1.11044,\n         \"close\":1.11023,\n         \"time\":1435824000\n      }\n   }\n]\n```\n\nWhere **buy** stands for whether the specific trade was made on a profit from a\nrising or falling market.\n\n**Revenue** is the the revenue that was obtained at the end of a trade.\n\n**MaximumLoss** describes how far the price movement went against the wanted direction.\n**MaximumProfit** describes how far the price movement went on the wanted direction.\n**start** and **end** are the candlesticks describing the boundaries of a given trade.\n**ProfitBeforeLoss** indicates whether the maximum profit was reached before maximum loss\n\nRoadmap\n---------------\n- [ ] Stabilize the solution / fix bugs\n- [ ] Make the algorithm more abstract (support for different kind of chromosomes and tree nodes)\n- [ ] Delegate indicator generation to a different library (perhaps use [node-talib](https://github.com/oransel/node-talib))\n- [ ] Implementing support for generating indicators (math formulas with OHLC as an input) based on successful trades\n- [ ] Think of more stuff to add. :)\n","funding_links":[],"categories":["Strategies \u0026 Research","📦 Legacy \u0026 Inactive Projects"],"sub_categories":["Technical Analysis","TA"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkmarek%2Fforex.analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkmarek%2Fforex.analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkmarek%2Fforex.analytics/lists"}