assetuniverse


Nameassetuniverse JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA downloader of historical daily returns for multiple investable assets with some analysis tools too.
upload_time2024-04-28 21:41:07
maintainerNone
docs_urlNone
authorMatthew Trotter
requires_python>=3.7
licenseGPL-3.0-or-later
keywords historical returns returns daily returns stocks futures commodities interactive brokers yahoo finance fred
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Asset Universe
==============

![Python Package](https://github.com/matthewtrotter/assetuniverse/workflows/Python%20package/badge.svg)

Download historical daily prices and returns of stocks, futures, cryptocurrencies, and fiat currencies. Plot historical returns and calculate correlation and covariance matrices. Asset Universe downloads historical data from the following sources:

- [Interactive Brokers Trader Workstation](https://www.interactivebrokers.com/en/trading/tws.php)
- [Yahoo Finance](https://finance.yahoo.com/)
- [Federal Reserve Economic Database](https://fred.stlouisfed.org)

## Installing
Install the [package with pip](https://pypi.org/project/assetuniverse/0.1.0/#description):
```bash
pip install assetuniverse
```

## Using
```python
import datetime
from assetuniverse import Asset, AssetUniverse

# Set start date, end date, and assets to download
days = 2*365    # 2 years
end = datetime.date.today()
start = end - datetime.timedelta(days=days)
assets = [
    Asset(start, end, 'AAPL'),
    Asset(start, end, 'CL=F', readable_name='Oil'),
    Asset(start, end, 'EURUSD=X'),
]
cashasset = Asset(start, end, 'VFISX', readable_name='Cash')

# Download the daily returns of the assets
AU = AssetUniverse(start, end, assets, cashasset)
AU.download()

# Print returns and prices
print(AU.returns())
print(AU.prices())

# Plot price history in a webpage.
# Prices are normalized to start at $1.
AU.plot_prices()

# Print covariance and correlation matrices
print(AU.correlation_matrix())  # correlation matrix over entire history
print(AU.correlation_matrix(
    ['AAPL', 'CL=F'],   # only of these two assets
    start=end - datetime.timedelta(days=30) # over past month
    ))
print(AU.covariance_matrix(
    ['AAPL', 'CL=F']
    ))
```

### Cash Asset
The `AssetUniverse` class requires you to specify a cash asset. This is the risk-free asset that the portfolio can invest in. For example, the Vanguard fund `VFISX` is a money market fund that invests in short-term U.S. government securities. 
```python
cashasset = Asset(start, end, 'VFISX', readable_name='Cash')
AU = AssetUniverse(start, end, assets, cashasset)
```

### Margin Borrowing Rate
The `AssetUniverse` class calculates a typical margin borrowing rate for each asset. The default rate is calculated as the 30-day Federal Funds Effective Rate plus a 1.5% spread. The rate is used to calculate the daily cost of borrowing money on margin in order to buy stock above the portfolio net asset value or short a stock. You can specify your own spread:
    
```python
# Set the borrow spread to 3.0%
AU = AssetUniverse(start, end, assets, cashasset, borrow_spread=3.0)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "assetuniverse",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "historical returns, returns, daily returns, stocks, futures, commodities, interactive brokers, yahoo finance, fred",
    "author": "Matthew Trotter",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/2f/30/2cffe224c6343e3421f0cf2dcad6b59450c362d08f5f1fcefbdfea72c894/assetuniverse-0.1.1.tar.gz",
    "platform": null,
    "description": "Asset Universe\n==============\n\n![Python Package](https://github.com/matthewtrotter/assetuniverse/workflows/Python%20package/badge.svg)\n\nDownload historical daily prices and returns of stocks, futures, cryptocurrencies, and fiat currencies. Plot historical returns and calculate correlation and covariance matrices. Asset Universe downloads historical data from the following sources:\n\n- [Interactive Brokers Trader Workstation](https://www.interactivebrokers.com/en/trading/tws.php)\n- [Yahoo Finance](https://finance.yahoo.com/)\n- [Federal Reserve Economic Database](https://fred.stlouisfed.org)\n\n## Installing\nInstall the [package with pip](https://pypi.org/project/assetuniverse/0.1.0/#description):\n```bash\npip install assetuniverse\n```\n\n## Using\n```python\nimport datetime\nfrom assetuniverse import Asset, AssetUniverse\n\n# Set start date, end date, and assets to download\ndays = 2*365    # 2 years\nend = datetime.date.today()\nstart = end - datetime.timedelta(days=days)\nassets = [\n    Asset(start, end, 'AAPL'),\n    Asset(start, end, 'CL=F', readable_name='Oil'),\n    Asset(start, end, 'EURUSD=X'),\n]\ncashasset = Asset(start, end, 'VFISX', readable_name='Cash')\n\n# Download the daily returns of the assets\nAU = AssetUniverse(start, end, assets, cashasset)\nAU.download()\n\n# Print returns and prices\nprint(AU.returns())\nprint(AU.prices())\n\n# Plot price history in a webpage.\n# Prices are normalized to start at $1.\nAU.plot_prices()\n\n# Print covariance and correlation matrices\nprint(AU.correlation_matrix())  # correlation matrix over entire history\nprint(AU.correlation_matrix(\n    ['AAPL', 'CL=F'],   # only of these two assets\n    start=end - datetime.timedelta(days=30) # over past month\n    ))\nprint(AU.covariance_matrix(\n    ['AAPL', 'CL=F']\n    ))\n```\n\n### Cash Asset\nThe `AssetUniverse` class requires you to specify a cash asset. This is the risk-free asset that the portfolio can invest in. For example, the Vanguard fund `VFISX` is a money market fund that invests in short-term U.S. government securities. \n```python\ncashasset = Asset(start, end, 'VFISX', readable_name='Cash')\nAU = AssetUniverse(start, end, assets, cashasset)\n```\n\n### Margin Borrowing Rate\nThe `AssetUniverse` class calculates a typical margin borrowing rate for each asset. The default rate is calculated as the 30-day Federal Funds Effective Rate plus a 1.5% spread. The rate is used to calculate the daily cost of borrowing money on margin in order to buy stock above the portfolio net asset value or short a stock. You can specify your own spread:\n    \n```python\n# Set the borrow spread to 3.0%\nAU = AssetUniverse(start, end, assets, cashasset, borrow_spread=3.0)\n```\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "A downloader of historical daily returns for multiple investable assets with some analysis tools too.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [
        "historical returns",
        " returns",
        " daily returns",
        " stocks",
        " futures",
        " commodities",
        " interactive brokers",
        " yahoo finance",
        " fred"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46459ae04725dd85f0bed346711f43528e23b35357681259bd437c22b1c98a79",
                "md5": "15cdc5434b0e7213c6e212ed79513cab",
                "sha256": "63a704a361a13fad4bc6660dfda05eb0aeab0ea65e73269f4ad47a19710a28ed"
            },
            "downloads": -1,
            "filename": "assetuniverse-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "15cdc5434b0e7213c6e212ed79513cab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 22153,
            "upload_time": "2024-04-28T21:41:06",
            "upload_time_iso_8601": "2024-04-28T21:41:06.217896Z",
            "url": "https://files.pythonhosted.org/packages/46/45/9ae04725dd85f0bed346711f43528e23b35357681259bd437c22b1c98a79/assetuniverse-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f302cffe224c6343e3421f0cf2dcad6b59450c362d08f5f1fcefbdfea72c894",
                "md5": "18043c40f6e3c3f607ec10ac3c12cc74",
                "sha256": "9ed4b64bff150389ad01a91601096d6cf5cb51fa4c0987b6b962e489193e7c0d"
            },
            "downloads": -1,
            "filename": "assetuniverse-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "18043c40f6e3c3f607ec10ac3c12cc74",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 22105,
            "upload_time": "2024-04-28T21:41:07",
            "upload_time_iso_8601": "2024-04-28T21:41:07.868701Z",
            "url": "https://files.pythonhosted.org/packages/2f/30/2cffe224c6343e3421f0cf2dcad6b59450c362d08f5f1fcefbdfea72c894/assetuniverse-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-28 21:41:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "assetuniverse"
}
        
Elapsed time: 0.24543s