|
9 | 9 |
|
10 | 10 | ## Features |
11 | 11 |
|
12 | | -- **Risk-Return Analysis**: Simulate various risk-return scenarios using adjustable parameters like win rate, trades per year, risk per trade, and return per unit of risk (RPUR). |
13 | | -- **Asset Correlation Simulator**: Generate and visualize portfolio performance based on customizable asset correlation matrices, with options for single or random correlation ranges. |
| 12 | +- **Risk-Return Analysis**: Simulate various risk-return scenarios using adjustable parameters like win rate, trades per year, risk per trade, and return per unit of risk (RPUR). Uses Monte Carlo simulation to estimate expected returns and drawdowns. |
| 13 | +- **Asset Correlation Simulator**: Generate and visualize portfolio performance based on customizable asset correlation matrices, with options for single or random correlation ranges. Computes Sharpe, Sortino, Calmar ratios, max drawdown, and more. |
14 | 14 |
|
15 | 15 | ## Screenshots |
16 | 16 |
|
|
28 | 28 |
|
29 | 29 | ## Project Structure |
30 | 30 |
|
31 | | -```bash |
| 31 | +``` |
32 | 32 | RiskSim/ |
33 | | -│ |
| 33 | +├── Welcome.py # Streamlit entrypoint (landing page) |
34 | 34 | ├── pages/ |
35 | | -│ ├── 1_🎯_risk_return_analysis.py # Main page for risk-return simulations |
36 | | -│ └── 2_📈_asset_correlation.py # Main page for asset correlation simulations |
37 | | -│ |
| 35 | +│ ├── 1_🎯_risk_return_analysis.py # Risk-return Monte Carlo simulation |
| 36 | +│ └── 2_📈_asset_correlation.py # Asset correlation portfolio simulator |
38 | 37 | ├── config/ |
39 | | -│ ├── slider_configs.py # Configuration for slider inputs in the Streamlit UI |
40 | | -│ └── __init__.py # Init file for config |
41 | | -│ |
| 38 | +│ └── slider_configs.py # Centralized slider defaults and bounds |
42 | 39 | ├── utils/ |
43 | | -│ ├── risk_simulation.py # Core simulation logic for risk management and portfolio performance |
44 | | -│ └── style.py # Styling and layout helpers for Streamlit app |
45 | | -│ |
46 | | -├── docs/images/ # Image assets for documentation and app UI |
47 | | -│ ├── header_image.jpg |
48 | | -│ ├── image.png |
49 | | -│ ├── image_1.png |
50 | | -│ ├── image_2.png |
51 | | -│ ├── image_3.png |
52 | | -│ └── image_4.png |
53 | | -│ |
54 | | -├── venv/ # Python virtual environment (optional) |
55 | | -├── Welcome.py # Main entry point for the app |
56 | | -├── README.md # This file |
57 | | -├── LICENSE.txt # License information |
58 | | -├── .gitignore # Files and directories to be ignored by git |
59 | | -└── requirements.txt # Python dependencies |
| 40 | +│ ├── risk_simulation.py # TradingSimulator class + drawdown simulation |
| 41 | +│ └── style.py # Footer and metric box HTML helpers |
| 42 | +├── tests/ |
| 43 | +│ ├── test_risk_simulation.py # Tests for simulation logic |
| 44 | +│ └── test_style.py # Tests for style helpers |
| 45 | +├── docs/ |
| 46 | +│ ├── audit_report.md # Codebase audit report |
| 47 | +│ └── images/ # Screenshots and header image |
| 48 | +├── .github/workflows/ci.yml # GitHub Actions CI (ruff + pytest) |
| 49 | +├── pyproject.toml # Ruff and pytest configuration |
| 50 | +├── requirements.txt # Python dependencies |
| 51 | +├── CHANGELOG.md # Change log |
| 52 | +├── LICENSE.txt # MIT License |
| 53 | +└── README.md |
60 | 54 | ``` |
61 | 55 |
|
62 | | -## Installation |
63 | | - |
64 | | -To get started with **RiskSim**, follow these steps: |
| 56 | +## Setup |
65 | 57 |
|
66 | 58 | ### Prerequisites |
67 | 59 |
|
68 | | -Ensure you have Python 3.8+ installed. You'll also need `pip` to install the required dependencies. |
| 60 | +- Python 3.10 or higher |
| 61 | +- pip |
69 | 62 |
|
70 | | -### Clone the Repository |
| 63 | +### Installation |
71 | 64 |
|
72 | 65 | ```bash |
73 | | -git clone https://github.com/your-username/RiskSim.git |
| 66 | +# Clone the repository |
| 67 | +git clone https://github.com/chrisduvillard/RiskSim.git |
74 | 68 | cd RiskSim |
| 69 | + |
| 70 | +# Create and activate a virtual environment |
| 71 | +python -m venv .venv |
| 72 | +# On Windows: |
| 73 | +.venv\Scripts\activate |
| 74 | +# On macOS/Linux: |
| 75 | +source .venv/bin/activate |
| 76 | + |
| 77 | +# Install dependencies |
| 78 | +pip install -r requirements.txt |
75 | 79 | ``` |
76 | 80 |
|
77 | | -### Create a Virtual Environment (Optional but Recommended) |
| 81 | +### Run the App |
78 | 82 |
|
79 | 83 | ```bash |
80 | | -python -m venv venv |
81 | | -source venv/bin/activate # On Windows use `venv\Scriptsctivate` |
| 84 | +streamlit run Welcome.py |
82 | 85 | ``` |
83 | 86 |
|
84 | | -### Install Dependencies |
| 87 | +This launches the app in your browser. Use the sidebar to navigate between pages. |
85 | 88 |
|
86 | | -Install the required Python packages by running: |
| 89 | +### Run Tests |
87 | 90 |
|
88 | 91 | ```bash |
89 | | -pip install -r requirements.txt |
| 92 | +pip install pytest |
| 93 | +pytest -v |
90 | 94 | ``` |
91 | 95 |
|
92 | | -### Run the Application |
93 | | - |
94 | | -Start the application using Streamlit: |
| 96 | +### Run Linter |
95 | 97 |
|
96 | 98 | ```bash |
97 | | -streamlit run Welcome.py |
| 99 | +pip install ruff |
| 100 | +ruff check . |
98 | 101 | ``` |
99 | 102 |
|
100 | | -This will launch the **RiskSim** app in your browser. |
101 | | - |
102 | | -## Usage |
| 103 | +## Methodology |
103 | 104 |
|
104 | 105 | ### Risk-Return Analysis |
105 | 106 |
|
106 | | -- Navigate to the **Risk-Return Analysis** section to simulate various risk-return scenarios. |
107 | | -- You can adjust the number of trades per year, win rate, risk per trade, and RPUR. |
108 | | -- View detailed metrics such as expected drawdown, Sharpe ratio, and more. |
109 | | - |
| 107 | +The Risk-Return Analysis page uses **Monte Carlo simulation** to model trading outcomes. Given a set of parameters (number of trades per year, win rate, risk per trade, and return per unit of risk), the simulator: |
| 108 | + |
| 109 | +1. Generates random trade sequences where each trade is a win or loss based on the specified win rate |
| 110 | +2. Applies compounding: each trade's P&L is a percentage of the *current* AUM (not the initial capital) |
| 111 | +3. Repeats this process thousands of times to build a distribution of outcomes |
| 112 | +4. Reports average returns across different RPUR levels and win rates |
| 113 | +5. Estimates the expected maximum consecutive-loss drawdown |
| 114 | + |
110 | 115 | ### Asset Correlation Simulation |
111 | 116 |
|
112 | | -- Use the **Asset Correlation** page to simulate portfolios with different asset correlations. |
113 | | -- Choose between fixed or random correlation settings. |
114 | | -- Visualize performance and compute portfolio metrics under various correlation regimes. |
| 117 | +The Asset Correlation page generates synthetic multi-asset portfolios using **correlated geometric Brownian motion**: |
115 | 118 |
|
| 119 | +1. Builds a correlation matrix (uniform or random within a range), ensuring positive definiteness |
| 120 | +2. Constructs a covariance matrix from per-asset volatilities and the correlation matrix |
| 121 | +3. Samples multivariate normal log-returns and converts to price paths |
| 122 | +4. Computes per-asset and portfolio performance metrics (Sharpe, Sortino, Calmar, max drawdown) |
| 123 | +5. Sweeps across correlation levels to show how diversification affects portfolio risk |
116 | 124 |
|
117 | 125 | ## License |
118 | 126 |
|
119 | 127 | This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file for details. |
120 | 128 |
|
121 | 129 | ## Author |
122 | 130 |
|
123 | | -Made with ❤️ by [Chris](https://www.linkedin.com/in/christopheduvillard/) |
124 | | - |
125 | | -## Acknowledgments |
126 | | - |
127 | | -- Streamlit |
128 | | -- Plotly |
129 | | - |
130 | | -## Contributing |
131 | | - |
132 | | -Contributions are welcome! Feel free to fork the repository, make improvements, and submit a pull request. |
| 131 | +Made by [Christophe Duvillard](https://www.linkedin.com/in/christopheduvillard/) |
0 commit comments