Python library to make development of portfolio analysis faster and easier
For the moment, Trafalgar is still in beta development. To install it you should:
- Download trafalgars-0.0.1-py3-none-any.whl in the folder you want
- Go to your folder with the command prompt and write :
pip install trafalgars-0.0.1-py3-none-any.whl
- Get close price, open price, adj close, volume and graphs of these in one line of code!
- Build a efficient frontier programm in 3 lines of code
- Backtest a portfolio, see its stats and compare it to a benchmark
#graph_close(stock, start_date, end_date)
graph_close(["FB"], "2020-01-01", "2021-01-01")
graph_close(["FB", "AAPL", "TSLA"], "2020-01-01", "2021-01-01")
#graph_volume(stock, start_date, end_date)
#for one stock
graph_volume(["FB"], "2020-01-01", "2021-01-01")
#for multiple stocks
graph_volume(["FB", "AAPL", "TSLA"], "2020-01-01", "2021-01-01")
#graph_open(stock, start_date, end_date)
#for one stock
graph_open(["FB"], "2020-01-01", "2021-01-01")
#for multiple stocks
graph_open(["FB", "AAPL", "TSLA"], "2020-01-01", "2021-01-01")
#graph_adj_close(stock, start_date, end_date)
#for one stock
graph_adj_close(["FB"], "2020-01-01", "2021-01-01")
#for multiple stocks
graph_adj_close(["FB", "AAPL", "TSLA"], "2020-01-01", "2021-01-01")
#returns_graph(stock, start_date, end_date)
#this one only work for one stock
returns_graph(["FB"], "2020-01-01", "2021-01-01")
#close(stock, start_date, end_date)
close(["AAPL"], "2020-01-01", "2021-01-01")
#volume(stock, start_date, end_date)
volume(["AAPL"], "2020-01-01", "2021-01-01")
#open(stock, start_date, end_date)
open(["AAPL"], "2020-01-01", "2021-01-01")
#adj_close(stock, start_date, end_date)
adj_close(["AAPL"], "2020-01-01", "2021-01-01")
#covariance(stocks, start_date, end_date, days) -> usually, days = 252
covariance(["AAPL", "DIS", "AMD"], "2020-01-01", "2021-01-01", 252)
#ohlcv(stock, start_date, end_date)
ohlcv("AAPL", "2020-01-01", "2021-01-01")
#cum_returns_graph(stocks, weights, start_date, end_date)
cum_returns_graph(["FB", "AAPL", "AMD"], [0.3, 0.4, 0.3],"2020-01-01", "2021-01-01")
#cum_returns(stocks, weights, start_date, end_date)
cum_returns(["FB", "AAPL", "AMD"], [0.3, 0.4, 0.3],"2020-01-01", "2021-01-01")
#annual_volatility(stocks, weights, start_date, end_date)
annual_volatility(["FB", "AAPL", "AMD"], [0.3, 0.4, 0.3],"2020-01-01", "2021-01-01")
#sharpe_ratio(stocks, weights, start_date, end_date)
sharpe_ratio(["FB", "AAPL", "AMD"], [0.3, 0.4, 0.3],"2020-01-01", "2021-01-01")
#returns_benchmark(stocks, weights, benchmark, start_date, end_date)
returns_benchmark(["AAPL", "AMD", "MSFT"], [0.3, 0.4, 0.3], "SPY", "2020-01-01", "2021-01-01")
Blue line : returns of your portfolio Red line : returns of the benchmark
#cum_returns_benchmark(stocks, weights, benchmark, start_date, end_date)
cum_returns_benchmark(["AAPL", "AMD", "MSFT"], [0.3, 0.4, 0.3], "SPY", "2020-01-01", "2021-01-01")
Blue line : cumulative returns of your portfolio Red line : cumulative returns of the benchmark
#alpha_beta(stocks, weights, benchmark, start_date, end_date)
alpha_beta(["AAPL", "AMD", "MSFT"], [0.3, 0.4, 0.3], "SPY", "2020-01-01", "2021-01-01")
#efficient_frontier(stocks, start_date, end_date, iterations) -> iterations = 10000 is a good starting point
efficient_frontier(["AAPL", "FB", "TSLA", "BABA"], "2020-01-01", "2021-01-01", 10000)
#individual_cum_returns_graph(stocks, start_date, end_date)
individual_cum_returns_graph(["FB", "AAPL", "AMD"],"2020-01-01", "2021-01-01")
#individual_cum_returns(stocks, start_date, end_date)
individual_cum_returns(["FB", "AAPL", "AMD"],"2020-01-01", "2021-01-01")
#individual_mean_daily_return(stocks, start_date, end_date)
individual_mean_daily_return(["FB", "AAPL", "AMD"],"2020-01-01", "2021-01-01")
#portfolio_daily_mean_return(stocks,weights, start_date, end_date)
individual_mean_daily_return(["FB", "AAPL", "AMD"],"2020-01-01", "2021-01-01")
#VaR(stock, start_date, end_date, confidence_level)
VaR("FB","2020-01-01", "2021-01-01", 98)
MIT