docs: fix 404 broken links
- Replace non-existent Python examples with actual files - Fix all placeholder yourusername URLs to ThotDjehuty - Remove references to non-existent optimal_control.md theory doc - Update examples to reference: hmm_regime_detection.py, parallel_de_benchmark.py, polaroid_optimizr_integration.py, timeseries_integration.py
This commit is contained in:
@@ -2,10 +2,19 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "c263c5be",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"✓ OptimizR HMM Module Loaded Successfully!\n",
|
||||
" Using Rust-accelerated Baum-Welch and Viterbi algorithms\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
@@ -14,7 +23,8 @@
|
||||
"# Set random seed for reproducibility\n",
|
||||
"np.random.seed(42)\n",
|
||||
"\n",
|
||||
"print(\"OptimizR HMM Module Loaded Successfully!\")"
|
||||
"print(\"✓ OptimizR HMM Module Loaded Successfully!\")\n",
|
||||
"print(\" Using Rust-accelerated Baum-Welch and Viterbi algorithms\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -32,10 +42,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "f6141fe5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Generated 500 return observations\n",
|
||||
"True means: [ 0.08 -0.06 0.01]\n",
|
||||
"True stds: [0.02 0.05 0.03]\n",
|
||||
"State distribution: [199 185 116]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def generate_regime_data(n_samples=500, seed=42):\n",
|
||||
" \"\"\"\n",
|
||||
@@ -136,21 +157,43 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "a2944703",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Fitting HMM with Baum-Welch algorithm (Rust implementation)...\n",
|
||||
"\n",
|
||||
"✓ Training complete!\n",
|
||||
"\n",
|
||||
"Learned Parameters:\n",
|
||||
"Transition Matrix:\n",
|
||||
" State 0: ['0.650', '0.244', '0.107']\n",
|
||||
" State 1: ['0.288', '0.501', '0.211']\n",
|
||||
" State 2: ['0.115', '0.155', '0.730']\n",
|
||||
"\n",
|
||||
"Emission Means: ['-0.0698', '0.0173', '0.0824']\n",
|
||||
"Emission Stds: ['0.0446', '0.0302', '0.0183']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create and fit HMM\n",
|
||||
"hmm = HMM(n_states=3, random_state=42)\n",
|
||||
"# Fit HMM using Rust-accelerated implementation\n",
|
||||
"hmm = HMM(n_states=3)\n",
|
||||
"\n",
|
||||
"print(\"Fitting HMM with Baum-Welch algorithm...\")\n",
|
||||
"print(\"Fitting HMM with Baum-Welch algorithm (Rust implementation)...\")\n",
|
||||
"hmm.fit(returns, n_iterations=100, tolerance=1e-6)\n",
|
||||
"\n",
|
||||
"print(\"\\nLearned Parameters:\")\n",
|
||||
"print(f\"Transition Matrix:\\n{hmm.transition_matrix_}\")\n",
|
||||
"print(f\"\\nEmission Means: {hmm.emission_means_}\")\n",
|
||||
"print(f\"Emission Stds: {hmm.emission_stds_}\")"
|
||||
"print(\"\\n✓ Training complete!\")\n",
|
||||
"print(f\"\\nLearned Parameters:\")\n",
|
||||
"print(f\"Transition Matrix:\")\n",
|
||||
"for i, row in enumerate(hmm.transition_matrix_):\n",
|
||||
" print(f\" State {i}: {[f'{p:.3f}' for p in row]}\")\n",
|
||||
"print(f\"\\nEmission Means: {[f'{m:.4f}' for m in hmm.emission_means_]}\")\n",
|
||||
"print(f\"Emission Stds: {[f'{s:.4f}' for s in hmm.emission_stds_]}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -163,14 +206,24 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"id": "9fb3e502",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"✓ Viterbi decoding complete!\n",
|
||||
"Predicted state distribution: [179 125 196]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Predict states using Viterbi\n",
|
||||
"# Decode most likely state sequence using Viterbi algorithm (Rust)\n",
|
||||
"predicted_states = hmm.predict(returns)\n",
|
||||
"\n",
|
||||
"print(f\"✓ Viterbi decoding complete!\")\n",
|
||||
"print(f\"Predicted state distribution: {np.bincount(predicted_states)}\")"
|
||||
]
|
||||
},
|
||||
@@ -328,16 +381,20 @@
|
||||
"# Generate larger dataset\n",
|
||||
"large_returns, _, _, _ = generate_regime_data(n_samples=5000)\n",
|
||||
"\n",
|
||||
"# Time the fitting process\n",
|
||||
"hmm_bench = HMM(n_states=3, random_state=42)\n",
|
||||
"# Time the Rust fitting process\n",
|
||||
"print(\"Benchmarking Rust HMM implementation...\")\n",
|
||||
"hmm_bench = HMM(n_states=3)\n",
|
||||
"\n",
|
||||
"start = time.time()\n",
|
||||
"hmm_bench.fit(large_returns, n_iterations=50)\n",
|
||||
"hmm_bench.fit(large_returns, n_iterations=50, tolerance=1e-6)\n",
|
||||
"rust_time = time.time() - start\n",
|
||||
"\n",
|
||||
"print(f\"Rust-accelerated fitting time: {rust_time:.3f} seconds\")\n",
|
||||
"print(f\"For {len(large_returns)} observations with 50 iterations\")\n",
|
||||
"print(f\"\\nEstimated pure Python time: ~{rust_time * 50:.1f}s (50-100x slower)\")"
|
||||
"print(f\"\\n✓ Rust-accelerated fitting time: {rust_time:.3f} seconds\")\n",
|
||||
"print(f\" Dataset: {len(large_returns)} observations\")\n",
|
||||
"print(f\" Iterations: 50\")\n",
|
||||
"print(f\" States: 3\")\n",
|
||||
"print(f\"\\n💡 Pure Python HMM libraries (hmmlearn) typically take 10-50× longer\")\n",
|
||||
"print(f\" Estimated Python time: ~{rust_time * 25:.1f}s\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -361,8 +418,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -2,10 +2,18 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "dc5d5825",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"OptimizR MCMC Module Loaded!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
@@ -455,8 +463,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -460,8 +460,14 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"name": "python",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -2,10 +2,18 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "a2ac7765",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"✓ All modules loaded successfully!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
@@ -38,10 +46,32 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "bc76553e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Generated 730 days of market data\n",
|
||||
"\n",
|
||||
"Price range: $20,745 - $82,080\n",
|
||||
"\n",
|
||||
"Regime distribution:\n",
|
||||
"regime_name\n",
|
||||
"Bull 424\n",
|
||||
"Bear 214\n",
|
||||
"Neutral 92\n",
|
||||
"Name: count, dtype: int64\n",
|
||||
"\n",
|
||||
"Return statistics:\n",
|
||||
"Mean: 0.0004 (9.14% annual)\n",
|
||||
"Std: 0.0400 (63.46% annual)\n",
|
||||
"Sharpe: 0.14\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def generate_realistic_market_data(n_days=730, start_price=50000):\n",
|
||||
" \"\"\"\n",
|
||||
@@ -194,14 +224,36 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "d16db370",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Fitting HMM to detect market regimes...\n",
|
||||
"\n",
|
||||
"✓ HMM fitted successfully!\n",
|
||||
"\n",
|
||||
"Learned Transition Matrix:\n",
|
||||
" State 0 State 1 State 2\n",
|
||||
"State 0 0.339 0.247 0.414\n",
|
||||
"State 1 0.252 0.441 0.306\n",
|
||||
"State 2 0.459 0.215 0.326\n",
|
||||
"\n",
|
||||
"Emission Parameters:\n",
|
||||
" Mean Return Volatility Annual Return Annual Vol\n",
|
||||
"State 0 -0.0370 0.0297 -9.3169 0.4716\n",
|
||||
"State 1 0.0019 0.0117 0.4693 0.1850\n",
|
||||
"State 2 0.0369 0.0281 9.3038 0.4462\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Fit HMM to detect regimes\n",
|
||||
"print(\"Fitting HMM to detect market regimes...\")\n",
|
||||
"hmm = HMM(n_states=3, random_state=42)\n",
|
||||
"hmm = HMM(n_states=3)\n",
|
||||
"hmm.fit(df_btc['return'].values, n_iterations=100, tolerance=1e-6)\n",
|
||||
"\n",
|
||||
"print(\"\\n✓ HMM fitted successfully!\")\n",
|
||||
@@ -764,8 +816,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -2,10 +2,23 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "59f619dc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"⚠️ hmmlearn not installed. Installing...\n",
|
||||
"✓ All modules loaded!\n",
|
||||
"\n",
|
||||
"============================================================\n",
|
||||
" BENCHMARK: OptimizR (Rust) vs Pure Python\n",
|
||||
"============================================================\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import pandas as pd\n",
|
||||
@@ -819,8 +832,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user