/* Minimal CSS for sidebar compatibility */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: ‘Segoe UI’, Arial, sans-serif;
line-height: 1.4;
color: #333;
background: #f8f9fa;
padding: 10px;
max-width: 100%;
overflow-x: hidden;
}
.container {
max-width: 100%;
margin: 0 auto;
}
h1, h2, h3, h4 {
color: #2c3e50;
margin-bottom: 10px;
}
h1 {
font-size: 20px;
text-align: center;
background: linear-gradient(90deg, #2c3e50, #3498db);
color: white;
padding: 12px;
border-radius: 6px;
margin-bottom: 15px;
}
h2 {
font-size: 16px;
border-bottom: 2px solid #3498db;
padding-bottom: 6px;
margin-top: 20px;
margin-bottom: 15px;
}
h3 {
font-size: 14px;
margin-top: 15px;
}
.card {
background: white;
border-radius: 6px;
padding: 12px;
margin-bottom: 15px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
border-left: 4px solid #3498db;
}
.card-header {
background: #2c3e50;
color: white;
padding: 8px 12px;
margin: -12px -12px 12px -12px;
border-radius: 6px 6px 0 0;
font-weight: bold;
}
.card.danger {
border-left-color: #e74c3c;
}
.card.warning {
border-left-color: #f39c12;
}
.card.success {
border-left-color: #27ae60;
}
.card-header.danger {
background: #e74c3c;
}
.card-header.warning {
background: #f39c12;
color: #333;
}
.card-header.success {
background: #27ae60;
}
.formula {
background: #f1f8ff;
padding: 8px;
border-radius: 4px;
font-family: ‘Courier New’, monospace;
font-size: 12px;
margin: 8px 0;
overflow-x: auto;
white-space: nowrap;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin: 10px 0;
font-size: 12px;
}
.data-table th, .data-table td {
padding: 6px;
border: 1px solid #ddd;
text-align: center;
}
.data-table th {
background: #2c3e50;
color: white;
}
.risk-badge {
display: inline-block;
padding: 6px 12px;
border-radius: 20px;
font-weight: bold;
font-size: 14px;
margin: 5px;
}
.risk-high {
background: #e74c3c;
color: white;
}
.risk-medium {
background: #f39c12;
color: #333;
}
.risk-low {
background: #27ae60;
color: white;
}
.slider-container {
margin: 15px 0;
}
.correlation-slider {
width: 100%;
height: 8px;
-webkit-appearance: none;
background: linear-gradient(to right, #27ae60, #f39c12, #e74c3c);
border-radius: 4px;
outline: none;
}
.correlation-slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #2c3e50;
border: 2px solid white;
box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.correlation-value {
font-size: 24px;
font-weight: bold;
text-align: center;
margin: 10px 0;
}
.correlation-negative {
color: #27ae60;
}
.correlation-zero {
color: #f39c12;
}
.correlation-positive {
color: #e74c3c;
}
.btn-group {
display: flex;
gap: 5px;
margin: 10px 0;
flex-wrap: wrap;
}
.btn {
padding: 6px 12px;
border: 1px solid #3498db;
background: white;
color: #3498db;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
flex: 1;
min-width: 60px;
}
.btn:hover {
background: #3498db;
color: white;
}
.btn-danger {
border-color: #e74c3c;
color: #e74c3c;
}
.btn-danger:hover {
background: #e74c3c;
color: white;
}
.btn-warning {
border-color: #f39c12;
color: #f39c12;
}
.btn-warning:hover {
background: #f39c12;
color: #333;
}
.btn-success {
border-color: #27ae60;
color: #27ae60;
}
.btn-success:hover {
background: #27ae60;
color: white;
}
.progress {
height: 20px;
background: #ecf0f1;
border-radius: 10px;
margin: 10px 0;
overflow: hidden;
}
.progress-bar {
height: 100%;
background: #3498db;
border-radius: 10px;
transition: width 0.3s;
text-align: center;
color: white;
font-size: 12px;
line-height: 20px;
}
.chart-container {
height: 200px;
margin: 15px 0;
}
.summary-box {
background: #e8f4fc;
padding: 10px;
border-radius: 6px;
margin: 10px 0;
border-left: 3px solid #3498db;
}
.insight-item {
margin: 8px 0;
padding-left: 20px;
position: relative;
}
.insight-item:before {
content: “•”;
color: #3498db;
font-weight: bold;
position: absolute;
left: 0;
}
@media (max-width: 480px) {
h1 {
font-size: 18px;
padding: 10px;
}
h2 {
font-size: 15px;
}
.card {
padding: 10px;
}
.correlation-value {
font-size: 20px;
}
}
📊 Portfolio Diversification: Correlation & Risk
This demonstrates how combining assets with different correlations reduces portfolio risk.
| Asset | Return | Risk (σ) |
|---|---|---|
| Asset A | 10% | 20% |
| Asset B | 8% | 15% |
Portfolio: wA = 0.5, wB = 0.5
Current Calculation:
With perfect positive correlation (ρ = +1), no diversification benefit.
Diversification Benefit:
Fixed Correlation Cases
Perfect positive correlation
No diversification
Zero correlation
28.6% less risk
Perfect negative correlation
85.7% less risk
| Correlation (ρ) | Portfolio Risk | Diversification | Risk Reduction |
|---|---|---|---|
| +1 (Perfect Positive) | 17.5% | None | 0% |
| 0 (No Correlation) | 12.5% | Moderate | 28.6% |
| -1 (Perfect Negative) | 2.5% | Maximum | 85.7% |
© Portfolio Diversification Example | Modern Portfolio Theory
// Set current year
document.getElementById(‘currentYear’).textContent = new Date().getFullYear();
// Portfolio calculation function
function calculatePortfolioRisk(correlation) {
const wA = 0.5, wB = 0.5;
const sigmaA = 0.20, sigmaB = 0.15;
const part1 = Math.pow(wA, 2) * Math.pow(sigmaA, 2);
const part2 = Math.pow(wB, 2) * Math.pow(sigmaB, 2);
const part3 = 2 * wA * wB * sigmaA * sigmaB * correlation;
const variance = part1 + part2 + part3;
const portfolioRisk = Math.sqrt(variance);
// Calculate diversification benefit
const maxRisk = 0.175; // ρ = +1
const minRisk = 0.025; // ρ = -1
const diversificationBenefit = ((maxRisk – portfolioRisk) / (maxRisk – minRisk)) * 100;
return {
risk: portfolioRisk,
riskPercent: (portfolioRisk * 100).toFixed(2),
diversificationBenefit: Math.max(0, Math.min(100, diversificationBenefit)),
calculation: `σp = √[${part1.toFixed(5)} + ${part2.toFixed(5)} + ${(part3 >= 0 ? ‘+’ : ”) + part3.toFixed(5)}] = ${(portfolioRisk*100).toFixed(2)}%`
};
}
// Update display
function updateDisplay(correlation) {
const result = calculatePortfolioRisk(correlation);
// Update correlation value
const correlationValue = document.getElementById(‘correlationValue’);
correlationValue.innerHTML = `ρ = ${correlation >= 0 ? ‘+’ : ”}${correlation.toFixed(2)}`;
// Update correlation color
if (correlation > 0.3) {
correlationValue.className = ‘correlation-value correlation-positive’;
} else if (correlation 0.15) {
riskBadge.className = ‘risk-badge risk-high’;
} else if (result.risk > 0.05) {
riskBadge.className = ‘risk-badge risk-medium’;
} else {
riskBadge.className = ‘risk-badge risk-low’;
}
// Update calculation
document.getElementById(‘calculation’).innerHTML = result.calculation;
// Update interpretation
const interpretation = document.getElementById(‘interpretation’);
let interpretationText = ”;
if (correlation > 0.7) {
interpretationText = ‘With perfect positive correlation (ρ = +’ + correlation.toFixed(2) + ‘), no diversification benefit.’;
} else if (correlation > 0.3) {
interpretationText = ‘With positive correlation (ρ = +’ + correlation.toFixed(2) + ‘), limited diversification benefit.’;
} else if (correlation > -0.3) {
interpretationText = ‘With low correlation (ρ = ‘ + (correlation >= 0 ? ‘+’ : ”) + correlation.toFixed(2) + ‘), good diversification.’;
} else {
interpretationText = ‘With negative correlation (ρ = ‘ + correlation.toFixed(2) + ‘), maximum diversification benefit.’;
}
interpretation.textContent = interpretationText;
// Update diversification bar
const diversificationBar = document.getElementById(‘diversificationBar’);
const benefitPercent = Math.round(result.diversificationBenefit);
diversificationBar.style.width = benefitPercent + ‘%’;
diversificationBar.textContent = benefitPercent + ‘%’;
// Update bar color
if (benefitPercent < 30) {
diversificationBar.style.background = '#e74c3c';
} else if (benefitPercent < 70) {
diversificationBar.style.background = '#f39c12';
} else {
diversificationBar.style.background = '#27ae60';
}
// Update chart
updateChart(correlation);
}
// Initialize chart
const ctx = document.getElementById('riskChart').getContext('2d');
let riskChart;
function initializeChart() {
// Generate data points
const correlations = [];
const risks = [];
for (let rho = -1; rho {
return Math.abs(parseFloat(label) – correlation) {
button.addEventListener(‘click’, function() {
const correlation = parseFloat(this.getAttribute(‘data-correlation’));
document.getElementById(‘correlationSlider’).value = correlation * 100;
updateDisplay(correlation);
});
});
// Initialize on load
window.addEventListener(‘load’, function() {
initializeChart();
updateDisplay(1);
});
