```python\nimport requests\nimport pandas as pd\nfrom collections import defaultdict\nimport matplotlib.pyplot as plt\nfrom typing import List, Dict, Any\nfrom datetime import datetime\n\n# Note: This code implements a sports betting backtesting strategy based on the user's request.\n# Strategy Logic:\n# 1. Focus on playmaking efficiency: primary_assists_per_game (fallback to assists_per_game if primary not available).\n# 2. Rolling calculation of top-10 playmakers (min 10 GP to avoid small samples).\n# 3. Bet moneyline on teams featuring at least one top-10 playmaker (higher confidence for Kucherov specifically).\n# 4. Special boost for Nikita Kucherov: if his efficiency ranks top-3, increase confidence/stake (medium risk).\n# 5. Proper forward-walk backtest: cumulative stats updated AFTER each game outcome simulation.\n# 6. Assumes BallDontLie API provides:\n#    - games: list of {'id':, 'date':, 'home_team_id':, 'away_team_id':, 'home_score':, 'away_score':, ...}\n#    - players: list of per-game logs {'game_id':, 'player_id':, 'player_name':, 'team_id':, 'primary_assists': (or 0), 'assists':, ...}\n#    - teams: list of {'id':, 'name':, ...}\n# 7. Fetches real data via BallDontLie API for 2025-26 NHL (adapt endpoints as per latest API docs).\n# 8. Backtest metrics: win rate, ROI, profit curve. Analyzes final top-10 vs playoff prediction.\n# 9. Expected assists: assumed in player logs as 'expected_assists' (fallback to primary_assists).\n# 10. Historical note: This is single-season backtest for 2025-26; extend seasons[] for multi-year.\n# Risk Warning: Medium risk strategy. Assumes even-money odds (-110-ish normalized to even for sim). High variance in player props/team ML.\n\ndef fetch_balldontlie_data(season: str, league: str = 'nhl') -> tuple[List[Dict], List[Dict], List[Dict]]:\n    """\n    Fetch games, player game logs (stats), teams from BallDontLie API.\n    Note: Adapt if exact endpoints differ; BallDontLie supports NHL player stats/game logs.\n    """\n    base_url = "https://www.balldontlie.io/api/v1"\n    \n    # Fetch games for season\n    games_url = f"{base_url}/games?seasons[]={season}&league={league}&per_page=100"\n    games_resp = requests.get(games_url).json()\n    games = games_resp['data']\n    \n    # Fetch player stats/game logs (assumes /stats endpoint supports game_logs= true or separate)\n    # For sim: use /stats?season={season}&player_game_logs=true&league={league}\n    stats_url = f"{base_url}/stats?seasons[]={season}&league={league}&per_page=100"\n    stats_resp = requests.get(stats_url).json()\n    player_logs = stats_resp['data']  # Transform to per-game if aggregate\n    \n    # Fetch teams\n    teams_url = f"{base_url}/teams?league={league}"\n    teams_resp = requests.get(teams_url).json()\n    teams = teams_resp['data']\n    \n    # Post-process player_logs to include primary_assists (proxy if not: assists * 0.6), expected_assists (if avail)\n    for log in player_logs:\n        log['primary_assists'] = log.get('primary_assists', log.get('assists', 0) * 0.6)  # Proxy\n        log['expected_assists'] = log.get('expected_assists', log['primary_assists'])  # Proxy\n        log['player_id'] = log.get('id', log['player_id'])  # Normalize\n    \n    return games, player_logs, teams\n\ndef generate_bets(games: List[Dict], players: List[Dict], teams: List[Dict], params: Dict[str, Any]) -> List[Dict]:\n    """\n    Core strategy function: Generates bets for given games using current cumulative state in params.\n    """\n    cumulative_stats = params.get('cumulative_stats', {})\n    min_gp = params.get('min_gp', 10)\n    top_n = params.get('top_n', 10)\n    base_stake = params.get('base_stake', 50)  # Medium risk\n    kuch_name = 'Nikita Kucherov'\n    \n    # Get current top playmakers by primary_assists_per_game (pref expected_assists_per_game)\n    candidates = [\n        (pid, stats) for pid, stats in cumulative_stats.items()\n        if stats['gp'] >= min_gp and stats.get('team_id')\n    ]\n    top_playmakers = sorted(candidates, key=lambda x: x[1].get('expected_assists_per_game', x[1]['primary_assists_per_game']), reverse=True)[:top_n]\n    top_teams = {stats['team_id'] for _, stats in top_playmakers}\n    \n    bets = []\n    for game in games:\n        home_id = game['home_team_id']\n        away_id = game['away_team_id']\n        \n        bet_conf = 0.55  # Base\n        stake = base_stake\n        \n        # Check home\n        if home_id in top_teams:\n            bet_conf += 0.1\n            bets.append({\n                'game_id': game['id'],\n                'bet_type': 'moneyline',\n                'prediction': 'home',\n                'confidence': min(0.85, bet_conf),\n                'stake': stake\n            })\n        \n        # Check away\n        if away_id in top_teams:\n            bet_conf += 0.1\n            bets.append({\n                'game_id': game['id'],\n                'bet_type': 'moneyline',\n                'prediction': 'away',\n                'confidence': min(0.85, bet_conf),\n                'stake': stake\n            })\n        \n        # Kucherov boost: if his team playing and top-3 efficiency\n        kuch_pid = next((p['player_id'] for p in players if p['player_name'] == kuch_name), None)\n        if kuch_pid and kuch_pid in cumulative_stats:\n            kuch_stats = cumulative_stats[kuch_pid]\n            if kuch_stats['gp'] >= min_gp:\n                kuch_metric = kuch_stats.get('expected_assists_per_game', kuch_stats['primary_assists_per_game'])\n                if kuch_metric >= sorted([s[1].get('expected_assists_per_game', s[1]['primary_assists_per_game']) for s in top_playmakers], reverse=True)[2]:  # Top-3 proxy\n                    bet_conf += 0.15\n                    stake *= 1.5  # Medium risk increase\n                    team_id = kuch_stats['team_id']\n                    pred = 'home' if home_id == team_id else 'away'\n                    bets.append({\n                        'game_id': game['id'],\n                        'bet_type': 'moneyline',\n                        'prediction': pred,\n                        'confidence': min(0.95, bet_conf),\n                        'stake': stake,\n                        'reason': 'Kucherov top playmaker boost'\n                    })\n    \n    return bets\n\ndef backtest_strategy(games: List[Dict], player_logs: List[Dict], teams: List[Dict], params: Dict[str, Any]) -> Dict[str, Any]:\n    """\n    Full stateful backtest: Iterates chronologically, generates bets pre-game, settles post-game.\n    Updates cumulative stats post-game.\n    """\n    # Sort games by date\n    games = sorted(games, key=lambda g: datetime.fromisoformat(g['date'].replace('Z', '+00:00')))\n    \n    # Group player_logs by player_id for quick lookup\n    player_dict = defaultdict(list)\n    for log in player_logs:\n        player_dict[log['player_id']].append(log)\n    \n    # Initialize cumulative stats: track team_id/name from first log\n    cumulative_stats = {}\n    for pid, logs in player_dict.items():\n        if logs:\n            first_log = logs[0]\n            cumulative_stats[pid] = {\n                'gp': 0,\n                'primary_assists': 0,\n                'expected_assists': 0,\n                'primary_assists_per_game': 0,\n                'expected_assists_per_game': 0,\n                'team_id': first_log['team_id'],\n                'name': first_log['player_name']\n            }\n    \n    bankroll_history = [params.get('initial_bankroll', 1000)]\n    total_wins = 0\n    total_bets = 0\n    total_staked = 0\n    bets_history = []\n    team_wins = defaultdict(int)  # For playoff proxy\n    \n    for game in games:\n        # Pre-game: generate bets with current cumulative\n        current_params = params.copy()\n        current_params['cumulative_stats'] = cumulative_stats\n        current_bets = generate_bets([game], player_logs, teams, current_params)\n        bets_history.extend(current_bets)\n        \n        # Simulate outcomes (even money odds: win +stake, loss -stake)\n        home_win = game.get('home_score', 0) > game.get('away_score', 0)\n        for bet in current_bets:\n            total_bets += 1\n            total_staked += bet['stake']\n\n⚠️ **Note:** Live backtesting encountered an issue. Please try again or use the Strategy Playground for detailed analysis.