Skip to content

1kc2/Long-Short-Stress-Test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Long Short Stress Test

Long/Short Equity Portfolio Stress Test.

This project will read the weights file for constituents (.csv), download historical prices (store them in a SQLAlchemy Core powered db) and calculate portfolio and benchmark returns.

Once daily return series are obtained, a portfolio beta is calculated and used for stress testing.

Results are currently outputted to a styled web page.

Dependencies:

Jinja2
numpy
pandas
pandas-datareader
psycopg2
SQLAlchemy
seaborn
scipy

Install the dependencies with

pip install -r requirements.txt

Also, if it is desired to convert the html output into a pdf, you can do this using wkhtmltopdf.

Usage

python src/run_stress_test.py --weights_file example_weights.csv

Your weights.csv should look like this

ticker,weight
ticker1,0.6
ticker2,0.2
ticker3,-0.4
...

Here's how the visuals would look like:

Long Positions Breakdown

Breakdown of Long Positions

Short Positions Breakdown

Breakdown of Short Positions

Cumulative Returns

Cumulative Returns

Rolling Correlations

Rolling Correlations vs S&P500

Scenario Returns

Stress Scenario Returns