from terms import terms, Engine
portfolio = Engine(
start_date = "2018-06-09",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
weights = [0.2, 0.2, 0.2, 0.2, 0.2], # equal weighting is set by default
benchmark = ["SPY"] # SPY is set by default
)
terms(portfolio)
A portfolio can be rebalanced for either a specific time period or for specific dates using the rebalance
option.
Time periods available for rebalancing are
2y
, 1y
, 6mo
, quarterly
, monthly
from terms import terms, Engine
portfolio = Engine(
start_date = "2018-06-09",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
weights = [0.2, 0.2, 0.2, 0.2, 0.2], # equal weighting is set by default
benchmark = ["SPY"], # SPY is set by default
rebalance = "1y"
)
terms(portfolio)
You can rebalance a portfolio by specifying a list of custom dates.
start_date
and the last element should correspond to the end_date
which is today"s date by default.
from terms import terms, Engine
portfolio = Engine(
start_date = "2018-06-09",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
weights = [0.2, 0.2, 0.2, 0.2, 0.2], # equal weighting is set by default
benchmark = ["SPY"], # SPY is set by default
rebalance = ["2018-06-09", "2019-01-01", "2020-01-01", "2021-01-01"]
)
terms(portfolio)
The default optimizer is equal weighting. You can specify custom weights, if desired.
from terms import terms, Engine
portfolio = Engine(
start_date = "2018-01-01",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
weights = [0.1, 0.3, 0.15, 0.25, 0.2], # custom weights
rebalance = "1y" # rebalance every year
)
terms(portfolio)
You can also use the built-in optimizers. There are 4 optimizers available:
"EF"
: Global Efficient Frontier Example"MEANVAR"
: Mean-Variance Example"HRP"
: Hierarchical Risk Parity Example"MINVAR"
: Minimum-Variance Example
from terms import terms, Engine
portfolio = Engine(
start_date = "2018-01-01",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "EF",
rebalance = "1y" # rebalance every year
)
portfolio.weights
Output:
[0.0, 0.0, 0.0348, 0.9652, 0.0]
We can see that the allocation has been optimized.
3 Risk Managers are available:
- Max Drawdown:
{"Max Drawdown" : -0.3}
Example - Take Profit:
{"Take Profit" : 0.4}
Example - Stop Loss:
{"Stop Loss" : -0.2}
Example
from terms import terms, Engine
portfolio = Engine(
start_date = "2018-01-01",
portfolio= ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "EF",
rebalance = "1y", # rebalance every year
risk_manager = {"Max Drawdown" : -0.2} # Stop the investment when the drawdown becomes superior to -20%
)
terms(portfolio)
You can use the get_report()
function of terms to generate a tearsheet, and then download this as a PDF document.
from terms import get_report, Engine
portfolio = Engine(
start_date = "2018-01-01",
portfolio = ["BABA", "PDD", "KO", "AMD","^IXIC"],
optimizer = "EF",
rebalance = "1y", #rebalance every year
risk_manager = {"Stop Loss" : -0.2}
)
get_report(portfolio)
Output:
terms uses GitHub to host its source code. Learn more about the Github flow.
For larger changes (e.g., new feature request, large refactoring), please open an issue to discuss first.
- If you wish to create a new Issue, then click here to create a new issue.
Smaller improvements (e.g., document improvements, bugfixes) can be handled by the Pull Request process of GitHub: pull requests.
-
To contribute to the code, you will need to do the following:
-
Fork terms - Click the Fork button at the upper right corner of this page.
-
Clone your own fork. E.g.,
git clone https://github.com/ssantoshp/terms.git
If your fork is out of date, then will you need to manually sync your fork: Synchronization method -
Create a Pull Request using your fork as the
compare head repository
.
You contributions will be reviewed, potentially modified, and hopefully merged into terms.
Thanks goes to these wonderful people (emoji key):
Brendan Glancy 💻 🐛 |
Renan Lopes 💻 🐛 |
Mark Thebault 💻 |
Diego Alvarez 💻🐛 |
Rakesh Bhat 💻 |
Anh Le 🐛 |
Tony Zhang 💻 |
Ikko Ashimine ✒️ |
QuantNomad 📹 |
Buckley ✒️💻 |
Adam Nelsson 💻 |
Ranjan Grover 🐛💻 |
This project follows the all-contributors specification. Contributions of any kind are welcome!
This library has also been made possible because of the work of these incredible people:
- Ran Aroussi for the Quantstats library
- Robert Martin for the PyPortfolioOpt
You are welcome to contact us by email at [email protected] or in terms"s discussion space
MIT