{ "info": { "author": "Jake Fowler", "author_email": "jake@cmdty.co.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Financial and Insurance Industry", "License :: OSI Approved :: MIT License", "Operating System :: Microsoft :: Windows", "Programming Language :: C#", "Programming Language :: Python :: 3", "Topic :: Office/Business :: Financial", "Topic :: Office/Business :: Financial :: Investment", "Topic :: Scientific/Engineering :: Mathematics", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "## Overview\n\nThe curves package contains a set of tools for building commodity forward, swaps, and futures curves.\n\nMore specifically, the problem being solved is to take a collection of traded forward prices, and tranform these into a \nforward curve of homogenous granularity. Additionally the derived curve can constructed to be in a granularity higher \nthan what is traded in the market.\n\nExamples of types of curve which can be constructed using this package:\n* Monthly granularity oil products swap curves from traded monthly, quarterly, and calendar yearly granularity\nmarket swap rates.\n* Daily granularity natural gas forward curves from traded daily, weekly, monthly, quarterly, seasonal, and\ngas year granularity forward and futures prices.\n* Half-hourly granularity power forward curves from traded daily, weekly, monthly, quarterly, and seasonal\ngranularity forward and futures prices.\n\nThe resulting curves should be consistent with inputs, in that they average back to the input forward contract prices.\nThis is a necessary to ensure that there are no arbitrage opportunities introduced between input contracts, and the derived forward curve.\n\n## Usage\nTwo functions in the curves package are the core of the curve building calculations; bootstrap_contracts and max_smooth_interp.\nSome basic examples of both of these function are given below. Both of these methods make extensive use of pandas, with\nthe pandas.Series used to represent forward curves, and pandas.Period for the delivery period of an input forward contract\nor derived forward curve.\n\nFor details of more advanced usage, view the docstrings for either of these functions and the Jupyter Notebook [curves_quick_start_tutorial](https://github.com/cmdty/curves/blob/master/samples/python/curves_quick_start_tutorial.ipynb).\n\n### Bootstrapper\nThe basic functionality of the method bootstrap_contracts is to take a set of forward prices, for contracts with overlapping \ndelivery/fixing periods, and return a curve with overlapping periods removed, but with prices consistent with the original inputs.\nBelow is a basic example showing prices for January and Q1 delivery period periods being bootstrapped into \nconsistent January, February and March forward prices.\n\n```python\nfrom curves import bootstrap_contracts\nfrom datetime import date\n\nq1_price = 19.05\ncontracts = [\n (date(2019, 1, 1), 18.95), # Jan-19\n (date(2019, 1, 1), date(2019, 3, 1), 19.05) # Q1-19\n]\npiecewise_curve, bootstrapped_contracts = bootstrap_contracts(contracts, freq='M')\nprint(piecewise_curve)\nprint()\nfor bc in bootstrapped_contracts:\n print(\"{0}, {1}, {2:.3f}\".format(repr(bc.start), repr(bc.end), bc.price))\n\n```\n\nThe above code prints to the following:\n```\n2019-01 18.950000\n2019-02 19.102542\n2019-03 19.102542\nFreq: M, dtype: float64\n\nPeriod('2019-01', 'M'), Period('2019-01', 'M'), 18.950\nPeriod('2019-02', 'M'), Period('2019-03', 'M'), 19.103\n```\n\n### Spline Interpolation\nIn order to facility creating a curve with higher granularity than the input contracts, the curves package includes the max_smooth_interp function. \nThis uses a maximum smoothness algorithm to interpolate input contracts with a fourth-order spline, whilst maintaining the average price constraints \ninherent in the input contract prices.\n\nThe example below creates a daily granularity curve, from input contracts of various granularities. As would usually be the case in a practical scenario, \nthe bootstrap_contracts method is first used to remove the overlaps from the contracts. The example below also shows how the input contracts can have gaps \nbetween them, which the spline will interpolate over, filling in the gaps in the final smooth curve. It also demonstrates the different ways of representing \nthe contract delivery period in the contract tuples and use of the helper module contract_period.\n\n```python\nfrom curves import max_smooth_interp\nfrom curves import contract_period as cp\n\ncontracts = [\n (date(2019, 5, 31), 34.875), \n (date(2019, 6, 1), date(2019, 6, 2), 32.87),\n ((date(2019, 6, 3), date(2019, 6, 9)), 32.14),\n (pd.Period(year=2019, month=6, freq='M'), 31.08),\n (cp.month(2019, 7), 29.95),\n (cp.q_3(2019), 30.18),\n (cp.q_4(2019), 37.64),\n (cp.winter(2019), 38.05),\n (cp.summer(2020), 32.39),\n (cp.winter(2020), 37.84),\n (cp.gas_year(2020), 35.12)\n]\n\npc_for_spline, bc_for_spline = bootstrap_contracts(contracts, freq='D')\nsmooth_curve = max_smooth_interp(bc_for_spline, freq='D')\n\nprint(smooth_curve)\n```\n\nThe above code prints to the following:\n```\n2019-05-31 34.875000\n2019-06-01 33.404383\n2019-06-02 32.335617\n2019-06-03 31.800171\n2019-06-04 31.676636\n2019-06-05 31.804146\n2019-06-06 32.057113\n2019-06-07 32.337666\n2019-06-08 32.575648\n2019-06-09 32.728620\n2019-06-10 32.781858\n2019-06-11 32.745075\n ... \n2021-09-19 26.727181\n2021-09-20 26.652039\n2021-09-21 26.576895\n2021-09-22 26.501749\n2021-09-23 26.426602\n2021-09-24 26.351454\n2021-09-25 26.276305\n2021-09-26 26.201156\n2021-09-27 26.126006\n2021-09-28 26.050856\n2021-09-29 25.975706\n2021-09-30 25.900556\nFreq: D, Length: 854, dtype: float64\n```\n\n\n\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/cmdty/curves", "keywords": "commodities trading curves oil gas power quantitative finance", "license": "", "maintainer": "", "maintainer_email": "", "name": "curves", "package_url": "https://pypi.org/project/curves/", "platform": "", "project_url": "https://pypi.org/project/curves/", "project_urls": { "Homepage": "https://github.com/cmdty/curves" }, "release_url": "https://pypi.org/project/curves/0.1.0b1/", "requires_dist": [ "pythonnet (>=2.4.0)", "pandas (>=0.24.2)" ], "requires_python": "", "summary": "Tools for building commodity forward, swaps, and futures curves.", "version": "0.1.0b1" }, "last_serial": 5717496, "releases": { "0.1.0a1": [ { "comment_text": "", "digests": { "md5": "e51fca9d75c85251781d9a63927f99e5", "sha256": "dd31fb094189373e36e97546761940fbcf4f10d8db8039836fa2aed897d0c3ad" }, "downloads": -1, "filename": "curves-0.1.0a1-py3-none-any.whl", "has_sig": false, "md5_digest": "e51fca9d75c85251781d9a63927f99e5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 647844, "upload_time": "2019-06-15T09:14:00", "url": "https://files.pythonhosted.org/packages/7a/61/63115d58fee64f61155e96b8de7206c38d7af84dfa1a72d5673e65ca5280/curves-0.1.0a1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d32ca9f662e76e1623628ade6dcf176f", "sha256": "07d34a740501bb280ee6774149510f65715b9074e6035981aaa2bb2f72b48411" }, "downloads": -1, "filename": "curves-0.1.0a1.tar.gz", "has_sig": false, "md5_digest": "d32ca9f662e76e1623628ade6dcf176f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 638089, "upload_time": "2019-06-15T09:14:04", "url": "https://files.pythonhosted.org/packages/52/cc/1f33ca1efa21b272d0070b3b79d3f49603b658187f227223de404379bc16/curves-0.1.0a1.tar.gz" } ], "0.1.0a2": [ { "comment_text": "", "digests": { "md5": "de1b0ec8bff482b4cb5d2d3e69d40fb9", "sha256": "56eaced8f7cf8a6918bdb9bf2e52cb980244b80b18d9fd64afdfd10c4d52b54a" }, "downloads": -1, "filename": "curves-0.1.0a2-py3-none-any.whl", "has_sig": false, "md5_digest": "de1b0ec8bff482b4cb5d2d3e69d40fb9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 647685, "upload_time": "2019-06-15T09:16:12", "url": "https://files.pythonhosted.org/packages/0e/4c/0f4311677278555c63295d5ad41b9387efb7a95f4fa1cc90180f31e4bc87/curves-0.1.0a2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "966307decddc1281816a8f94ceaad451", "sha256": "6e595c1888287b6a097f64e5a618fd4c1b2e1c687037a2fae600ddc5e7ed011b" }, "downloads": -1, "filename": "curves-0.1.0a2.tar.gz", "has_sig": false, "md5_digest": "966307decddc1281816a8f94ceaad451", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 637905, "upload_time": "2019-06-15T09:16:16", "url": "https://files.pythonhosted.org/packages/89/c9/675dc0220506f06c932128a901ca5ccf48dc513ee1c56a03d130a4547ebd/curves-0.1.0a2.tar.gz" } ], "0.1.0a3": [ { "comment_text": "", "digests": { "md5": "2ad599474617aa462d4f7545360b1546", "sha256": "4b3d56a80c6bcbcf259ced54b7df8c490e0df34140edfb5f2e3ed789af656fed" }, "downloads": -1, "filename": "curves-0.1.0a3-py3-none-any.whl", "has_sig": false, "md5_digest": "2ad599474617aa462d4f7545360b1546", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 661422, "upload_time": "2019-07-07T18:48:07", "url": "https://files.pythonhosted.org/packages/f3/2f/a35bb29aaeef1675f373fc22626ce77a7583dd31fbd9a73f6ed899c90196/curves-0.1.0a3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "400dc8ef6d1233ed7d9fbca149786267", "sha256": "923f7a8e469b294deb53efdff8e0d94265798d48e47b809148712732172becfe" }, "downloads": -1, "filename": "curves-0.1.0a3.tar.gz", "has_sig": false, "md5_digest": "400dc8ef6d1233ed7d9fbca149786267", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 652580, "upload_time": "2019-07-07T18:48:12", "url": "https://files.pythonhosted.org/packages/de/2b/e9752f2a067dd4442a7f29cdaa824f30b962a29ae59e1afc655d3517eba5/curves-0.1.0a3.tar.gz" } ], "0.1.0a5": [ { "comment_text": "", "digests": { "md5": "feee3df3459302fcc394fad5c102d18f", "sha256": "2f8fc53047b43dd9b91d7c24a656e62b0deb4ca7b35a762a87298e8717122830" }, "downloads": -1, "filename": "curves-0.1.0a5-py3-none-any.whl", "has_sig": false, "md5_digest": "feee3df3459302fcc394fad5c102d18f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 662962, "upload_time": "2019-07-30T05:25:41", "url": "https://files.pythonhosted.org/packages/28/15/49eaa401118eddf22b9e46d5591edb533e9bea31bd68f328135ec3dfa08c/curves-0.1.0a5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7adcd154813892d84b4398ae377f5b5a", "sha256": "f8ea48f5bb4166df4aac234ad3afce8d4fc66a09678e25763065e8c7a90f05ab" }, "downloads": -1, "filename": "curves-0.1.0a5.tar.gz", "has_sig": false, "md5_digest": "7adcd154813892d84b4398ae377f5b5a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11446, "upload_time": "2019-07-30T05:25:43", "url": "https://files.pythonhosted.org/packages/b7/c6/30c974a86b1fd6943fe805cdd7447113547e7425f6aaf21ab1c243e1b92e/curves-0.1.0a5.tar.gz" } ], "0.1.0b1": [ { "comment_text": "", "digests": { "md5": "6e6cd2931c8d16489594b58062539066", "sha256": "d2d895a9e896d8b433ed19e9f8b5fd2928c391ad47f1284da00e5d3e45921a0f" }, "downloads": -1, "filename": "curves-0.1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "6e6cd2931c8d16489594b58062539066", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 663704, "upload_time": "2019-08-22T21:33:30", "url": "https://files.pythonhosted.org/packages/8f/79/0c4aaa89452448135896e7db82811b722c9f8268e601bdcb4aa0a65d2b1e/curves-0.1.0b1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f14e3eb3948bce72eec1456e81ff2448", "sha256": "94ca9b4078c40a83083e47c493eeb9435de12a9d97354b7d0048904d46d6bc40" }, "downloads": -1, "filename": "curves-0.1.0b1.tar.gz", "has_sig": false, "md5_digest": "f14e3eb3948bce72eec1456e81ff2448", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11345, "upload_time": "2019-08-22T21:33:32", "url": "https://files.pythonhosted.org/packages/a6/e3/97f462362605482f5eab516ca5280aa9a1fca4fa54e1e9a12847b29bc364/curves-0.1.0b1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6e6cd2931c8d16489594b58062539066", "sha256": "d2d895a9e896d8b433ed19e9f8b5fd2928c391ad47f1284da00e5d3e45921a0f" }, "downloads": -1, "filename": "curves-0.1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "6e6cd2931c8d16489594b58062539066", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 663704, "upload_time": "2019-08-22T21:33:30", "url": "https://files.pythonhosted.org/packages/8f/79/0c4aaa89452448135896e7db82811b722c9f8268e601bdcb4aa0a65d2b1e/curves-0.1.0b1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f14e3eb3948bce72eec1456e81ff2448", "sha256": "94ca9b4078c40a83083e47c493eeb9435de12a9d97354b7d0048904d46d6bc40" }, "downloads": -1, "filename": "curves-0.1.0b1.tar.gz", "has_sig": false, "md5_digest": "f14e3eb3948bce72eec1456e81ff2448", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11345, "upload_time": "2019-08-22T21:33:32", "url": "https://files.pythonhosted.org/packages/a6/e3/97f462362605482f5eab516ca5280aa9a1fca4fa54e1e9a12847b29bc364/curves-0.1.0b1.tar.gz" } ] }