A downloader of historical daily returns for multiple investable assets with some analysis tools too.
Project description
Asset Universe
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file assetuniverse-0.1.1.tar.gz
.
File metadata
- Download URL: assetuniverse-0.1.1.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ed4b64bff150389ad01a91601096d6cf5cb51fa4c0987b6b962e489193e7c0d |
|
MD5 | 18043c40f6e3c3f607ec10ac3c12cc74 |
|
BLAKE2b-256 | 2f302cffe224c6343e3421f0cf2dcad6b59450c362d08f5f1fcefbdfea72c894 |
File details
Details for the file assetuniverse-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: assetuniverse-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63a704a361a13fad4bc6660dfda05eb0aeab0ea65e73269f4ad47a19710a28ed |
|
MD5 | 15cdc5434b0e7213c6e212ed79513cab |
|
BLAKE2b-256 | 46459ae04725dd85f0bed346711f43528e23b35357681259bd437c22b1c98a79 |