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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Page 6: Educational Resources
|
| 3 |
+
==============================
|
| 4 |
+
|
| 5 |
+
Learn about portfolio optimization:
|
| 6 |
+
- Modern Portfolio Theory
|
| 7 |
+
- Risk metrics explained
|
| 8 |
+
- Optimization techniques
|
| 9 |
+
- Investment strategies
|
| 10 |
+
- Common mistakes to avoid
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import streamlit as st
|
| 14 |
+
|
| 15 |
+
# ============ PAGE CONFIGURATION ============
|
| 16 |
+
st.set_page_config(
|
| 17 |
+
page_title="Learn | NSE Optimizer",
|
| 18 |
+
page_icon="π",
|
| 19 |
+
layout="wide"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# ============ MAIN APP ============
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
st.title("π Educational Resources")
|
| 26 |
+
st.markdown("Learn about portfolio optimization, investing principles, and risk management")
|
| 27 |
+
|
| 28 |
+
st.markdown("---")
|
| 29 |
+
|
| 30 |
+
# Table of Contents
|
| 31 |
+
st.markdown("## π Quick Navigation")
|
| 32 |
+
|
| 33 |
+
col1, col2, col3 = st.columns(3)
|
| 34 |
+
|
| 35 |
+
with col1:
|
| 36 |
+
st.markdown("""
|
| 37 |
+
**Basics:**
|
| 38 |
+
- Modern Portfolio Theory
|
| 39 |
+
- Risk vs Return
|
| 40 |
+
- Diversification
|
| 41 |
+
""")
|
| 42 |
+
|
| 43 |
+
with col2:
|
| 44 |
+
st.markdown("""
|
| 45 |
+
**Advanced:**
|
| 46 |
+
- Sharpe Ratio
|
| 47 |
+
- Efficient Frontier
|
| 48 |
+
- Monte Carlo Simulation
|
| 49 |
+
""")
|
| 50 |
+
|
| 51 |
+
with col3:
|
| 52 |
+
st.markdown("""
|
| 53 |
+
**Practical:**
|
| 54 |
+
- How to Use This App
|
| 55 |
+
- Investment Strategies
|
| 56 |
+
- Common Mistakes
|
| 57 |
+
""")
|
| 58 |
+
|
| 59 |
+
st.markdown("---")
|
| 60 |
+
|
| 61 |
+
# Lesson 1: Modern Portfolio Theory
|
| 62 |
+
with st.expander("π Lesson 1: Modern Portfolio Theory (MPT)", expanded=True):
|
| 63 |
+
st.markdown("""
|
| 64 |
+
### What is Modern Portfolio Theory?
|
| 65 |
+
|
| 66 |
+
**Developed by:** Harry Markowitz (Nobel Prize 1990)
|
| 67 |
+
|
| 68 |
+
**Key Principle:** Don't put all your eggs in one basket
|
| 69 |
+
|
| 70 |
+
**Core Idea:**
|
| 71 |
+
- Risk can be reduced through diversification
|
| 72 |
+
- Optimal portfolios maximize return for given risk level
|
| 73 |
+
- Mathematical framework for portfolio construction
|
| 74 |
+
|
| 75 |
+
### The Efficient Frontier
|
| 76 |
+
|
| 77 |
+
The efficient frontier represents all optimal portfolios:
|
| 78 |
+
- Each point offers maximum return for its risk level
|
| 79 |
+
- Points below the line are sub-optimal
|
| 80 |
+
- Your goal: Find the point that matches your risk tolerance
|
| 81 |
+
|
| 82 |
+
### Why It Matters
|
| 83 |
+
|
| 84 |
+
**1. Quantifies Diversification Benefits**
|
| 85 |
+
- Shows exact impact of adding stocks
|
| 86 |
+
- Measures correlation effects
|
| 87 |
+
|
| 88 |
+
**2. Risk-Adjusted Returns**
|
| 89 |
+
- Not just about highest return
|
| 90 |
+
- Considers risk you're taking
|
| 91 |
+
|
| 92 |
+
**3. Objective Decision-Making**
|
| 93 |
+
- Removes emotion from investing
|
| 94 |
+
- Based on mathematical optimization
|
| 95 |
+
|
| 96 |
+
### Real-World Example
|
| 97 |
+
|
| 98 |
+
Imagine two portfolios:
|
| 99 |
+
- **Portfolio A:** 20% return, 25% volatility
|
| 100 |
+
- **Portfolio B:** 18% return, 15% volatility
|
| 101 |
+
|
| 102 |
+
Which is better? MPT helps you decide based on your risk tolerance!
|
| 103 |
+
""")
|
| 104 |
+
|
| 105 |
+
# Lesson 2: Risk Metrics
|
| 106 |
+
with st.expander("π Lesson 2: Understanding Risk Metrics"):
|
| 107 |
+
st.markdown("""
|
| 108 |
+
### Key Risk Metrics Explained
|
| 109 |
+
|
| 110 |
+
#### 1. Volatility (Standard Deviation)
|
| 111 |
+
**What:** Measures how much returns vary
|
| 112 |
+
**Example:** 15% volatility = returns typically within Β±15% of average
|
| 113 |
+
**Good/Bad:** Lower is less risky
|
| 114 |
+
|
| 115 |
+
**Interpretation:**
|
| 116 |
+
- < 10% = Very low risk (stable, like bonds)
|
| 117 |
+
- 10-20% = Moderate risk (balanced portfolio)
|
| 118 |
+
- > 20% = High risk (aggressive stocks)
|
| 119 |
+
|
| 120 |
+
#### 2. Sharpe Ratio
|
| 121 |
+
**Formula:** (Return - Risk-free Rate) / Volatility
|
| 122 |
+
**What:** Return per unit of risk taken
|
| 123 |
+
|
| 124 |
+
**Benchmark:**
|
| 125 |
+
- < 1.0 = Poor (not worth the risk)
|
| 126 |
+
- 1.0-2.0 = Good (acceptable risk-adjusted return)
|
| 127 |
+
- > 2.0 = Excellent (great risk-adjusted return)
|
| 128 |
+
|
| 129 |
+
**Example:** If portfolio returns 15% with 10% volatility and risk-free rate is 6%:
|
| 130 |
+
- Sharpe = (15% - 6%) / 10% = 0.9 (below 1, needs improvement)
|
| 131 |
+
|
| 132 |
+
#### 3. Value at Risk (VaR)
|
| 133 |
+
**What:** Maximum expected loss at confidence level
|
| 134 |
+
**Example:** 95% VaR of -2% = 95% chance daily loss won't exceed 2%
|
| 135 |
+
|
| 136 |
+
**Use Cases:**
|
| 137 |
+
- Set stop-loss levels
|
| 138 |
+
- Determine position sizing
|
| 139 |
+
- Prepare emergency funds
|
| 140 |
+
|
| 141 |
+
#### 4. Maximum Drawdown
|
| 142 |
+
**What:** Largest peak-to-trough decline
|
| 143 |
+
**Example:** -30% = portfolio lost 30% from highest point
|
| 144 |
+
|
| 145 |
+
**Psychological Impact:**
|
| 146 |
+
- Tests your ability to hold during downturns
|
| 147 |
+
- Many investors sell at worst time
|
| 148 |
+
- Know your drawdown tolerance!
|
| 149 |
+
|
| 150 |
+
#### 5. Correlation
|
| 151 |
+
**Range:** -1 to +1
|
| 152 |
+
|
| 153 |
+
**Interpretation:**
|
| 154 |
+
- +1 = Move together perfectly (no diversification)
|
| 155 |
+
- 0 = No relationship (good diversification)
|
| 156 |
+
- -1 = Move opposite directions (excellent hedge)
|
| 157 |
+
|
| 158 |
+
**Goal:** Seek low/negative correlations for diversification
|
| 159 |
+
""")
|
| 160 |
+
|
| 161 |
+
# Lesson 3: Optimization
|
| 162 |
+
with st.expander("βοΈ Lesson 3: How Portfolio Optimization Works"):
|
| 163 |
+
st.markdown("""
|
| 164 |
+
### Portfolio Optimization Process
|
| 165 |
+
|
| 166 |
+
#### Step 1: Data Collection
|
| 167 |
+
- Download historical prices (typically 2-5 years)
|
| 168 |
+
- Calculate daily returns
|
| 169 |
+
- Compute statistics (mean, volatility, correlation)
|
| 170 |
+
|
| 171 |
+
#### Step 2: Define Objective
|
| 172 |
+
**Maximize:** Sharpe Ratio (most common)
|
| 173 |
+
|
| 174 |
+
**Constraints:**
|
| 175 |
+
- Sum of weights = 100%
|
| 176 |
+
- No short selling (weights β₯ 0)
|
| 177 |
+
- Optional: Max per-stock limit (e.g., 20%)
|
| 178 |
+
|
| 179 |
+
#### Step 3: Mathematical Optimization
|
| 180 |
+
Uses **CVXPY** (convex optimization):
|
| 181 |
+
- Solves quadratic programming problem
|
| 182 |
+
- Finds global optimal solution
|
| 183 |
+
- Guarantees mathematically best result
|
| 184 |
+
|
| 185 |
+
#### Step 4: Allocation
|
| 186 |
+
- Convert percentage weights to shares
|
| 187 |
+
- Account for transaction costs
|
| 188 |
+
- Generate buy/sell orders
|
| 189 |
+
|
| 190 |
+
### What Makes a Portfolio "Optimal"?
|
| 191 |
+
|
| 192 |
+
**1. Maximum Sharpe Ratio**
|
| 193 |
+
- Best risk-adjusted returns
|
| 194 |
+
- Efficient use of capital
|
| 195 |
+
|
| 196 |
+
**2. Proper Diversification**
|
| 197 |
+
- Low correlation between holdings
|
| 198 |
+
- Sector balance
|
| 199 |
+
|
| 200 |
+
**3. Risk Management**
|
| 201 |
+
- Controlled volatility
|
| 202 |
+
- Acceptable drawdown limits
|
| 203 |
+
|
| 204 |
+
### Common Optimization Approaches
|
| 205 |
+
|
| 206 |
+
**Minimum Variance:** Lowest possible risk
|
| 207 |
+
**Maximum Return:** Highest possible return (usually too risky)
|
| 208 |
+
**Maximum Sharpe:** Best risk-adjusted (recommended) β
|
| 209 |
+
**Risk Parity:** Equal risk contribution from each asset
|
| 210 |
+
""")
|
| 211 |
+
|
| 212 |
+
# Lesson 4: Monte Carlo
|
| 213 |
+
with st.expander("π² Lesson 4: Monte Carlo Simulation"):
|
| 214 |
+
st.markdown("""
|
| 215 |
+
### What is Monte Carlo Simulation?
|
| 216 |
+
|
| 217 |
+
**Purpose:** Understand range of possible outcomes
|
| 218 |
+
|
| 219 |
+
**How It Works:**
|
| 220 |
+
1. Use historical volatility and returns
|
| 221 |
+
2. Generate 1000+ random future scenarios
|
| 222 |
+
3. Calculate portfolio value in each scenario
|
| 223 |
+
4. Analyze distribution of outcomes
|
| 224 |
+
|
| 225 |
+
### What You Learn
|
| 226 |
+
|
| 227 |
+
**Best Case (95th percentile):**
|
| 228 |
+
- Top 5% of outcomes
|
| 229 |
+
- Optimistic scenario
|
| 230 |
+
- "If things go really well..."
|
| 231 |
+
|
| 232 |
+
**Expected Case (50th percentile):**
|
| 233 |
+
- Most likely outcome
|
| 234 |
+
- Median result
|
| 235 |
+
- "Most probable scenario..."
|
| 236 |
+
|
| 237 |
+
**Worst Case (5th percentile):**
|
| 238 |
+
- Bottom 5% of outcomes
|
| 239 |
+
- Prepare for this mentally
|
| 240 |
+
- "If things go badly..."
|
| 241 |
+
|
| 242 |
+
### Important Limitations
|
| 243 |
+
|
| 244 |
+
β οΈ **NOT a prediction of the future**
|
| 245 |
+
|
| 246 |
+
- Based on historical patterns
|
| 247 |
+
- Markets can change dramatically
|
| 248 |
+
- Black swan events not captured
|
| 249 |
+
- Use as one input, not definitive answer
|
| 250 |
+
|
| 251 |
+
### Best Use Cases
|
| 252 |
+
|
| 253 |
+
**1. Risk Assessment**
|
| 254 |
+
- Understand downside risk
|
| 255 |
+
- Prepare psychologically
|
| 256 |
+
- Set realistic expectations
|
| 257 |
+
|
| 258 |
+
**2. Scenario Planning**
|
| 259 |
+
- "What if" analysis
|
| 260 |
+
- Stress testing
|
| 261 |
+
- Contingency planning
|
| 262 |
+
|
| 263 |
+
**3. Goal Setting**
|
| 264 |
+
- Realistic return expectations
|
| 265 |
+
- Time horizon planning
|
| 266 |
+
- Retirement projections
|
| 267 |
+
|
| 268 |
+
### Example Interpretation
|
| 269 |
+
|
| 270 |
+
Investment: βΉ1,00,000
|
| 271 |
+
Time: 1 year
|
| 272 |
+
|
| 273 |
+
Monte Carlo Results:
|
| 274 |
+
- **Best Case:** βΉ1,35,000 (35% gain)
|
| 275 |
+
- **Expected:** βΉ1,12,000 (12% gain)
|
| 276 |
+
- **Worst Case:** βΉ85,000 (15% loss)
|
| 277 |
+
|
| 278 |
+
**Question:** Can you handle a βΉ15,000 loss?
|
| 279 |
+
""")
|
| 280 |
+
|
| 281 |
+
# Lesson 5: Practical Guide
|
| 282 |
+
with st.expander("π― Lesson 5: How to Use This App Effectively"):
|
| 283 |
+
st.markdown("""
|
| 284 |
+
### Complete Workflow
|
| 285 |
+
|
| 286 |
+
#### For New Investors
|
| 287 |
+
|
| 288 |
+
**Step 1: Start with New Portfolio**
|
| 289 |
+
1. Choose NIFTY 50 for broad diversification
|
| 290 |
+
2. Set investment amount (min βΉ10,000)
|
| 291 |
+
3. Use 2-3 years historical data
|
| 292 |
+
4. Keep default settings initially
|
| 293 |
+
|
| 294 |
+
**Step 2: Review Results**
|
| 295 |
+
1. Check Sharpe Ratio (aim for >1.0)
|
| 296 |
+
2. Review sector allocation (avoid concentration)
|
| 297 |
+
3. Understand risk metrics
|
| 298 |
+
4. Download action plan
|
| 299 |
+
|
| 300 |
+
**Step 3: Execute**
|
| 301 |
+
1. Open trading account if needed
|
| 302 |
+
2. Place exact buy orders
|
| 303 |
+
3. Keep leftover cash in savings
|
| 304 |
+
4. Mark calendar for quarterly review
|
| 305 |
+
|
| 306 |
+
#### For Existing Portfolio Holders
|
| 307 |
+
|
| 308 |
+
**Step 1: Use Rebalance Page**
|
| 309 |
+
1. Upload current holdings CSV
|
| 310 |
+
2. Or enter manually
|
| 311 |
+
3. Set rebalancing threshold (5% default)
|
| 312 |
+
|
| 313 |
+
**Step 2: Analyze Current vs Optimal**
|
| 314 |
+
1. Compare performance metrics
|
| 315 |
+
2. Review improvement potential
|
| 316 |
+
3. Check transaction costs
|
| 317 |
+
|
| 318 |
+
**Step 3: Execute Rebalancing**
|
| 319 |
+
1. Follow buy/sell recommendations
|
| 320 |
+
2. Execute during market hours
|
| 321 |
+
3. Update your records
|
| 322 |
+
|
| 323 |
+
#### Regular Monitoring
|
| 324 |
+
|
| 325 |
+
**Monthly:**
|
| 326 |
+
- Check portfolio value
|
| 327 |
+
- Review major news
|
| 328 |
+
- Monitor for large drifts
|
| 329 |
+
|
| 330 |
+
**Quarterly:**
|
| 331 |
+
- Check for >5% drift
|
| 332 |
+
- Consider rebalancing
|
| 333 |
+
- Review risk metrics
|
| 334 |
+
|
| 335 |
+
**Annually:**
|
| 336 |
+
- Full portfolio review
|
| 337 |
+
- Tax planning
|
| 338 |
+
- Goal reassessment
|
| 339 |
+
- Reoptimize if needed
|
| 340 |
+
""")
|
| 341 |
+
|
| 342 |
+
# Lesson 6: Common Mistakes
|
| 343 |
+
with st.expander("β οΈ Lesson 6: Common Investment Mistakes to Avoid"):
|
| 344 |
+
st.markdown("""
|
| 345 |
+
### Top 10 Mistakes to Avoid
|
| 346 |
+
|
| 347 |
+
#### 1. Emotional Decisions π±
|
| 348 |
+
**Problem:** Panic selling during crashes, FOMO buying during rallies
|
| 349 |
+
**Solution:** Stick to your plan, focus on long-term, automate decisions
|
| 350 |
+
|
| 351 |
+
#### 2. Chasing Returns π
|
| 352 |
+
**Problem:** Buying last year's winners, sector rotation chasing
|
| 353 |
+
**Solution:** Focus on fundamentals and diversification, not past performance
|
| 354 |
+
|
| 355 |
+
#### 3. Over-Concentration π―
|
| 356 |
+
**Problem:** Too much in one stock/sector (>20%)
|
| 357 |
+
**Solution:** Use optimization, limit single stock to 15-20% max
|
| 358 |
+
|
| 359 |
+
#### 4. Ignoring Costs πΈ
|
| 360 |
+
**Problem:** Frequent trading erodes returns
|
| 361 |
+
**Solution:** Consider transaction costs, tax implications, hold long-term
|
| 362 |
+
|
| 363 |
+
#### 5. Market Timing β°
|
| 364 |
+
**Problem:** Trying to predict market moves
|
| 365 |
+
**Solution:** Time IN the market > Timing the market
|
| 366 |
+
|
| 367 |
+
#### 6. Neglecting Rebalancing βοΈ
|
| 368 |
+
**Problem:** Portfolio drifts from targets over time
|
| 369 |
+
**Solution:** Rebalance quarterly or when drift >5%
|
| 370 |
+
|
| 371 |
+
#### 7. Following Tips π’
|
| 372 |
+
**Problem:** Acting on rumors/tips/hot stock recommendations
|
| 373 |
+
**Solution:** Do your own research, use systematic approach
|
| 374 |
+
|
| 375 |
+
#### 8. Ignoring Risk π²
|
| 376 |
+
**Problem:** Only looking at returns, not volatility
|
| 377 |
+
**Solution:** Always check risk metrics (volatility, drawdown, VaR)
|
| 378 |
+
|
| 379 |
+
#### 9. No Emergency Fund π¨
|
| 380 |
+
**Problem:** Forced to sell during emergencies at worst time
|
| 381 |
+
**Solution:** Keep 6 months expenses in liquid funds first
|
| 382 |
+
|
| 383 |
+
#### 10. Overconfidence πͺ
|
| 384 |
+
**Problem:** Thinking you can beat professionals consistently
|
| 385 |
+
**Solution:** Use proven frameworks like MPT, stay humble
|
| 386 |
+
|
| 387 |
+
### Golden Rules for Success
|
| 388 |
+
|
| 389 |
+
1. **Diversify** across stocks and sectors
|
| 390 |
+
2. **Rebalance** regularly (quarterly or semi-annually)
|
| 391 |
+
3. **Stay disciplined** during volatility
|
| 392 |
+
4. **Focus on process**, not short-term outcomes
|
| 393 |
+
5. **Keep learning** and adapting
|
| 394 |
+
6. **Control costs** - fees and taxes matter
|
| 395 |
+
7. **Have patience** - wealth compounds over time
|
| 396 |
+
8. **Know yourself** - match investments to risk tolerance
|
| 397 |
+
""")
|
| 398 |
+
|
| 399 |
+
# Additional Resources
|
| 400 |
+
st.markdown("---")
|
| 401 |
+
st.markdown("## π Additional Learning Resources")
|
| 402 |
+
|
| 403 |
+
col1, col2 = st.columns(2)
|
| 404 |
+
|
| 405 |
+
with col1:
|
| 406 |
+
st.markdown("""
|
| 407 |
+
### π Recommended Books
|
| 408 |
+
|
| 409 |
+
**For Beginners:**
|
| 410 |
+
1. "A Random Walk Down Wall Street" - Burton Malkiel
|
| 411 |
+
2. "The Intelligent Investor" - Benjamin Graham
|
| 412 |
+
3. "Common Sense on Mutual Funds" - John Bogle
|
| 413 |
+
|
| 414 |
+
**For Intermediate:**
|
| 415 |
+
4. "Common Stocks and Uncommon Profits" - Philip Fisher
|
| 416 |
+
5. "One Up On Wall Street" - Peter Lynch
|
| 417 |
+
6. "The Little Book That Builds Wealth" - Pat Dorsey
|
| 418 |
+
|
| 419 |
+
**For Advanced:**
|
| 420 |
+
7. "Security Analysis" - Graham & Dodd
|
| 421 |
+
8. "Margin of Safety" - Seth Klarman
|
| 422 |
+
9. "The Most Important Thing" - Howard Marks
|
| 423 |
+
|
| 424 |
+
### π Online Courses
|
| 425 |
+
|
| 426 |
+
- **Coursera:** Investment Management Specialization
|
| 427 |
+
- **Khan Academy:** Finance & Capital Markets (Free)
|
| 428 |
+
- **NSE Academy:** Free Certification Courses
|
| 429 |
+
- **Zerodha Varsity:** Free Indian Market Education
|
| 430 |
+
""")
|
| 431 |
+
|
| 432 |
+
with col2:
|
| 433 |
+
st.markdown("""
|
| 434 |
+
### ποΈ Regulatory & Official Sources
|
| 435 |
+
|
| 436 |
+
**Regulatory Bodies:**
|
| 437 |
+
- [SEBI](https://www.sebi.gov.in) - Securities regulator
|
| 438 |
+
- [RBI](https://www.rbi.org.in) - Reserve Bank of India
|
| 439 |
+
- [NSE](https://www.nseindia.com) - National Stock Exchange
|
| 440 |
+
- [BSE](https://www.bseindia.com) - Bombay Stock Exchange
|
| 441 |
+
|
| 442 |
+
**Market Data & News:**
|
| 443 |
+
- [Moneycontrol](https://www.moneycontrol.com)
|
| 444 |
+
- [Economic Times Markets](https://economictimes.indiatimes.com/markets)
|
| 445 |
+
- [Bloomberg Quint](https://www.bloombergquint.com)
|
| 446 |
+
- [LiveMint](https://www.livemint.com)
|
| 447 |
+
|
| 448 |
+
### π§ Useful Tools
|
| 449 |
+
|
| 450 |
+
- **Screener.in** - Stock fundamentals analysis
|
| 451 |
+
- **TradingView** - Charts and technical analysis
|
| 452 |
+
- **Investing.com** - Global market data
|
| 453 |
+
- **ValueResearch** - Mutual fund analysis
|
| 454 |
+
""")
|
| 455 |
+
|
| 456 |
+
st.markdown("---")
|
| 457 |
+
|
| 458 |
+
# Glossary
|
| 459 |
+
st.markdown("## π Investment Glossary")
|
| 460 |
+
|
| 461 |
+
with st.expander("Common Terms Explained"):
|
| 462 |
+
st.markdown("""
|
| 463 |
+
**Alpha:** Excess return beyond market benchmark
|
| 464 |
+
**Beta:** Measure of volatility relative to market
|
| 465 |
+
**Correlation:** Relationship between two assets (-1 to +1)
|
| 466 |
+
**Diversification:** Spreading risk across multiple investments
|
| 467 |
+
**Efficient Frontier:** Set of optimal portfolios
|
| 468 |
+
**FMCG:** Fast-Moving Consumer Goods
|
| 469 |
+
**Market Cap:** Total value of company (price Γ shares)
|
| 470 |
+
**NIFTY 50:** India's benchmark index of top 50 companies
|
| 471 |
+
**P/E Ratio:** Price-to-Earnings ratio (valuation metric)
|
| 472 |
+
**Portfolio:** Collection of investments
|
| 473 |
+
**Rebalancing:** Adjusting portfolio back to target weights
|
| 474 |
+
**Risk-free Rate:** Return on safest investment (G-Sec)
|
| 475 |
+
**Sharpe Ratio:** Risk-adjusted return measure
|
| 476 |
+
**Volatility:** Measure of price fluctuation
|
| 477 |
+
**Yield:** Income return on investment
|
| 478 |
+
""")
|
| 479 |
+
|
| 480 |
+
st.markdown("---")
|
| 481 |
+
|
| 482 |
+
# FAQ
|
| 483 |
+
st.markdown("## β Frequently Asked Questions")
|
| 484 |
+
|
| 485 |
+
with st.expander("How much should I invest?"):
|
| 486 |
+
st.markdown("""
|
| 487 |
+
**General Guidelines:**
|
| 488 |
+
- Start with what you can afford to lose
|
| 489 |
+
- Have 6 months emergency fund first
|
| 490 |
+
- Don't invest money needed within 3-5 years
|
| 491 |
+
- Typical: 10-20% of monthly income
|
| 492 |
+
|
| 493 |
+
**Portfolio Size Recommendations:**
|
| 494 |
+
- Minimum: βΉ10,000 (for diversification)
|
| 495 |
+
- Comfortable: βΉ50,000+ (better diversification)
|
| 496 |
+
- Optimal: βΉ2,00,000+ (full benefits)
|
| 497 |
+
""")
|
| 498 |
+
|
| 499 |
+
with st.expander("How often should I rebalance?"):
|
| 500 |
+
st.markdown("""
|
| 501 |
+
**Rebalancing Frequency:**
|
| 502 |
+
- **Quarterly:** Good balance (recommended)
|
| 503 |
+
- **Semi-annually:** Acceptable for most
|
| 504 |
+
- **Annually:** Minimum frequency
|
| 505 |
+
|
| 506 |
+
**Trigger-based:**
|
| 507 |
+
- When any position drifts >5% from target
|
| 508 |
+
- After major market moves (>10%)
|
| 509 |
+
- When adding new capital
|
| 510 |
+
|
| 511 |
+
**Cost Considerations:**
|
| 512 |
+
- More frequent = higher transaction costs
|
| 513 |
+
- Less frequent = more drift from optimal
|
| 514 |
+
""")
|
| 515 |
+
|
| 516 |
+
with st.expander("What's a good Sharpe ratio?"):
|
| 517 |
+
st.markdown("""
|
| 518 |
+
**Sharpe Ratio Benchmarks:**
|
| 519 |
+
- **< 0:** Worse than risk-free rate (bad)
|
| 520 |
+
- **0-1:** Positive but sub-optimal
|
| 521 |
+
- **1-2:** Good risk-adjusted returns β
|
| 522 |
+
- **2-3:** Very good performance
|
| 523 |
+
- **> 3:** Exceptional (rare, verify data)
|
| 524 |
+
|
| 525 |
+
**Context Matters:**
|
| 526 |
+
- Compare to market benchmark (NIFTY ~1.0)
|
| 527 |
+
- Higher risk tolerance = can accept lower Sharpe
|
| 528 |
+
- Lower risk tolerance = need higher Sharpe
|
| 529 |
+
""")
|
| 530 |
+
|
| 531 |
+
with st.expander("How do I handle market crashes?"):
|
| 532 |
+
st.markdown("""
|
| 533 |
+
**During a Crash:**
|
| 534 |
+
1. **Don't panic sell** - worst decision
|
| 535 |
+
2. **Review fundamentals** - has anything changed?
|
| 536 |
+
3. **Check diversification** - is portfolio balanced?
|
| 537 |
+
4. **Consider buying** - if you have cash (buy low)
|
| 538 |
+
5. **Stick to plan** - trust your strategy
|
| 539 |
+
|
| 540 |
+
**Preparation:**
|
| 541 |
+
- Know your maximum drawdown tolerance
|
| 542 |
+
- Have emergency fund separate
|
| 543 |
+
- Don't check portfolio daily
|
| 544 |
+
- Remember: markets recover (historically)
|
| 545 |
+
|
| 546 |
+
**Historical Perspective:**
|
| 547 |
+
- Markets always recovered from crashes
|
| 548 |
+
- Average recovery time: 1-3 years
|
| 549 |
+
- Those who stayed invested won
|
| 550 |
+
""")
|
| 551 |
+
|
| 552 |
+
st.markdown("---")
|
| 553 |
+
|
| 554 |
+
# Final Tips
|
| 555 |
+
st.markdown("## π‘ Final Tips for Success")
|
| 556 |
+
|
| 557 |
+
col1, col2, col3 = st.columns(3)
|
| 558 |
+
|
| 559 |
+
with col1:
|
| 560 |
+
st.markdown("""
|
| 561 |
+
**Mindset:**
|
| 562 |
+
- Think long-term (5+ years)
|
| 563 |
+
- Control emotions
|
| 564 |
+
- Stay disciplined
|
| 565 |
+
- Keep learning
|
| 566 |
+
""")
|
| 567 |
+
|
| 568 |
+
with col2:
|
| 569 |
+
st.markdown("""
|
| 570 |
+
**Strategy:**
|
| 571 |
+
- Diversify properly
|
| 572 |
+
- Rebalance regularly
|
| 573 |
+
- Control costs
|
| 574 |
+
- Review quarterly
|
| 575 |
+
""")
|
| 576 |
+
|
| 577 |
+
with col3:
|
| 578 |
+
st.markdown("""
|
| 579 |
+
**Risk Management:**
|
| 580 |
+
- Know your tolerance
|
| 581 |
+
- Set stop-losses
|
| 582 |
+
- Have emergency fund
|
| 583 |
+
- Don't overtrade
|
| 584 |
+
""")
|
| 585 |
+
|
| 586 |
+
st.markdown("---")
|
| 587 |
+
|
| 588 |
+
st.success("""
|
| 589 |
+
π‘ **Remember:** Successful investing is a marathon, not a sprint.
|
| 590 |
+
Use this tool to make informed decisions, but always consult a qualified financial advisor
|
| 591 |
+
for personalized guidance. Happy investing! π
|
| 592 |
+
""")
|
| 593 |
+
|
| 594 |
+
# Footer
|
| 595 |
+
st.caption("For more help, visit other pages: Home | New Portfolio | Rebalance | Risk Analysis | Market Insights | Settings")
|
| 596 |
+
|
| 597 |
+
if __name__ == "__main__":
|
| 598 |
+
main()
|