Skip to content

Facilitates investment planning by S&P 500 sector analysis based on historical data. A weighted custom portfolio is built based on analysis using Python and Pandas. Then a Monte Carlo simulation is ran to forecast performance.

Notifications You must be signed in to change notification settings

dldmarnell/sector-dominance

Repository files navigation

Sector Dominance

The following code was developed in the sector_data_analysis notebook as a tool to facilitate investment planning by sector analysis. It uses the Alpaca API to fetch historical closing prices for ETFs that represent each sector of the S&P 500. After the data has been cleaned, the code analyzes and visualizes risk, returns, votality, and Sharpe ratios of individual sectors against the S&P 500. Next it runs two Monte Carlo simulations, one to project performance of a portfolio equally distributed across sectors at 20 years and one to project our portfolio performance at 20 years. Then the Monte Carlo data is used to calculate the expected portfolio returns given a specific initial investment amount. Finally, tear sheets are created in the portfolio_tear_sheets notebook as a quick reference to the sectors in our portfolio.


Technologies

Language: Python3, Pandas

Imports: pandas, numpy, dotenv, pandas_datareader, empyrical, pyfolio, plotly.express, pn.extension('plotly'), matplotlib, matplotlib.pyplot, panel, hvplot.pandas, alpaca_trade_api and MCForecastTools

External Resources: Alpaca Markets API

Developed with JupyterLab


Installation

JupyterLab - Install JupyterLab


Examples

Creating the Alpaca API object: alpaca_api_object

Loop to make multiple queries to pull more data than 1000 day Alpaca limit: fetch_alpaca_data

Configuring Monte Carlo simulation: configure_mc

Functions needed to fix Pyfolio library:

The first function determines peak, valley, and recovery dates given an 'underwater' DataFrame. new_pyfolio_fuction1

The second function is a wrapper for pandas.io.data.get_data_yahoo(). new_pyfolio_function2

This code overrides the broken fuctions in the Pyfolio library and replaces them with the new functions. pyfolio_override


Contributors

Drew Disbrow Marnell: [email protected]

Matt Epler: [email protected]

Yoko Yamamoto: [email protected]

Scott Alexander: [email protected]


License

MIT License Copyright (c) 2021 Drew Disbrow Marnell

About

Facilitates investment planning by S&P 500 sector analysis based on historical data. A weighted custom portfolio is built based on analysis using Python and Pandas. Then a Monte Carlo simulation is ran to forecast performance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages