Tool to help find an optimal portfolio allocation
Project description
Porfolio Finder
A Python library, based primarily around pandas, to identify an optimal portfolio allocation through back-testing.
API Documentation is available on Read the Docs.
Example Usage
Each of these examples make use of data.csv which provides returns for a handful of funds over 1970-2019.
Find best portfolio allocation to minimize the required timeframe to achieve a target value
import portfoliofinder as pf
contributions = pf.RegularContributions(100000, 10000)
print(pf.Allocations(0.05, ['USA_TSM', 'WLDx_TSM', 'USA_INT', 'EM'])\
.filter('USA_TSM>=0.6 & WLDx_TSM<=0.2 & USA_INT>=0.3')\
.with_returns(csv="data.csv")\
.with_regular_contributions(100000, 10000)\
.get_backtested_values(timeframe=10)\
.get_statistics(['min', 'max', 'mean', 'std'])\
.filter_by_min_of('max')\
.filter_by_max_of('min')\
.get_allocation_which_min_statistic('std'))
Output
Statistic
min 14.000000
max 22.000000
mean 16.965517
std 2.809204
Name: Allocation(USA_TSM=0.65, WLDx_TSM=0.0, USA_INT=0.3, EM=0.05), dtype: float64
Find best portfolio allocation to maximize value with minimal risk over a fixed timeframe
import portfoliofinder as pf
print(pf.Allocations(0.05, ['USA_TSM', 'WLDx_TSM', 'USA_INT', 'EM'])\
.filter('USA_TSM>=0.6 & WLDx_TSM<=0.2 & USA_INT>=0.3')\
.with_returns(csv="data.csv")\
.with_regular_contributions(100000, 10000)\
.get_backtested_values(timeframe=10)\
.get_statistics(['mean', 'std'])\
.filter_by_gte_percentile_of(90, 'mean')\
.get_allocation_which_min_statistic('std'))
Output
Statistic
mean 446560.590088
std 117448.007302
Name: Allocation(USA_TSM=0.6, WLDx_TSM=0.0, USA_INT=0.3, EM=0.1), dtype: float64
Graph statistics from multiple portfolio allocations to visualize their efficient frontier
import portfoliofinder as pf
allocations = pf.Allocations(0.05, ['USA_TSM', 'WLDx_TSM', 'USA_INT', 'EM'])\
.filter('USA_TSM>=0.2 & USA_INT>=0.2')\
.with_returns(csv="data.csv")\
.with_regular_contributions(100000, 10000)\
.get_backtested_values(timeframe=10)\
.get_statistics()\
.graph('std', 'mean')
Output
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
portfoliofinder-0.1.tar.gz
(2.7 kB
view hashes)
Built Distributions
Close
Hashes for portfoliofinder-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d82bc2ee7faccbe8ed3862c706602774d7d450670088634b52a743e560bc30c |
|
MD5 | 586edbd4a91e2b25ec4cfdbaec6b1239 |
|
BLAKE2b-256 | adac23b50f4cb6eb2b3ca4a15ff3999671e25607e7c8357999e874128a68eec8 |
Close
Hashes for portfoliofinder-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade60d1d0358f75bf9587ba68146c3d0be1493545bd34f3f273e501c5a7dfe1f |
|
MD5 | 914137e48cc461ba893f1858edf4532d |
|
BLAKE2b-256 | 4a98573c190d1b4be6be5462b35b63674b9b8c26b8ec173ea8224d8e81dede12 |