A comprehensive suite of Python-based financial analysis tools for portfolio management, risk assessment, strategy backtesting, and market data analysis. Provides practical implementations of modern portfolio theory, risk metrics, and quantitative trading strategies, designed for both learning and real-world application.
To get started, ensure you have Python and uv installed on your system. Once both are set up, follow these steps to configure the project:
Clone this repository to your local machine:
git clone https://github.com/gabrielpalassi/FinancialMarketPython.gitNavigate to the repository folder:
cd FinancialMarketPythonInstall dependencies using uv:
uv syncNow you're ready to use the programs!
uv run main.pyBelow are the financial analysis tools available in this repository. Each program provides detailed instructions when executed.
Backtest a weighted portfolio to evaluate historical performance. This tool calculates cumulative returns for your entire portfolio and compares it against individual asset performance, providing insights into how your asset allocation performed over time.
Optimize portfolio asset allocation using Modern Portfolio Theory. Visualize the efficient frontier and find optimal portfolio weights based on three strategies: maximizing the Sharpe ratio for best risk-adjusted returns, targeting a specific expected return with minimal risk, or maximizing returns within a defined risk tolerance.
Analyze drawdown patterns to understand potential losses from peak values. This tool calculates and visualizes the maximum drawdown for individual assets or entire portfolios, helping you assess historical downside risk.
Calculate Value at Risk using historical simulation methodology. Estimate potential losses at customizable confidence levels (e.g., 95%, 99%) for individual assets or portfolios across daily, monthly, and yearly periods, providing a comprehensive risk assessment.
Evaluate a momentum-based investment strategy that allocates capital based on prior month performance. This model invests in IBOV (Brazilian stock index) when it outperformed CDI (Brazilian risk-free rate) in the previous month, and switches to CDI otherwise.
Test a trend-following strategy using moving averages as entry and exit signals. This model invests in IBOV when the previous month's closing price exceeds the moving average, indicating an uptrend, and allocates to CDI during downtrends for capital preservation.
Backtest a mean reversion strategy using Bollinger Bands technical indicator. This tool generates long signals when price crosses below the lower band (expecting reversion upward) and short signals when price crosses above the upper band (expecting reversion downward). Customizable window periods and standard deviation multipliers allow you to fine-tune the strategy parameters.
Access and analyze historical economic data from the Brazilian Central Bank (Banco Central do Brasil). Query various indicators including interest rates (SELIC), inflation metrics (IPCA, IGP-M), and exchange rates to support macroeconomic analysis.
Retrieve market expectations data compiled by the Brazilian Central Bank through its FOCUS survey. Analyze consensus forecasts for key economic indicators such as interest rates, inflation, exchange rates, and GDP growth to inform investment decisions.
We welcome contributions to this repository. If you have ideas for new programs, bug fixes, or improvements, please open an issue or submit a pull request.








