{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Competitors Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: openpyxl in /opt/python/lib/python3.13/site-packages (3.1.5)\n",
      "Requirement already satisfied: et-xmlfile in /opt/python/lib/python3.13/site-packages (from openpyxl) (2.0.0)\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "!pip install openpyxl\n",
    "import os\n",
    "import s3fs\n",
    "import seaborn as sns\n",
    "import plotly.express as px\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "fs = s3fs.S3FileSystem(\n",
    "    client_kwargs={'endpoint_url': 'https://'+'minio-simple.lab.groupe-genes.fr'},\n",
    "    key = os.environ[\"AWS_ACCESS_KEY_ID\"], \n",
    "    secret = os.environ[\"AWS_SECRET_ACCESS_KEY\"], \n",
    "    token = os.environ[\"AWS_SESSION_TOKEN\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "with fs.open('s3://projet-bdc-data/carmignac/Data Modélisation/competitors/weekly_perf_full.csv', 'rb') as f:\n",
    "    weekly_perf = pd.read_csv(f, sep=\";\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "weekly_perf[\"Date\"] = pd.to_datetime(weekly_perf['Date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "weekly_perf.to_csv('weekly_perf_full.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Time span of each competitor fund"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                         First_Appearance Last_Appearance\n",
      "shareClass_name                                                          \n",
      "AB EM Multi-Asset A EUR H                      2012-12-01      2025-09-27\n",
      "AB European Growth A EUR                       2024-03-23      2025-09-27\n",
      "AB European Income A2 EUR                      2012-12-01      2025-09-27\n",
      "AB Event Driven S1 EUR H                       2020-03-21      2025-09-27\n",
      "AB Global Dynamic Bond I2 GBP                  2014-06-21      2025-09-27\n",
      "...                                                   ...             ...\n",
      "iShares MSCI EM ex China ETF USD Acc           2021-05-29      2025-09-27\n",
      "iShares € Aggt Bd ESG SRI ETF EUR Dist         2012-12-01      2025-09-27\n",
      "iShares € Corp Bd 0-3yr ESG SRI ETF€Dist       2016-02-06      2025-09-27\n",
      "iShares € Govt Bond 1-3yr ETF EUR Dist         2012-12-01      2025-09-27\n",
      "ÖkoWorld ÖkoVision Classic C                   2015-01-07      2015-12-30\n",
      "\n",
      "[1012 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "span_df = weekly_perf.groupby('shareClass_name')['Date'].agg(['min', 'max'])\n",
    "\n",
    "span_df.columns = ['First_Appearance', 'Last_Appearance']\n",
    "\n",
    "print(span_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "carmignac_funds = weekly_perf[weekly_perf['shareClass_name'].str.contains(\"Carmignac\", case=False, na=False)]\n",
    "carmignac_span = carmignac_funds.groupby('shareClass_name')['Date'].agg(['min', 'max'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "carmignac_funds.to_csv(\"carmignac_perf.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>min</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>shareClass_name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AXA Sel Carmignac Convictions Instl I €</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AXA Sel Carmignac Convictions Rtl R EUR</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Best Carmignac FI</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carmignac Absolute Ret Eur A EUR Acc</th>\n",
       "      <td>2012-12-01</td>\n",
       "      <td>2025-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carmignac Absolute Ret Eur A EUR Ydis</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Multimgrs Equilibre-Carmignac Patrim I</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Multimgrs Equilibre-Carmignac Patrim P</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Multimgrs Equilibre-Carmignac Patrim S</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nomura Carmignac Fund A</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nomura Carmignac Fund B</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>224 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               min        max\n",
       "shareClass_name                                              \n",
       "AXA Sel Carmignac Convictions Instl I € 2015-01-07 2015-12-30\n",
       "AXA Sel Carmignac Convictions Rtl R EUR 2015-01-07 2015-12-30\n",
       "Best Carmignac FI                       2015-01-07 2015-12-30\n",
       "Carmignac Absolute Ret Eur A EUR Acc    2012-12-01 2025-09-27\n",
       "Carmignac Absolute Ret Eur A EUR Ydis   2015-01-07 2015-12-30\n",
       "...                                            ...        ...\n",
       "Multimgrs Equilibre-Carmignac Patrim I  2015-01-07 2015-12-30\n",
       "Multimgrs Equilibre-Carmignac Patrim P  2015-01-07 2015-12-30\n",
       "Multimgrs Equilibre-Carmignac Patrim S  2015-01-07 2015-12-30\n",
       "Nomura Carmignac Fund A                 2015-01-07 2015-12-30\n",
       "Nomura Carmignac Fund B                 2015-01-07 2015-12-30\n",
       "\n",
       "[224 rows x 2 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "carmignac_span_filtered = carmignac_span[carmignac_span[\"max\"] >= 2025-12]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Other"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              Date perfPeriod                        shareClass_name  \\\n",
      "4       2012-12-29     1YrRet  Carmignac Pf Asia Discovery A EUR Acc   \n",
      "11      2012-12-29     1YrRet  Carmignac Pf Asia Discovery F EUR Acc   \n",
      "16      2013-01-05     1YrRet  Carmignac Pf Asia Discovery F EUR Acc   \n",
      "26      2013-01-05     1YrRet  Carmignac Pf Asia Discovery A EUR Acc   \n",
      "32      2013-01-12     1YrRet  Carmignac Pf Asia Discovery F EUR Acc   \n",
      "...            ...        ...                                    ...   \n",
      "2370113 2015-12-30  WeeklyRet     Carmignac Pf Global Bond A EUR Acc   \n",
      "2370124 2015-12-30  WeeklyRet  Carmignac Pf Asia Discovery F EUR Acc   \n",
      "2370142 2015-12-30  WeeklyRet  Carmignac Pf Investissement A EUR Acc   \n",
      "2370150 2015-12-30  WeeklyRet         Carmignac Patrimoine A EUR Acc   \n",
      "2370157 2015-12-30  WeeklyRet       Carmignac Pf Sécurité FW EUR Acc   \n",
      "\n",
      "            return  percentile   max_date  \n",
      "4        15.370509         2.0 2025-09-27  \n",
      "11       15.364424         2.0 2025-09-27  \n",
      "16       15.487607         2.0 2025-09-27  \n",
      "26       15.487613         2.0 2025-09-27  \n",
      "32       10.613214         6.0 2025-09-27  \n",
      "...            ...         ...        ...  \n",
      "2370113   0.014101        51.0 2025-09-27  \n",
      "2370124  -0.179625        90.0 2025-09-27  \n",
      "2370142   0.387834        68.0 2025-09-27  \n",
      "2370150   0.105970        72.0 2025-09-27  \n",
      "2370157   0.019303        51.0 2025-09-27  \n",
      "\n",
      "[140423 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "df = weekly_perf\n",
    "\n",
    "# 1. Ensure Date is datetime format [cite: 1, 2]\n",
    "df['Date'] = pd.to_datetime(df['Date'])\n",
    "\n",
    "# 2. Create the 'max' (Last Appearance) column for each fund [cite: 1, 2]\n",
    "df['max_date'] = df.groupby('shareClass_name')['Date'].transform('max')\n",
    "\n",
    "# 3. Define your target date\n",
    "target_value = pd.to_datetime('2025-01-01')\n",
    "\n",
    "# 4. Filter for Carmignac funds that appeared AFTER the target value\n",
    "# This keeps all historical rows for funds whose LAST appearance > target\n",
    "filtered_carmignac = df[\n",
    "    (df['shareClass_name'].str.contains(\"Carmignac\", case=False)) & \n",
    "    (df['max_date'] > target_value)\n",
    "]\n",
    "\n",
    "print(filtered_carmignac)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Rest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42744 characters]",
      "text/plain": [
       "<Figure size 1000x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize=(10, 5))\n",
    "aum_by_asset_type.plot(kind='bar', ax=ax, color='steelblue', edgecolor='navy', alpha=0.8)\n",
    "ax.set_title('AUM Distribution by Product - Asset Type')\n",
    "ax.set_xlabel('Product - Asset Type')\n",
    "ax.set_ylabel('Total AUM (€)')\n",
    "ax.tick_params(axis='x', rotation=45)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 69628 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# For each asset type: AUM per account (sum across funds/dates)\n",
    "aum_per_account = stocks.groupby(['Product - Asset Type', 'Registrar Account - ID'], dropna=False)['Value - AUM €'].sum().reset_index()\n",
    "\n",
    "# Build cumulative concentration curves per asset type\n",
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "\n",
    "for asset_type in aum_per_account['Product - Asset Type'].unique():\n",
    "    subset = aum_per_account[aum_per_account['Product - Asset Type'] == asset_type].copy()\n",
    "    subset = subset.sort_values('Value - AUM €', ascending=False).reset_index(drop=True)\n",
    "    \n",
    "    total_aum = subset['Value - AUM €'].sum()\n",
    "    if total_aum == 0:\n",
    "        continue\n",
    "    \n",
    "    subset['cumsum_aum'] = subset['Value - AUM €'].cumsum()\n",
    "    subset['cumsum_pct'] = 100 * subset['cumsum_aum'] / total_aum\n",
    "    subset['n_accounts'] = range(1, len(subset) + 1)\n",
    "    \n",
    "    ax.plot(subset['n_accounts'], subset['cumsum_pct'], label=asset_type if pd.notna(asset_type) else '(empty)', linewidth=2)\n",
    "\n",
    "ax.axhline(y=90, color='gray', linestyle='--', alpha=0.5, label='90% threshold')\n",
    "ax.set_xlabel('Number of accounts (sorted by AUM, largest first)')\n",
    "ax.set_ylabel('Cumulative % of total AUM')\n",
    "ax.set_title('Account concentration: how many accounts hold X% of each asset type?')\n",
    "ax.legend(loc='lower right')\n",
    "ax.grid(True, alpha=0.3)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Product - Asset Type</th>\n",
       "      <th>50% of AUM</th>\n",
       "      <th>75% of AUM</th>\n",
       "      <th>90% of AUM</th>\n",
       "      <th>95% of AUM</th>\n",
       "      <th>99% of AUM</th>\n",
       "      <th>Total accounts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alternative</td>\n",
       "      <td>19</td>\n",
       "      <td>80</td>\n",
       "      <td>193</td>\n",
       "      <td>309</td>\n",
       "      <td>667</td>\n",
       "      <td>2679</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Diversified</td>\n",
       "      <td>36</td>\n",
       "      <td>113</td>\n",
       "      <td>289</td>\n",
       "      <td>480</td>\n",
       "      <td>1100</td>\n",
       "      <td>8846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Equity</td>\n",
       "      <td>35</td>\n",
       "      <td>125</td>\n",
       "      <td>331</td>\n",
       "      <td>556</td>\n",
       "      <td>1378</td>\n",
       "      <td>9123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Fixed Income</td>\n",
       "      <td>33</td>\n",
       "      <td>114</td>\n",
       "      <td>307</td>\n",
       "      <td>514</td>\n",
       "      <td>1132</td>\n",
       "      <td>7348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Private Assets</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Product - Asset Type  50% of AUM  75% of AUM  90% of AUM  95% of AUM  \\\n",
       "0          Alternative          19          80         193         309   \n",
       "1          Diversified          36         113         289         480   \n",
       "2               Equity          35         125         331         556   \n",
       "3         Fixed Income          33         114         307         514   \n",
       "4       Private Assets           1           1           1           1   \n",
       "\n",
       "   99% of AUM  Total accounts  \n",
       "0         667            2679  \n",
       "1        1100            8846  \n",
       "2        1378            9123  \n",
       "3        1132            7348  \n",
       "4           3              18  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Summary: number of accounts holding X% of each asset type\n",
    "thresholds = [50, 75, 90, 95, 99]\n",
    "results = []\n",
    "\n",
    "for asset_type in aum_per_account['Product - Asset Type'].unique():\n",
    "    subset = aum_per_account[aum_per_account['Product - Asset Type'] == asset_type].copy()\n",
    "    subset = subset.sort_values('Value - AUM €', ascending=False).reset_index(drop=True)\n",
    "    total_aum = subset['Value - AUM €'].sum()\n",
    "    if total_aum == 0:\n",
    "        continue\n",
    "    \n",
    "    cumsum_pct = 100 * subset['Value - AUM €'].cumsum() / total_aum\n",
    "    \n",
    "    row = {'Product - Asset Type': asset_type if pd.notna(asset_type) else '(empty)'}\n",
    "    for pct in thresholds:\n",
    "        n_accounts = (cumsum_pct >= pct).idxmax() + 1 if (cumsum_pct >= pct).any() else len(subset)\n",
    "        row[f'{pct}% of AUM'] = n_accounts\n",
    "    row['Total accounts'] = len(subset)\n",
    "    results.append(row)\n",
    "\n",
    "pd.DataFrame(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alternative: 309 accounts (95% AUM) → 50947 rows → aum_95pct_by_asset_type/aum_alternative_95pct.csv\n",
      "Diversified: 480 accounts (95% AUM) → 354694 rows → aum_95pct_by_asset_type/aum_diversified_95pct.csv\n",
      "Equity: 556 accounts (95% AUM) → 431011 rows → aum_95pct_by_asset_type/aum_equity_95pct.csv\n",
      "Fixed Income: 514 accounts (95% AUM) → 345213 rows → aum_95pct_by_asset_type/aum_fixed_income_95pct.csv\n",
      "Private Assets: 1 accounts (95% AUM) → 88 rows → aum_95pct_by_asset_type/aum_private_assets_95pct.csv\n",
      "nan: 4 accounts (95% AUM) → 3076 rows → aum_95pct_by_asset_type/aum_empty_95pct.csv\n",
      "\n",
      "Done. Files saved in 'aum_95pct_by_asset_type/'\n"
     ]
    }
   ],
   "source": [
    "OUTPUT_DIR = 'aum_95pct_by_asset_type'\n",
    "os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
    "\n",
    "def safe_filename(asset_type):\n",
    "    \"\"\"Convert asset type to a safe filename.\"\"\"\n",
    "    if pd.isna(asset_type) or str(asset_type).strip() == '':\n",
    "        return 'empty'\n",
    "    return re.sub(r'[^\\w\\-]', '_', str(asset_type).strip().lower().replace(' ', '_'))\n",
    "\n",
    "# For each asset type: get accounts holding 95% of AUM\n",
    "for asset_type in aum_per_account['Product - Asset Type'].unique():\n",
    "    if pd.isna(asset_type):\n",
    "        subset = aum_per_account[aum_per_account['Product - Asset Type'].isna()].copy()\n",
    "    else:\n",
    "        subset = aum_per_account[aum_per_account['Product - Asset Type'] == asset_type].copy()\n",
    "    subset = subset.sort_values('Value - AUM €', ascending=False).reset_index(drop=True)\n",
    "    total_aum = subset['Value - AUM €'].sum()\n",
    "    \n",
    "    if total_aum == 0:\n",
    "        n_accounts_95 = 0\n",
    "        accounts_95 = set()\n",
    "    else:\n",
    "        cumsum_pct = 100 * subset['Value - AUM €'].cumsum() / total_aum\n",
    "        n_accounts_95 = (cumsum_pct >= 95).idxmax() + 1 if (cumsum_pct >= 95).any() else len(subset)\n",
    "        accounts_95 = set(subset.head(n_accounts_95)['Registrar Account - ID'])\n",
    "    \n",
    "    # Extract all rows from original df for these accounts AND this asset type\n",
    "    if pd.isna(asset_type):\n",
    "        type_mask = stocks['Product - Asset Type'].isna()\n",
    "    else:\n",
    "        type_mask = stocks['Product - Asset Type'] == asset_type\n",
    "    mask = type_mask & (stocks['Registrar Account - ID'].isin(accounts_95))\n",
    "    df_subset = stocks.loc[mask]\n",
    "    \n",
    "    filename = f\"aum_{safe_filename(asset_type)}_95pct.csv\"\n",
    "    filepath = os.path.join(OUTPUT_DIR, filename)\n",
    "    df_subset.to_csv(filepath, index=False)\n",
    "    \n",
    "    print(f\"{asset_type or '(empty)'}: {len(accounts_95)} accounts (95% AUM) → {len(df_subset)} rows → {filepath}\")\n",
    "\n",
    "print(f\"\\nDone. Files saved in '{OUTPUT_DIR}/'\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sum of AUM by Product - Fund"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AUM (€) by Product - Fund:\n",
      "Product - Fund\n",
      "Carmignac Patrimoine                                         1.838372e+12\n",
      "Carmignac Sécurité                                           1.053010e+12\n",
      "Carmignac Investissement                                     5.300035e+11\n",
      "Carmignac Portfolio Sécurité                                 2.562135e+11\n",
      "Carmignac Portfolio Flexible Bond                            2.223185e+11\n",
      "Carmignac Portfolio Patrimoine                               2.035761e+11\n",
      "Carmignac Emergents                                          1.218833e+11\n",
      "Carmignac Portfolio Global Bond                              1.119945e+11\n",
      "Carmignac Portfolio Credit                                   8.413277e+10\n",
      "Carmignac Court Terme                                        8.224046e+10\n",
      "Carmignac Portfolio Emerging Patrimoine                      7.216283e+10\n",
      "Carmignac Portfolio Grande Europe                            6.404670e+10\n",
      "Carmignac Portfolio Long-Short European Equities             6.162365e+10\n",
      "Carmignac Portfolio Climate Transition                       5.125412e+10\n",
      "Carmignac Absolute Return Europe                             4.100414e+10\n",
      "Carmignac Credit 2027                                        3.937522e+10\n",
      "Carmignac Portfolio Patrimoine Europe                        3.880186e+10\n",
      "Carmignac Portfolio Investissement                           3.643094e+10\n",
      "Carmignac Investissement Latitude                            3.474053e+10\n",
      "Carmignac Portfolio Emergents                                2.942745e+10\n",
      "Carmignac Portfolio Asia Discovery                           2.934378e+10\n",
      "Carmignac Multi Expertise                                    2.633552e+10\n",
      "Carmignac Euro-Entrepreneurs                                 2.522512e+10\n",
      "Carmignac Credit 2029                                        1.738790e+10\n",
      "Carmignac Portfolio Grandchildren                            1.627555e+10\n",
      "Carmignac Credit 2025                                        1.547217e+10\n",
      "Fonditalia Carmignac Active Allocation                       1.452571e+10\n",
      "Carmignac Portfolio EM Debt                                  1.231814e+10\n",
      "UFF Grande Europe 0-100                                      1.222263e+10\n",
      "Carmignac Profil Réactif 75                                  1.178726e+10\n",
      "Carmignac Global Active                                      1.079949e+10\n",
      "Carmignac Profil Réactif 100                                 1.032957e+10\n",
      "FP Carmignac European Leaders                                8.759356e+09\n",
      "Mapfre Carmignac F.P.                                        8.205244e+09\n",
      "Carmignac Portfolio Flexible Allocation 2024                 6.464648e+09\n",
      "Carmignac China New Economy                                  5.961919e+09\n",
      "Carmignac Portfolio Investissement Latitude                  5.955304e+09\n",
      "Carmignac Credit 2031                                        5.310328e+09\n",
      "FP Carmignac Global Equity Compounders                       4.482628e+09\n",
      "Carmignac Portfolio Merger Arbitrage Plus                    4.335203e+09\n",
      "Credit Suisse Carmignac Emerging Markets Multi-Asset Fund    3.920236e+09\n",
      "Carmignac Portfolio Euro-Entrepreneurs                       3.670384e+09\n",
      "Carmignac Portfolio Merger Arbitrage                         3.643225e+09\n",
      "Carmignac Portfolio Human Xperience                          3.477910e+09\n",
      "Carmignac Alts ICAV Carmignac Credit Opportunities           3.294673e+09\n",
      "Carmignac Alts ICAV European Long Short                      3.260443e+09\n",
      "Carmignac Portfolio Capital Cube                             2.773859e+09\n",
      "Carmignac Portfolio China New Economy                        2.757754e+09\n",
      "FP Carmignac Emerging Markets                                2.224219e+09\n",
      "FP Carmignac Global Bond                                     2.208401e+09\n",
      "Carmignac S.A. SICAV - PART II UCI Private Evergreen         2.205183e+09\n",
      "Carmignac Portfolio Family Governed                          2.104642e+09\n",
      "Carmignac Portfolio Tech Solutions                           1.812327e+09\n",
      "FP Carmignac Emerging Patrimoine                             1.486110e+09\n",
      "Carmignac Portfolio Long-Short Global Equities               1.450546e+09\n",
      "FP Carmignac Patrimoine                                      1.367843e+09\n",
      "FP Carmignac Emerging Discovery                              1.315189e+09\n",
      "Carmignac Portfolio Global Market Neutral                    8.912455e+08\n",
      "Carmignac Portfolio China                                    8.898217e+08\n",
      "Carmignac Portfolio Inflation Solution                       8.063914e+08\n",
      "Carmignac Portfolio Absolute Return Europe                   7.929928e+08\n",
      "Solys - Carmignac Equity Selection                           6.677506e+08\n",
      "LUX IM - Carmignac Emerging Flexible Bond                    6.397498e+08\n",
      "Carmignac Portfolio Evolution                                5.464840e+08\n",
      "Carmignac Portfolio Alpha Themes                             5.085499e+08\n",
      "Carmignac Portfolio Active Risk Allocation                   3.816403e+08\n",
      "Carmignac Portfolio Cross Asset Opportunities                2.291751e+08\n",
      "Carmignac Portfolio Sustainable Bond                         6.016398e+07\n",
      "Carmignac Epargne Actions Monde ISR                          1.858147e+07\n",
      "CFP 1                                                        2.300000e+02\n",
      "Carmignac Innovation                                         0.000000e+00\n",
      "Carmignac Euro-Investissement                                0.000000e+00\n",
      "Carmignac Portfolio Infotech                                 0.000000e+00\n",
      "Carmignac Portfolio Market Neutral                           0.000000e+00\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Product - Fund</th>\n",
       "      <th>Total AUM (€)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Carmignac Patrimoine</td>\n",
       "      <td>1.838372e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Carmignac Sécurité</td>\n",
       "      <td>1.053010e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Carmignac Investissement</td>\n",
       "      <td>5.300035e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Carmignac Portfolio Sécurité</td>\n",
       "      <td>2.562135e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Carmignac Portfolio Flexible Bond</td>\n",
       "      <td>2.223185e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>CFP 1</td>\n",
       "      <td>2.300000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>Carmignac Innovation</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>Carmignac Euro-Investissement</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>Carmignac Portfolio Infotech</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>Carmignac Portfolio Market Neutral</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>74 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Product - Fund  Total AUM (€)\n",
       "0                 Carmignac Patrimoine   1.838372e+12\n",
       "1                   Carmignac Sécurité   1.053010e+12\n",
       "2             Carmignac Investissement   5.300035e+11\n",
       "3         Carmignac Portfolio Sécurité   2.562135e+11\n",
       "4    Carmignac Portfolio Flexible Bond   2.223185e+11\n",
       "..                                 ...            ...\n",
       "69                               CFP 1   2.300000e+02\n",
       "70                Carmignac Innovation   0.000000e+00\n",
       "71       Carmignac Euro-Investissement   0.000000e+00\n",
       "72        Carmignac Portfolio Infotech   0.000000e+00\n",
       "73  Carmignac Portfolio Market Neutral   0.000000e+00\n",
       "\n",
       "[74 rows x 2 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Sum Value - AUM € per Product - Fund\n",
    "aum_by_fund = stocks.groupby('Product - Fund', dropna=False)['Value - AUM €'].sum().sort_values(ascending=False)\n",
    "\n",
    "print(\"AUM (€) by Product - Fund:\")\n",
    "print(aum_by_fund.to_string())\n",
    "\n",
    "# Display as DataFrame for nicer formatting\n",
    "aum_by_fund_df = aum_by_fund.reset_index()\n",
    "aum_by_fund_df.columns = ['Product - Fund', 'Total AUM (€)']\n",
    "aum_by_fund_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 365640 characters]",
      "text/plain": [
       "<Figure size 1000x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize=(10, 8))\n",
    "aum_by_fund.plot(kind='barh', ax=ax, color='coral', edgecolor='darkred', alpha=0.8)\n",
    "ax.set_title('AUM Distribution by Product - Fund')\n",
    "ax.set_xlabel('Total AUM (€)')\n",
    "ax.set_ylabel('Product - Fund')\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
