
Explore backtesting and modern portfolio theory with python, building a backtesting engine using riskfolio lib to optimize diversified s&p 500 portfolios and generate actionable insights.
Explore the end product in the main notebook file, run back tests, analyze growth rate, and visualize results using the back test class, analytics class, and database.
Explore how a modern portfolio theory allocation would have performed by backtesting over the last 20 years, using the risk folio library to compute allocations, rebalance periods, and parameter variations.
Install and verify a Python 3.0+ environment and open the downloaded zip using VS Code to begin coding in a popular IDE.
Extract the zip file, open the correct root folder in VS Code, and avoid conflicts by ensuring the right folder level.
Explore the downloaded zip's folder containing a database folder, a py file, a csv, a large database, analytics.py, a backtest class, a main notebook, a requirements.txt, and a .gitignore.
Set up a Python virtual environment, activate and deactivate it, and install libraries from requirements.txt with pip, noting platform differences for Windows and Mac.
Explore the project architecture for a Python backtest of risk parity portfolios, including the back test class and a notebook-style main file with parameter-driven setup for dates, lookback, and allocations.
Walk through project architecture for a Python backtest, including an analytics module with Sharpe ratio and annual return, a local SQL database, and a S&P 500 stock universe.
Master how to connect to a sqlite3 database for backtesting, retrieve prices with get price and get prices, and safely close the connection using a dedicated database utility class.
Browse a sqlite database to inspect stocks data, filter tickers like apple, review the two tables, benchmark and sp 500 data, and run simple sql queries in python.
Explore the Riskfolio library to visualize allocations with pie charts and select risk-based portfolios along the efficient frontier using different risk measures and constraints.
Learn how Riskfolio guides you from asset data to optimized weights and an efficient frontier for risk parity backtesting. Enforce 10% per asset and industry diversification.
Verify your setup by opening the main Jupyter notebook, selecting the correct Python environment, and running cells to confirm the virtual environment and libraries work for backtests.
Explains how self in Python refers to the instance within a class, enabling methods to access and modify attributes and call other methods via self.
Explore how the backtest class processes data bar by bar with on_bar function. Pull SPY data from a SQL database, iterate trading days, and record the portfolio with timing metrics.
Rebalance the portfolio by stepping through trading days, computing days since last rebalance, and triggering updates when the period (e.g., 90 days) elapses, while printing charts of Sharpe ratios.
Rebalance the portfolio by computing liquid cash worth, deriving new weights, saving allocations, and reallocating holdings, timing the process with lookback data and risk folio calculation.
Rebalance by generating new weights after liquidating to cash, then buy stocks. Record allocations in a date symbol weight dataframe for future reference.
Learn how the generation allocation weights function determines the rebalancing date, fetches historical price data for valid tickers on trading days, and computes new weights via risk folio calculation function.
Validate data for the SPI risk folio by ensuring sufficient lookback data and forward data to the next rebalance date, using get tickers for date to filter valid tickers.
Set a test mode flag by assigning self.test_mode from the test mode parameter at the file's start and constrain valid tickers to the first 20.
Explore how the get prices function pulls data for symbols, builds a symbol list, runs an SQL query, and prepares data for risk folio allocation and generate allocation weights function.
Build a Risk Folio allocation by processing assets, date, and data, apply long/short budgets, set a Sharpe-based optimization with historical scenarios and asset constraints.
Execute the rebalance logic to generate and apply allocation weights, record daily portfolio data, and lay the groundwork for upcoming analytics.
Record daily portfolio snapshots by liquidating holdings, compute daily balance from cash and weights and shares, and value each symbol using today's prices to aggregate performance.
Record portfolio part 2 loops symbols to capture shares, price, value, and weight, recording daily balance in a portfolio data frame for analytics.
Instantiate the database class and open a single sqlite3 connection to the configured Rocksdb database, enabling efficient retrieval of prices, tickers, and S&P 500 universe data.
Set up and run a backtest in a Jupyter notebook, adjusting start and end dates, lookback windows, rebalance periods, and long-short allocations using the risk folio library.
Explore the backtest object and portfolio data frame to review daily balances, symbol weights, prices, values, and shares across 190 days, with 90-day blocks for analytics.
Explore two methods to run analytics, compare portfolio and benchmark results around 13%, and visualize data with interactive charts to spot anomalies.
Print the portfolio balance and benchmark data to understand the backtest data structures. Compute returns, compounding growth, Sharpe ratio, and max drawdown using the backtest analytics.
Normalize the data by dividing each series by the first value and scaling by the starting cash, then plot a Plotly figure comparing portfolio and benchmark.
Use the empirical library to perform performance analytics on a backtest, computing returns, Sharpe ratio, drawdown, value at risk, alpha, beta, and benchmark comparisons.
Explore back test analytics and performance analytics in the empirical library, validating percentage calculations against spy benchmark data while reloading modules and using a starting cache.
Dive into the world of portfolio management with our comprehensive course that teaches you how to build an iterative Python backtester from scratch, specialized for Risk Parity strategies. This course is meticulously tailored to guide finance professionals, traders, and investment enthusiasts through the intricacies of constructing and analyzing risk parity portfolios using Python's powerful programming capabilities.
Throughout this course, you will:
Understand the foundational concepts of Risk Parity and why it is a preferred method for portfolio construction.
Learn how to code a backtesting environment in Python that can simulate trading strategies and evaluate their historical performance.
Gain hands-on experience with data retrieval, cleansing, and manipulation using Python's renowned libraries such as Pandas and NumPy.
Explore portfolio optimization techniques, including how to apply leverage and balance asset classes to achieve desired risk levels.
Master the art of visualizing complex financial data to make informed decisions, using libraries such as Matplotlib and Plotly
Discover advanced risk management concepts and learn to integrate them into your backtesting framework to develop robust investment strategies.
Engage with real-world case studies that will take you through the journey of backtesting and optimizing risk parity portfolios in a step-by-step process
By the end of this course, you will be equipped with the practical skills to implement risk parity strategies, the knowledge to enhance them with custom risk management techniques, and the confidence to apply Python's versatile tools to optimize your investment portfolio. Whether you're looking to manage your investments, advance your career, or simply gain a deeper understanding of portfolio management, this course is your gateway to success in the realm of Risk Parity Portfolio Management.
Join us on this educational adventure and transform the way you think about and manage risk in your investment portfolio.