{ "info": { "author": "Gregory Morse", "author_email": "gregory.morse@live.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Office/Business :: Financial", "Topic :: Office/Business :: Financial :: Investment", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# trendln\n\nSupport and Resistance Trend lines Calculator for Financial Analysis\n====================================================================\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/trendln)](https://pypi.python.org/pypi/trendln)\n[![PyPI - Version](https://img.shields.io/pypi/v/trendln.svg?maxAge=60)](https://pypi.python.org/pypi/trendln)\n[![PyPI - Status](https://img.shields.io/pypi/status/trendln.svg?maxAge=60)](https://pypi.python.org/pypi/trendln)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/trendln.svg?maxAge=2592000&label=installs&color=%2327B1FF)](https://pypi.python.org/pypi/trendln)\n[![PyPI - License](https://img.shields.io/pypi/l/trendln)](https://pypi.python.org/pypi/trendln)\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/trendln)](https://pypi.python.org/pypi/trendln)\n[![GitHub stars](https://img.shields.io/github/stars/GregoryMorse/trendln?style=social)](https://github.com/GregoryMorse/trendln)\n\nNote\n----\n\nThis library can calculate and plot trend lines for any time series, not only for its primary intended purpose of financial analysis.\n\n[Changelog \u00bb](./CHANGELOG.md)\n\n---\n\n==> Check out this article on [Programmatic Identification of Support/Resistance Trend lines with Python](https://towardsdatascience.com/programmatic-identification-of-support-resistance-trend-lines-with-python-d797a4a90530) or [alternatively here](https://medium.com/@gregory.morse1/programmatic-identification-of-support-resistance-trend-lines-with-python-d797a4a90530)\nfor details on how the library and its features are implemented and work.\n\n---\n\nQuick Start\n===========\n\nCalculation Only\n----------------\n\nThe **calc_support_resistance** function will calculate all support and\nresistance information including local extrema, average and their\ntrend lines using several different methods:\n\n\timport trendln\n\t# this will serve as an example for security or index closing prices\n\timport yfinance as yf # requires yfinance - pip install yfinance\n\ttick = yf.Ticker('^GSPC') # S&P500\n\thist = tick.history(period=\"max\", rounding=True)\n\tminimaIdxs, maximaIdxs, pmin, pmax, mintrend, maxtrend, minwindows, maxwindows =\n\t\tcalc_support_resistance(hist[-1000:].Close)\n\tminimaIdxs, maximaIdxs, pmin, pmax, mintrend, maxtrend, minwindows, maxwindows =\n\t\tcalc_support_resistance(\n\t\t# list of data as float\n\t\thist,\n\n\t\t# METHOD_NAIVE - any local minima or maxima only for a single interval (currently requires pandas)\n\t\t# METHOD_NAIVECONSEC - any local minima or maxima including those for consecutive constant intervals (currently requires pandas)\n\t\t# METHOD_NUMDIFF (default) - numerical differentiation determined local minima or maxima (requires findiff)\n\t\textmethod = METHOD_NUMDIFF,\n\t\t\n\t\t# METHOD_NCUBED - simple exhuastive 3 point search (slowest)\n\t\t# METHOD_NSQUREDLOGN (default) - 2 point sorted slope search (fast)\n\t\t# METHOD_HOUGHPOINTS - Hough line transform optimized for points\n\t\t# METHOD_HOUGHLINES - image-based Hough line transform (requires scikit-image)\n\t\t# METHOD_PROBHOUGH - image-based Probabilistic Hough line transform (requires scikit-image)\n\t\tmethod=METHOD_NSQUREDLOGN,\n\t\t\n\t\t# window size when searching for trend lines prior to merging together\n\t\twindow=125,\n\t\t\n\t\t# maximum percentage slope standard error\n\t\terrpct = 0.005,\n\t\t\n\t\t# for all METHOD_*HOUGH*, the smallest unit increment for discretization e.g. cents/pennies 0.01\n\t\though_scale=0.01\n\t\t\n\t\t# only for METHOD_PROBHOUGH, number of iterations to run\n\t\though_prob_iter=10,\n\t\t\n\t\t# sort by area under wrong side of curve, otherwise sort by slope standard error\n\t\tsortError=False)\n\t# minimaIdxs - sorted list of indexes to the local minima\n\t# maximaIdxs - sorted list of indexes to the local maxima\n\t# pmin - [slope, intercept] of average best fit line through all local minima points\n\t# pmax - [slope, intercept] of average best fit line through all local maxima points\n\t# mintrend - sorted list containing (points, result) for local minima trend lines\n\t# maxtrend - sorted list containing (points, result) for local maxima trend lines\n\t\t# points - list of indexes to points in trend line\n\t\t# result - (slope, intercept, SSR, slopeErr, interceptErr, areaAvg)\n\t\t\t# slope - slope of best fit trend line\n\t\t\t# intercept - y-intercept of best fit trend line\n\t\t\t# SSR - sum of squares due to regression\n\t\t\t# slopeErr - standard error of slope\n\t\t\t# interceptErr - standard error of intercept\n\t\t\t# areaAvg - Reimann sum area of difference between best fit trend line\n\t\t\t# and actual data points averaged per time unit\n\t# minwindows - list of windows each containing mintrend for that window\n\t# maxwindows - list of windows each containing maxtrend for that window\n\nPlotting Calculations\n---------------------\nThe **plot_support_resistance** function will calculate and plot the average\nand top 2 support and resistance lines, along with marking extrema used with\na maximum history length, and otherwise identical arguments to the\ncalculation function.\n\n\tfig = plot_support_resistance(hist[-1000:].Close) # requires matplotlib - pip install matplotlib\n\tfig = plot_support_resistance(\n\t\thist,\n\t\txformatter = None, #x-axis data formatter turning numeric indexes to display output\n\t\t # e.g. ticker.FuncFormatter(func) otherwise just display numeric indexes\n\t\tnumbest = 2, #number of best support and best resistance lines to display\n\t\tfromwindows = True, #draw numbest best from each window, otherwise draw numbest across whole range\n\t\tpctbound = 0.1, # bound trend line based on this maximum percentage of the data range above the high or below the low\n\t\textmethod = METHOD_NUMDIFF,\n\t\tmethod=METHOD_NSQUREDLOGN,\n\t\twindow=125,\n\t\terrpct = 0.005,\n\t\though_prob_iter=10,\n\t\tsortError=False)\n\t# fig - returns matplotlib.pyplot.gcf() or the current figure\n\tplt.savefig('suppres.svg', format='svg')\n\tplt.show()\n\t\n\tfig = plot_sup_res_date(hist[-1000:].Close, hist[-1000:].index) #requires pandas\n\tfig = plot_sup_res_date( #automatic date formatter based on US trading calendar\n\t\thist,\n\t\tidx, #date index from pandas\n\t\tnumbest = 2,\n\t\tfromwindows = True,\n\t\tpctbound = 0.1,\n\t\textmethod = METHOD_NUMDIFF,\n\t\tmethod=METHOD_NSQUREDLOGN,\n\t\twindow=125,\n\t\terrpct = 0.005,\n\t\though_scale=0.01,\n\t\though_prob_iter=10,\n\t\tsortError=False)\n\t\n\tplot_sup_res_learn( #draw learning figures, included for reference material only\n\t\tcurdir, #base output directory for png and svg images, will be saved in 'data' subfolder\n\t\thist) #pandas DataFrame containing Close and date index\n\t\n![Example output of plotting support resistance](https://github.com/GregoryMorse/trendln/blob/master/img/suppres.svg)\n\nInstallation\n------------\n\nInstall ``trendln`` using ``pip``:\n\n $ pip install trendln --upgrade --no-cache-dir\n\n\nInstall ``trendln`` using ``conda``:\n\n $ conda install -c GregoryMorse trendln\n\nInstallation sanity check:\n\n\timport trendln\n\t#requires yfinance library install, not a package requirement, but used to assist with sanity check\n\t#pip install yfinance\n\tdirectory = '.' # a 'data' folder will be created here if not existing to store images\n\ttrendln.test_sup_res(directory) #simple tests that all methods are executing correct, assertion or other error indicates problem\n\nRequirements\n------------\n\n* [Python](https://www.python.org) >= 2.7, 3.4+\n* [numpy](http://www.numpy.org) >= 1.15\n* [findiff](https://github.com/maroba/findiff) >= 0.7.0 (if using default numerical differentiation method)\n* [scikit-image](https://scikit-image.org) >= 0.14.0 (if using image-based Hough line transform or its probabilistic variant)\n* [pandas](https://github.com/pydata/pandas) >= 0.23.1 (if using date plotting function, or using naive minima/maxima methods)\n* [matplotlib](https://matplotlib.org) >= 3.1.0 (if using any plotting function)\n\n\nLicense\n-------\n\n**trendln** is distributed under the **MIT License**. See the [LICENSE](./LICENSE) file in the release for details.\n\nSupport\n-------\n\nAny questions, issues or ideas can kindly be submitted for review.\n\n**Gregory Morse**\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/GregoryMorse/trendln", "keywords": "trendlines,trend lines,trend,support,resistance,trends,technical,indicators,financial,analysis", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "trendln", "package_url": "https://pypi.org/project/trendln/", "platform": "any", "project_url": "https://pypi.org/project/trendln/", "project_urls": { "Homepage": "https://github.com/GregoryMorse/trendln" }, "release_url": "https://pypi.org/project/trendln/0.1.8/", "requires_dist": null, "requires_python": "", "summary": "Support and Resistance Trend lines Calculator for Financial Analysis", "version": "0.1.8" }, "last_serial": 5970536, "releases": { "0.1.8": [ { "comment_text": "", "digests": { "md5": "74e0b4fe6479d46df39667cacd080af4", "sha256": "e2131c5e724258597f828e3210084d41f8eeedc38b462c8a33c9fbb772935f06" }, "downloads": -1, "filename": "trendln-0.1.8.tar.gz", "has_sig": false, "md5_digest": "74e0b4fe6479d46df39667cacd080af4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20498, "upload_time": "2019-10-14T09:05:35", "url": "https://files.pythonhosted.org/packages/fd/fa/f27aaf83119a7e76e099972e94979ba58860b6ad917bf16ebeee465f0b6b/trendln-0.1.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "74e0b4fe6479d46df39667cacd080af4", "sha256": "e2131c5e724258597f828e3210084d41f8eeedc38b462c8a33c9fbb772935f06" }, "downloads": -1, "filename": "trendln-0.1.8.tar.gz", "has_sig": false, "md5_digest": "74e0b4fe6479d46df39667cacd080af4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20498, "upload_time": "2019-10-14T09:05:35", "url": "https://files.pythonhosted.org/packages/fd/fa/f27aaf83119a7e76e099972e94979ba58860b6ad917bf16ebeee465f0b6b/trendln-0.1.8.tar.gz" } ] }