Skip to main content

Asset Universe

Python Package

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:

Installing

Install the package with pip:

pip install assetuniverse

Using

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.

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:

# Set the borrow spread to 3.0%
AU = AssetUniverse(start, end, assets, cashasset, borrow_spread=3.0)

Metadata

Release files for assetuniverse 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for assetuniverse 0.1.1
File Size Uploaded Provenance
assetuniverse-0.1.1.tar.gz 22.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for assetuniverse 0.1.1
File Interpreter ABI Platform
assetuniverse-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 44.3 kB

Release files / assetuniverse-0.1.1.tar.gz

Download URL assetuniverse-0.1.1.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ed4b64bff150389ad01a91601096d6cf5cb51fa4c0987b6b962e489193e7c0d
BLAKE2b-256 checksum
How to use checksums
2f302cffe224c6343e3421f0cf2dcad6b59450c362d08f5f1fcefbdfea72c894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / assetuniverse-0.1.1-py3-none-any.whl

Download URL assetuniverse-0.1.1-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63a704a361a13fad4bc6660dfda05eb0aeab0ea65e73269f4ad47a19710a28ed
BLAKE2b-256 checksum
How to use checksums
46459ae04725dd85f0bed346711f43528e23b35357681259bd437c22b1c98a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Security for assetuniverse 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page