diff --git "a/notebooks/retention_metrics.ipynb" "b/notebooks/retention_metrics.ipynb" --- "a/notebooks/retention_metrics.ipynb" +++ "b/notebooks/retention_metrics.ipynb" @@ -21,13 +21,33 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 113, "metadata": {}, "outputs": [], "source": [ "retention_df = pd.read_parquet(\"../data/retention_activity.parquet\")" ] }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1020643" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(retention_df)" + ] + }, { "cell_type": "code", "execution_count": 91, @@ -50,6 +70,90 @@ "retention_df.columns" ] }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "month_year_week\n", + "Jan-12-2025 148192\n", + "Dec-15-2024 136640\n", + "Dec-22-2024 136529\n", + "Jan-05-2025 136190\n", + "Dec-29-2024 128665\n", + "Dec-08-2024 109545\n", + "Nov-24-2024 72777\n", + "Dec-01-2024 67851\n", + "Jan-19-2025 53165\n", + "Nov-17-2024 31089\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retention_df.month_year_week.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "month_year_week\n", + "Jan-14-2025 30424\n", + "Jan-01-2025 28494\n", + "Jan-07-2025 28200\n", + "Jan-11-2025 26174\n", + "Jan-09-2025 22810\n", + " ... \n", + "Nov-14-2024 8757\n", + "Nov-25-2024 8112\n", + "Nov-15-2024 7658\n", + "Nov-17-2024 4967\n", + "Jan-15-2025 3728\n", + "Name: count, Length: 63, dtype: int64" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retention_df.month_year_week.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "136190" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jan5 = retention_df.loc[retention_df[\"month_year_week\"]==\"Jan-05-2025\"]\n", + "len(jan5)" + ] + }, { "cell_type": "code", "execution_count": 42, @@ -83,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 130, "metadata": {}, "outputs": [], "source": [ @@ -94,13 +198,62 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 131, "metadata": {}, "outputs": [], "source": [ "olas_data = retention_df.loc[retention_df[\"trader_type\"]==\"Olas\"]" ] }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [], + "source": [ + "jan5 = olas_data.loc[olas_data[\"month_year_week\"]==\"Jan-05-2025\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "193" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jan5.trader_address.nunique()" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "31363" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(jan5)" + ] + }, { "cell_type": "code", "execution_count": 45, @@ -553,12 +706,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 135, "metadata": {}, "outputs": [], "source": [ - "# read trades dataset\n", - "traders_df = pd.read_parquet(\"../data/all_trades_profitability.parquet\")" + "def prepare_retention_dataset(\n", + " retention_df: pd.DataFrame, unknown_df: pd.DataFrame\n", + ") -> pd.DataFrame:\n", + "\n", + " retention_df[\"trader_type\"] = retention_df[\"staking\"].apply(\n", + " lambda x: \"non_Olas\" if x == \"non_Olas\" else \"Olas\"\n", + " )\n", + " retention_df.rename(columns={\"request_time\": \"creation_timestamp\"}, inplace=True)\n", + " retention_df = retention_df[\n", + " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", + " ]\n", + " unknown_df[\"trader_type\"] = \"unclassified\"\n", + " unknown_df = unknown_df[\n", + " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", + " ]\n", + " all_traders = pd.concat([retention_df, unknown_df], ignore_index=True)\n", + "\n", + " all_traders[\"creation_timestamp\"] = pd.to_datetime(\n", + " all_traders[\"creation_timestamp\"]\n", + " )\n", + " all_traders = all_traders.sort_values(by=\"creation_timestamp\", ascending=True)\n", + " all_traders[\"month_year_week\"] = (\n", + " all_traders[\"creation_timestamp\"].dt.to_period(\"W\").dt.strftime(\"%b-%d-%Y\")\n", + " )\n", + " return all_traders" ] }, { @@ -571,65 +747,6 @@ "unknown_df = pd.read_parquet(\"../data/unknown_traders.parquet\")\n" ] }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "staking\n", - "non_Olas 56266\n", - "non_staking 20954\n", - "pearl 6084\n", - "quickstart 3975\n", - "Name: count, dtype: int64" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "traders_df.staking.value_counts()" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "traders_df[\"trader_type\"] = traders_df[\"staking\"].apply(\n", - " lambda x: \"non_Olas\" if x == \"non_Olas\" else \"Olas\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "trader_type\n", - "non_Olas 56266\n", - "Olas 31013\n", - "Name: count, dtype: int64" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "traders_df.trader_type.value_counts()" - ] - }, { "cell_type": "code", "execution_count": 26, @@ -663,29 +780,38 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 136, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/2945974734.py:23: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.\n", + " all_traders[\"creation_timestamp\"].dt.to_period(\"W\").dt.strftime(\"%b-%d-%Y\")\n" + ] + } + ], "source": [ - "all_traders = pd.concat([traders_df, unknown_df], ignore_index=True)" + "all_traders = prepare_retention_dataset(retention_df=retention_df, unknown_df=unknown_df)" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 137, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "trader_type\n", - "non_Olas 56266\n", - "Olas 31013\n", - "unclassified 1654\n", + "non_Olas 738323\n", + "Olas 282320\n", + "unclassified 3531\n", "Name: count, dtype: int64" ] }, - "execution_count": 31, + "execution_count": 137, "metadata": {}, "output_type": "execute_result" } @@ -696,7 +822,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 138, "metadata": {}, "outputs": [ { @@ -726,15 +852,25 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 212, "metadata": {}, "outputs": [], "source": [ - "def calculate_wow_retention_by_type(df):\n", + "def calculate_wow_retention_by_type(\n", + " df: pd.DataFrame, market_creator: str\n", + ") -> pd.DataFrame:\n", + " filtered_df = df.loc[df[\"market_creator\"] == market_creator]\n", " # Get unique traders per week and type\n", - " weekly_traders = df.groupby(['month_year_week', 'trader_type'])['trader_address'].nunique().reset_index()\n", - " weekly_traders = weekly_traders.sort_values(['trader_type', 'month_year_week'])\n", - " \n", + " weekly_traders = filtered_df.groupby(['month_year_week', 'trader_type'], sort=False)['trader_address'].nunique().reset_index()\n", + " #weekly_traders = weekly_traders.sort_values(['trader_type', 'month_year_week'])\n", + " # Get ordered list of unique weeks - converting to datetime for proper sorting\n", + " all_weeks = filtered_df[\"month_year_week\"].unique()\n", + " weeks_datetime = pd.to_datetime(all_weeks)\n", + " sorted_weeks_idx = weeks_datetime.argsort()\n", + " all_weeks = all_weeks[sorted_weeks_idx]\n", + "\n", + " # Create mapping from week string to numeric index\n", + " week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", " # Calculate retention\n", " retention = []\n", " # Iterate through each trader type\n", @@ -744,7 +880,16 @@ " # Calculate retention for each week within this trader type\n", " for i in range(1, len(type_data)):\n", " current_week = type_data.iloc[i]['month_year_week']\n", - " previous_week = type_data.iloc[i-1]['month_year_week']\n", + " print(f\"current_week={current_week}\")\n", + " week_number = week_to_number[current_week]\n", + " if week_to_number == 0:\n", + " # no previous week info\n", + " continue\n", + " previous_week_number = week_number -1\n", + " # this should give only one value\n", + " previous_week = [key for key in week_to_number.keys() if week_to_number[key] == previous_week_number][0]\n", + " #previous_week = type_data.iloc[i-1]['month_year_week']\n", + " print(f\"previous week = {previous_week}\")\n", " \n", " # Get traders in both weeks for this type\n", " current_traders = set(df[\n", @@ -764,6 +909,7 @@ " 'trader_type': trader_type,\n", " 'week': current_week,\n", " 'retained_traders': retained,\n", + " 'new_traders': \n", " 'previous_traders': len(previous_traders),\n", " 'retention_rate': round(retention_rate, 2)\n", " })\n", @@ -773,16 +919,75 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 213, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "current_week=Nov-24-2024\n", + "previous week = Nov-17-2024\n", + "current_week=Dec-01-2024\n", + "previous week = Nov-24-2024\n", + "current_week=Dec-08-2024\n", + "previous week = Dec-01-2024\n", + "current_week=Dec-15-2024\n", + "previous week = Dec-08-2024\n", + "current_week=Dec-22-2024\n", + "previous week = Dec-15-2024\n", + "current_week=Dec-29-2024\n", + "previous week = Dec-22-2024\n", + "current_week=Jan-05-2025\n", + "previous week = Dec-29-2024\n", + "current_week=Jan-12-2025\n", + "previous week = Jan-05-2025\n", + "current_week=Jan-19-2025\n", + "previous week = Jan-12-2025\n", + "current_week=Nov-24-2024\n", + "previous week = Nov-17-2024\n", + "current_week=Dec-01-2024\n", + "previous week = Nov-24-2024\n", + "current_week=Dec-08-2024\n", + "previous week = Dec-01-2024\n", + "current_week=Dec-15-2024\n", + "previous week = Dec-08-2024\n", + "current_week=Dec-22-2024\n", + "previous week = Dec-15-2024\n", + "current_week=Dec-29-2024\n", + "previous week = Dec-22-2024\n", + "current_week=Jan-05-2025\n", + "previous week = Dec-29-2024\n", + "current_week=Jan-12-2025\n", + "previous week = Jan-05-2025\n", + "current_week=Jan-19-2025\n", + "previous week = Jan-12-2025\n", + "current_week=Nov-24-2024\n", + "previous week = Nov-17-2024\n", + "current_week=Dec-01-2024\n", + "previous week = Nov-24-2024\n", + "current_week=Dec-08-2024\n", + "previous week = Dec-01-2024\n", + "current_week=Dec-15-2024\n", + "previous week = Dec-08-2024\n", + "current_week=Dec-22-2024\n", + "previous week = Dec-15-2024\n", + "current_week=Dec-29-2024\n", + "previous week = Dec-22-2024\n", + "current_week=Jan-05-2025\n", + "previous week = Dec-29-2024\n", + "current_week=Jan-12-2025\n", + "previous week = Jan-05-2025\n" + ] + } + ], "source": [ - "wow_retention = calculate_wow_retention_by_type(all_traders)" + "wow_retention = calculate_wow_retention_by_type(all_traders, market_creator=\"pearl\")" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 216, "metadata": {}, "outputs": [ { @@ -815,70 +1020,58 @@ " \n", " \n", " \n", - " 0\n", - " Olas\n", - " Dec-08-2024\n", - " 93\n", - " 98\n", - " 94.90\n", - " \n", - " \n", - " 1\n", - " Olas\n", - " Dec-15-2024\n", - " 187\n", - " 207\n", - " 90.34\n", - " \n", - " \n", - " 2\n", - " Olas\n", - " Dec-22-2024\n", - " 186\n", - " 213\n", - " 87.32\n", + " 6\n", + " non_Olas\n", + " 2025-01-05\n", + " 333\n", + " 353\n", + " 94.33\n", " \n", " \n", - " 3\n", + " 15\n", " Olas\n", - " Dec-29-2024\n", - " 143\n", - " 203\n", - " 70.44\n", + " 2025-01-05\n", + " 177\n", + " 194\n", + " 91.24\n", " \n", " \n", - " 4\n", - " Olas\n", - " Jan-05-2025\n", - " 117\n", - " 148\n", - " 79.05\n", + " 24\n", + " unclassified\n", + " 2025-01-05\n", + " 2\n", + " 19\n", + " 10.53\n", " \n", " \n", "\n", "" ], "text/plain": [ - " trader_type week retained_traders previous_traders retention_rate\n", - "0 Olas Dec-08-2024 93 98 94.90\n", - "1 Olas Dec-15-2024 187 207 90.34\n", - "2 Olas Dec-22-2024 186 213 87.32\n", - "3 Olas Dec-29-2024 143 203 70.44\n", - "4 Olas Jan-05-2025 117 148 79.05" + " trader_type week retained_traders previous_traders \\\n", + "6 non_Olas 2025-01-05 333 353 \n", + "15 Olas 2025-01-05 177 194 \n", + "24 unclassified 2025-01-05 2 19 \n", + "\n", + " retention_rate \n", + "6 94.33 \n", + "15 91.24 \n", + "24 10.53 " ] }, - "execution_count": 35, + "execution_count": 216, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "wow_retention.head()" + "jan5 = wow_retention.loc[wow_retention[\"week\"]==\"Jan-05-2025\"]\n", + "jan5" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 214, "metadata": {}, "outputs": [ { @@ -911,17 +1104,209 @@ " \n", " \n", " \n", - " 9\n", + " 0\n", " non_Olas\n", - " 2024-12-08\n", - " 154\n", - " 154\n", - " 100.00\n", + " Nov-24-2024\n", + " 157\n", + " 180\n", + " 87.22\n", " \n", " \n", - " 10\n", + " 1\n", " non_Olas\n", - " 2024-12-15\n", + " Dec-01-2024\n", + " 173\n", + " 186\n", + " 93.01\n", + " \n", + " \n", + " 2\n", + " non_Olas\n", + " Dec-08-2024\n", + " 182\n", + " 196\n", + " 92.86\n", + " \n", + " \n", + " 3\n", + " non_Olas\n", + " Dec-15-2024\n", + " 303\n", + " 324\n", + " 93.52\n", + " \n", + " \n", + " 4\n", + " non_Olas\n", + " Dec-22-2024\n", + " 313\n", + " 325\n", + " 96.31\n", + " \n", + " \n", + "\n", + "" + ], + "text/plain": [ + " trader_type week retained_traders previous_traders retention_rate\n", + "0 non_Olas Nov-24-2024 157 180 87.22\n", + "1 non_Olas Dec-01-2024 173 186 93.01\n", + "2 non_Olas Dec-08-2024 182 196 92.86\n", + "3 non_Olas Dec-15-2024 303 324 93.52\n", + "4 non_Olas Dec-22-2024 313 325 96.31" + ] + }, + "execution_count": 214, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wow_retention.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
trader_typeweekretained_tradersprevious_tradersretention_rate
0OlasDec-08-202418720292.57
1OlasDec-15-202421223390.99
2OlasDec-22-202420422789.87
3OlasDec-29-202418721487.38
4OlasJan-05-202517719491.24
\n", + "
" + ], + "text/plain": [ + " trader_type week retained_traders previous_traders retention_rate\n", + "0 Olas Dec-08-2024 187 202 92.57\n", + "1 Olas Dec-15-2024 212 233 90.99\n", + "2 Olas Dec-22-2024 204 227 89.87\n", + "3 Olas Dec-29-2024 187 214 87.38\n", + "4 Olas Jan-05-2025 177 194 91.24" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wow_retention.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -1011,7 +1396,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 142, "metadata": {}, "outputs": [], "source": [ @@ -1065,7 +1450,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 215, "metadata": {}, "outputs": [ { @@ -1091,27 +1476,27 @@ "showlegend": true, "type": "scatter", "x": [ - "2024-11-10T00:00:00", - "2024-11-17T00:00:00", "2024-11-24T00:00:00", + "2024-12-01T00:00:00", "2024-12-08T00:00:00", "2024-12-15T00:00:00", "2024-12-22T00:00:00", "2024-12-29T00:00:00", "2025-01-05T00:00:00", - "2025-01-12T00:00:00" + "2025-01-12T00:00:00", + "2025-01-19T00:00:00" ], "xaxis": "x", "y": [ - 78.57, - 92.99, - 80, - 94.9, - 90.34, - 87.32, - 70.44, - 79.05, - 51.94 + 94.55, + 83.26, + 92.57, + 90.99, + 89.87, + 87.38, + 91.24, + 91.71, + 78.92 ], "yaxis": "y" }, @@ -1131,27 +1516,27 @@ "showlegend": true, "type": "scatter", "x": [ - "2024-11-10T00:00:00", - "2024-11-17T00:00:00", "2024-11-24T00:00:00", + "2024-12-01T00:00:00", "2024-12-08T00:00:00", "2024-12-15T00:00:00", "2024-12-22T00:00:00", "2024-12-29T00:00:00", "2025-01-05T00:00:00", - "2025-01-12T00:00:00" + "2025-01-12T00:00:00", + "2025-01-19T00:00:00" ], "xaxis": "x", "y": [ - 20.32, - 90, - 83.43, - 100, - 92.9, - 96.57, - 91.5, - 93.25, - 73.87 + 87.22, + 93.01, + 92.86, + 93.52, + 96.31, + 95.64, + 94.33, + 94.72, + 94.13 ], "yaxis": "y" }, @@ -1171,6 +1556,8 @@ "showlegend": true, "type": "scatter", "x": [ + "2024-11-24T00:00:00", + "2024-12-01T00:00:00", "2024-12-08T00:00:00", "2024-12-15T00:00:00", "2024-12-22T00:00:00", @@ -1180,12 +1567,14 @@ ], "xaxis": "x", "y": [ - 100, - 75, + 13.21, + 17.07, + 80, + 7.09, 90, - 19.35, - 11.11, - 0 + 20.97, + 10.53, + 28.57 ], "yaxis": "y" } @@ -2044,7 +2433,7 @@ ], "range": [ 0, - 110.00000000000001 + 105.94100000000002 ], "ticksuffix": "%", "title": { @@ -2064,100 +2453,1107 @@ "fig.show()" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Cohort retention" - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": {}, - "outputs": [], - "source": [ - "def calculate_cohort_retention(\n", - " df: pd.DataFrame, market_creator: str, trader_type: str\n", - ") -> pd.DataFrame:\n", - " df_filtered = df.loc[\n", - " (df[\"market_creator\"] == market_creator) & (df[\"trader_type\"] == trader_type)\n", - " ]\n", - " # Get first week for each trader\n", - " first_trades = (\n", - " df_filtered.groupby(\"trader_address\")\n", - " .agg({\"creation_timestamp\": \"min\", \"month_year_week\": \"first\"})\n", - " .reset_index()\n", - " )\n", - " first_trades.columns = [\"trader_address\", \"first_trade\", \"cohort_week\"]\n", - "\n", - " # Get ordered list of unique weeks - converting to datetime for proper sorting\n", - " all_weeks = df_filtered[\"month_year_week\"].unique()\n", - " weeks_datetime = pd.to_datetime(all_weeks)\n", - " sorted_weeks_idx = weeks_datetime.argsort()\n", - " all_weeks = all_weeks[sorted_weeks_idx]\n", - " print(f\"all_weeks={all_weeks}\")\n", - "\n", - " # Create mapping from week string to numeric index\n", - " week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", - "\n", - " # Merge back to get all activities\n", - " cohort_data = pd.merge(\n", - " df_filtered,\n", - " first_trades[[\"trader_address\", \"cohort_week\"]],\n", - " on=\"trader_address\",\n", - " )\n", - " print(cohort_data.tail())\n", - " print(cohort_data.cohort_week.value_counts())\n", - "\n", - " # Calculate week number since first activity\n", - " cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", - " cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", - " cohort_data[\"week_number\"] = (\n", - " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", - " )\n", - "\n", - " # Calculate retention by cohort\n", - " cohort_sizes = cohort_data.groupby(\"cohort_week\")[\"trader_address\"].nunique()\n", - " print(\"COHORT SIZES\")\n", - " print(cohort_sizes)\n", - " retention_matrix = cohort_data.groupby([\"cohort_week\", \"week_number\"])[\n", - " \"trader_address\"\n", - " ].nunique()\n", - " retention_matrix = retention_matrix.unstack(fill_value=0)\n", - "\n", - " # Convert to percentages\n", - " retention_matrix = retention_matrix.div(cohort_sizes, axis=0) * 100\n", - "\n", - " # Sort index (cohort_week) chronologically\n", - " retention_matrix.index = pd.to_datetime(retention_matrix.index)\n", - " retention_matrix = retention_matrix.sort_index()\n", - "\n", - " return retention_matrix.round(2)" - ] - }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 143, "metadata": {}, - "outputs": [], - "source": [ - "def prepare_retention_dataset(\n", - " retention_df: pd.DataFrame, unknown_df: pd.DataFrame\n", - ") -> pd.DataFrame:\n", - "\n", - " retention_df[\"trader_type\"] = retention_df[\"staking\"].apply(\n", - " lambda x: \"non_Olas\" if x == \"non_Olas\" else \"Olas\"\n", - " )\n", - " retention_df.rename(columns={\"request_time\": \"creation_timestamp\"}, inplace=True)\n", - " retention_df = retention_df[\n", - " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", - " ]\n", - " unknown_df[\"trader_type\"] = \"unclassified\"\n", - " unknown_df = unknown_df[\n", - " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", - " ]\n", - " all_traders = pd.concat([retention_df, unknown_df], ignore_index=True)\n", + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "hovertemplate": "%{y:.1f}%
Week: %{x|%Y-%m-%d}", + "legendgroup": "Olas", + "line": { + "color": "#636efa", + "dash": "solid" + }, + "marker": { + "symbol": "circle" + }, + "mode": "lines+markers", + "name": "Olas", + "orientation": "v", + "showlegend": true, + "type": "scatter", + "x": [ + "2024-11-17T00:00:00", + "2024-11-24T00:00:00", + "2024-12-08T00:00:00", + "2024-12-15T00:00:00", + "2024-12-22T00:00:00", + "2024-12-29T00:00:00", + "2025-01-05T00:00:00", + "2025-01-12T00:00:00", + "2025-01-19T00:00:00" + ], + "xaxis": "x", + "y": [ + 79.08, + 94.55, + 92.57, + 90.99, + 89.87, + 87.38, + 91.24, + 91.71, + 78.92 + ], + "yaxis": "y" + }, + { + "hovertemplate": "%{y:.1f}%
Week: %{x|%Y-%m-%d}", + "legendgroup": "non_Olas", + "line": { + "color": "#EF553B", + "dash": "solid" + }, + "marker": { + "symbol": "circle" + }, + "mode": "lines+markers", + "name": "non_Olas", + "orientation": "v", + "showlegend": true, + "type": "scatter", + "x": [ + "2024-11-17T00:00:00", + "2024-11-24T00:00:00", + "2024-12-08T00:00:00", + "2024-12-15T00:00:00", + "2024-12-22T00:00:00", + "2024-12-29T00:00:00", + "2025-01-05T00:00:00", + "2025-01-12T00:00:00", + "2025-01-19T00:00:00" + ], + "xaxis": "x", + "y": [ + 35.76, + 87.22, + 92.86, + 93.52, + 96.31, + 95.64, + 94.33, + 94.72, + 94.13 + ], + "yaxis": "y" + }, + { + "hovertemplate": "%{y:.1f}%
Week: %{x|%Y-%m-%d}", + "legendgroup": "unclassified", + "line": { + "color": "#00cc96", + "dash": "solid" + }, + "marker": { + "symbol": "circle" + }, + "mode": "lines+markers", + "name": "unclassified", + "orientation": "v", + "showlegend": true, + "type": "scatter", + "x": [ + "2024-11-17T00:00:00", + "2024-11-24T00:00:00", + "2024-12-08T00:00:00", + "2024-12-15T00:00:00", + "2024-12-22T00:00:00", + "2024-12-29T00:00:00", + "2025-01-05T00:00:00", + "2025-01-12T00:00:00", + "2025-01-19T00:00:00" + ], + "xaxis": "x", + "y": [ + 75, + 13.21, + 80, + 7.09, + 90, + 20.97, + 10.53, + 28.57, + 30.77 + ], + "yaxis": "y" + } + ], + "layout": { + "hovermode": "x unified", + "legend": { + "orientation": "v", + "title": { + "text": "Trader Type" + }, + "tracegroupgap": 0, + "x": 1.02, + "xanchor": "left", + "y": 0.5, + "yanchor": "middle" + }, + "margin": { + "r": 150 + }, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Weekly Retention Rate by Trader Type" + }, + "xaxis": { + "anchor": "y", + "domain": [ + 0, + 1 + ], + "tickformat": "%Y-%m-%d", + "title": { + "text": "Week" + } + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 1 + ], + "range": [ + 0, + 105.94100000000002 + ], + "ticksuffix": "%", + "title": { + "text": "Retention Rate (%)" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Create and show the plot\n", + "fig = plot_wow_retention_by_type(wow_retention)\n", + "fig.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cohort retention OLD computation" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_cohort_retention(\n", + " df: pd.DataFrame, market_creator: str, trader_type: str\n", + ") -> pd.DataFrame:\n", + " df_filtered = df.loc[\n", + " (df[\"market_creator\"] == market_creator) & (df[\"trader_type\"] == trader_type)\n", + " ]\n", + " # Get first week for each trader\n", + " first_trades = (\n", + " df_filtered.groupby(\"trader_address\")\n", + " .agg({\"creation_timestamp\": \"min\", \"month_year_week\": \"first\"})\n", + " .reset_index()\n", + " )\n", + " first_trades.columns = [\"trader_address\", \"first_trade\", \"cohort_week\"]\n", + "\n", + " # Get ordered list of unique weeks - converting to datetime for proper sorting\n", + " all_weeks = df_filtered[\"month_year_week\"].unique()\n", + " weeks_datetime = pd.to_datetime(all_weeks)\n", + " sorted_weeks_idx = weeks_datetime.argsort()\n", + " all_weeks = all_weeks[sorted_weeks_idx]\n", + " print(f\"all_weeks={all_weeks}\")\n", + "\n", + " # Create mapping from week string to numeric index\n", + " week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", + "\n", + " # Merge back to get all activities\n", + " cohort_data = pd.merge(\n", + " df_filtered,\n", + " first_trades[[\"trader_address\", \"cohort_week\"]],\n", + " on=\"trader_address\",\n", + " )\n", + " print(cohort_data.tail())\n", + " print(cohort_data.cohort_week.value_counts())\n", + "\n", + " # Calculate week number since first activity\n", + " cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", + " cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", + " cohort_data[\"week_number\"] = (\n", + " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", + " )\n", + "\n", + " # Calculate retention by cohort\n", + " cohort_sizes = cohort_data.groupby(\"cohort_week\")[\"trader_address\"].nunique()\n", + " print(\"COHORT SIZES\")\n", + " print(cohort_sizes)\n", + " retention_matrix = cohort_data.groupby([\"cohort_week\", \"week_number\"])[\n", + " \"trader_address\"\n", + " ].nunique()\n", + " retention_matrix = retention_matrix.unstack(fill_value=0)\n", + "\n", + " # Convert to percentages\n", + " retention_matrix = retention_matrix.div(cohort_sizes, axis=0) * 100\n", + "\n", + " # Sort index (cohort_week) chronologically\n", + " retention_matrix.index = pd.to_datetime(retention_matrix.index)\n", + " retention_matrix = retention_matrix.sort_index()\n", + "\n", + " return retention_matrix.round(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "def prepare_retention_dataset(\n", + " retention_df: pd.DataFrame, unknown_df: pd.DataFrame\n", + ") -> pd.DataFrame:\n", + "\n", + " retention_df[\"trader_type\"] = retention_df[\"staking\"].apply(\n", + " lambda x: \"non_Olas\" if x == \"non_Olas\" else \"Olas\"\n", + " )\n", + " retention_df.rename(columns={\"request_time\": \"creation_timestamp\"}, inplace=True)\n", + " retention_df = retention_df[\n", + " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", + " ]\n", + " unknown_df[\"trader_type\"] = \"unclassified\"\n", + " unknown_df = unknown_df[\n", + " [\"trader_type\", \"market_creator\", \"trader_address\", \"creation_timestamp\"]\n", + " ]\n", + " all_traders = pd.concat([retention_df, unknown_df], ignore_index=True)\n", "\n", " all_traders[\"creation_timestamp\"] = pd.to_datetime(\n", " all_traders[\"creation_timestamp\"]\n", @@ -2171,32 +3567,27 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 169, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/2945974734.py:23: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.\n", - " all_traders[\"creation_timestamp\"].dt.to_period(\"W\").dt.strftime(\"%b-%d-%Y\")\n" - ] - } - ], - "source": [ - "all_traders = prepare_retention_dataset(retention_df=retention_df, unknown_df=unknown_df)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/2945974734.py:23: UserWarning:\n", + "\n", + "Converting to PeriodArray/Index representation will drop timezone information.\n", + "\n" + ] + } + ], + "source": [ + "all_traders = prepare_retention_dataset(retention_df=retention_df, unknown_df=unknown_df)" + ] }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 144, "metadata": {}, "outputs": [ { @@ -2206,38 +3597,38 @@ "all_weeks=['Nov-17-2024' 'Nov-24-2024' 'Dec-01-2024' 'Dec-08-2024' 'Dec-15-2024'\n", " 'Dec-22-2024' 'Dec-29-2024' 'Jan-05-2025' 'Jan-12-2025' 'Jan-19-2025']\n", " trader_type market_creator trader_address \\\n", - "50119 Olas pearl 0xcaa568047b0ae065b5cf5d29b875e31afe0ab70e \n", - "50120 Olas pearl 0xcaa568047b0ae065b5cf5d29b875e31afe0ab70e \n", - "50121 Olas pearl 0x5fc7213135962250147030c5dd30b84a80f2ad1e \n", - "50122 Olas pearl 0xe715cc8f264ab48f75bb1b5c11d7dbaf949d73c5 \n", - "50123 Olas pearl 0xe715cc8f264ab48f75bb1b5c11d7dbaf949d73c5 \n", + "49834 Olas pearl 0x92b62e835d5ebf0e79b76715fcb87284e069ff81 \n", + "49835 Olas pearl 0x92b62e835d5ebf0e79b76715fcb87284e069ff81 \n", + "49836 Olas pearl 0x92b62e835d5ebf0e79b76715fcb87284e069ff81 \n", + "49837 Olas pearl 0x92b62e835d5ebf0e79b76715fcb87284e069ff81 \n", + "49838 Olas pearl 0x3badd0a1beb34fc1532f6c717fa857b3325da184 \n", "\n", " creation_timestamp month_year_week cohort_week \n", - "50119 2025-01-14 12:34:00+00:00 Jan-19-2025 Dec-08-2024 \n", - "50120 2025-01-14 12:36:35+00:00 Jan-19-2025 Dec-08-2024 \n", - "50121 2025-01-14 13:18:10+00:00 Jan-19-2025 Nov-17-2024 \n", - "50122 2025-01-14 13:21:10+00:00 Jan-19-2025 Nov-17-2024 \n", - "50123 2025-01-14 13:22:55+00:00 Jan-19-2025 Nov-17-2024 \n", + "49834 2025-01-15 13:45:45+00:00 Jan-19-2025 Nov-17-2024 \n", + "49835 2025-01-15 13:48:30+00:00 Jan-19-2025 Nov-17-2024 \n", + "49836 2025-01-15 13:52:00+00:00 Jan-19-2025 Nov-17-2024 \n", + "49837 2025-01-15 13:55:50+00:00 Jan-19-2025 Nov-17-2024 \n", + "49838 2025-01-15 14:01:00+00:00 Jan-19-2025 Nov-17-2024 \n", "cohort_week\n", - "Nov-17-2024 46407\n", - "Nov-24-2024 1802\n", - "Dec-01-2024 848\n", - "Dec-08-2024 578\n", + "Nov-17-2024 43957\n", + "Nov-24-2024 3368\n", + "Dec-01-2024 1430\n", + "Dec-08-2024 589\n", "Dec-15-2024 429\n", - "Jan-19-2025 46\n", + "Jan-19-2025 52\n", "Dec-22-2024 7\n", "Dec-29-2024 7\n", "Name: count, dtype: int64\n", "COHORT SIZES\n", "cohort_week\n", - "Dec-01-2024 7\n", + "Dec-01-2024 9\n", "Dec-08-2024 6\n", "Dec-15-2024 10\n", "Dec-22-2024 2\n", "Dec-29-2024 1\n", "Jan-19-2025 1\n", - "Nov-17-2024 143\n", - "Nov-24-2024 6\n", + "Nov-17-2024 133\n", + "Nov-24-2024 13\n", "Name: trader_address, dtype: int64\n" ] } @@ -2408,18 +3799,20 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 145, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/3309953326.py:1: SettingWithCopyWarning: \n", + "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/3309953326.py:1: SettingWithCopyWarning:\n", + "\n", + "\n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", - " olas_data.rename(columns={\"request_time\": \"creation_timestamp\"}, inplace=True)\n" + "\n" ] } ], @@ -2429,15 +3822,17 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 146, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/1537996894.py:3: UserWarning: Converting to PeriodArray/Index representation will drop timezone information.\n", - " olas_data[\"creation_timestamp\"].dt.to_period(\"W\").dt.strftime(\"%b-%d-%Y\")\n" + "/var/folders/gp/02mb1d514ng739czlxw1lhh00000gn/T/ipykernel_51242/1537996894.py:3: UserWarning:\n", + "\n", + "Converting to PeriodArray/Index representation will drop timezone information.\n", + "\n" ] } ], @@ -2450,14 +3845,7 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 98, + "execution_count": 147, "metadata": {}, "outputs": [], "source": [ @@ -2471,7 +3859,37 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "cohort_week\n", + "Nov-17-2024 202\n", + "Nov-24-2024 30\n", + "Dec-01-2024 12\n", + "Dec-08-2024 12\n", + "Dec-15-2024 10\n", + "Dec-22-2024 2\n", + "Jan-05-2025 1\n", + "Jan-19-2025 1\n", + "Dec-29-2024 1\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_trades.cohort_week.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 150, "metadata": {}, "outputs": [ { @@ -2502,194 +3920,338 @@ " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + "
trader_typeweekretained_tradersprevious_tradersretention_rate
9non_Olas2024-12-08154154100.00
10non_Olas2024-12-1530132492.90
00x006f70b4e3c3a3648f31ec16b2e7106fc58166f22024-11-20 07:26:35+00:00Nov-24-2024740x3784c7866a0d308d72719aa17e888b457d399ca72025-01-01 14:46:45+00:00Jan-05-2025
10x00897abcbbefe4f558956b7a9d1b7819677e4d902024-11-13 10:21:25+00:00Nov-17-2024
\n", + "
" + ], + "text/plain": [ + " trader_address first_trade \\\n", + "74 0x3784c7866a0d308d72719aa17e888b457d399ca7 2025-01-01 14:46:45+00:00 \n", + "\n", + " cohort_week \n", + "74 Jan-05-2025 " + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_trades.loc[first_trades[\"cohort_week\"]==\"Jan-05-2025\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024', 'Dec-08-2024',\n", + " 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024', 'Jan-05-2025',\n", + " 'Jan-12-2025', 'Jan-19-2025'], dtype=object)" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_weeks = olas_data[\"month_year_week\"].unique()\n", + "all_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [], + "source": [ + "all_weeks = olas_data[\"month_year_week\"].unique()\n", + "weeks_datetime = pd.to_datetime(all_weeks)\n", + "sorted_weeks_idx = weeks_datetime.argsort()\n", + "all_weeks = all_weeks[sorted_weeks_idx]" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024', 'Dec-08-2024',\n", + " 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024', 'Jan-05-2025',\n", + " 'Jan-12-2025', 'Jan-19-2025'], dtype=object)" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "outputs": [], + "source": [ + "# Create mapping from week string to numeric index\n", + "week_to_number = {week: idx for idx, week in enumerate(all_weeks)}" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Nov-17-2024': 0,\n", + " 'Nov-24-2024': 1,\n", + " 'Dec-01-2024': 2,\n", + " 'Dec-08-2024': 3,\n", + " 'Dec-15-2024': 4,\n", + " 'Dec-22-2024': 5,\n", + " 'Dec-29-2024': 6,\n", + " 'Jan-05-2025': 7,\n", + " 'Jan-12-2025': 8,\n", + " 'Jan-19-2025': 9}" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "week_to_number" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "metadata": {}, + "outputs": [], + "source": [ + "# Merge back to get all activities\n", + "cohort_data = pd.merge(\n", + " olas_data,\n", + " first_trades[[\"trader_address\", \"cohort_week\"]],\n", + " on=\"trader_address\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", "
trader_addresscreation_timestampmarket_creatorrequest_datestakingmonth_year_weektrader_typecohort_week
20x01274796ce41aa8e8312e05a427ffb4b0d2148f62024-11-13 10:13:05+00:0000x1c1bb5398ba525c5bca07eeade45958e455de4b32024-11-14 00:00:05+00:00quickstart2024-11-14non_stakingNov-17-2024
30x01c72d0743a22b70d73c76c5e16ba7524e20e0c02024-11-13 19:27:15+00:00OlasNov-17-2024
40x0244169d0fe1014b9e71f71070099d9c2364af282024-11-16 06:06:20+00:0010xf839eaf4b42eadd917b46d7b6da0dd0e1fd6f6842024-11-14 00:00:10+00:00quickstart2024-11-14non_stakingNov-17-2024
............
2680xfaa64c148c32af3552413438ec78599bffbd077a2024-11-13 03:23:00+00:00OlasNov-17-2024
2690xfab01f48385de3ffea00f9bf9f27c888e4802d172024-11-13 12:22:50+00:0020xa761001fdebabef8f8c2efe91850c3b8b69c27692024-11-14 00:00:15+00:00quickstart2024-11-14non_stakingNov-17-2024OlasNov-17-2024
2700xfe16926cefc4db4a7496bfc3e961445228fbbf392024-12-15 12:47:10+00:00Dec-15-2024
2710xfe2c8e93ce30d1c961831d8e4d120a307aedbe722024-11-13 11:44:40+00:0030xc598397ce2b8bdf93071c0446d1eedc2141f01d02024-11-14 00:00:15+00:00quickstart2024-11-14quickstartNov-17-2024OlasNov-17-2024
2720xfe94203ab2c1c22fe8585cbebf865f7b69eb70272024-11-13 00:46:35+00:0040x01274796ce41aa8e8312e05a427ffb4b0d2148f62024-11-14 00:00:20+00:00quickstart2024-11-14non_stakingNov-17-2024OlasNov-17-2024
\n", - "

273 rows × 3 columns

\n", "
" ], "text/plain": [ - " trader_address first_trade \\\n", - "0 0x006f70b4e3c3a3648f31ec16b2e7106fc58166f2 2024-11-20 07:26:35+00:00 \n", - "1 0x00897abcbbefe4f558956b7a9d1b7819677e4d90 2024-11-13 10:21:25+00:00 \n", - "2 0x01274796ce41aa8e8312e05a427ffb4b0d2148f6 2024-11-13 10:13:05+00:00 \n", - "3 0x01c72d0743a22b70d73c76c5e16ba7524e20e0c0 2024-11-13 19:27:15+00:00 \n", - "4 0x0244169d0fe1014b9e71f71070099d9c2364af28 2024-11-16 06:06:20+00:00 \n", - ".. ... ... \n", - "268 0xfaa64c148c32af3552413438ec78599bffbd077a 2024-11-13 03:23:00+00:00 \n", - "269 0xfab01f48385de3ffea00f9bf9f27c888e4802d17 2024-11-13 12:22:50+00:00 \n", - "270 0xfe16926cefc4db4a7496bfc3e961445228fbbf39 2024-12-15 12:47:10+00:00 \n", - "271 0xfe2c8e93ce30d1c961831d8e4d120a307aedbe72 2024-11-13 11:44:40+00:00 \n", - "272 0xfe94203ab2c1c22fe8585cbebf865f7b69eb7027 2024-11-13 00:46:35+00:00 \n", + " trader_address creation_timestamp \\\n", + "0 0x1c1bb5398ba525c5bca07eeade45958e455de4b3 2024-11-14 00:00:05+00:00 \n", + "1 0xf839eaf4b42eadd917b46d7b6da0dd0e1fd6f684 2024-11-14 00:00:10+00:00 \n", + "2 0xa761001fdebabef8f8c2efe91850c3b8b69c2769 2024-11-14 00:00:15+00:00 \n", + "3 0xc598397ce2b8bdf93071c0446d1eedc2141f01d0 2024-11-14 00:00:15+00:00 \n", + "4 0x01274796ce41aa8e8312e05a427ffb4b0d2148f6 2024-11-14 00:00:20+00:00 \n", "\n", - " cohort_week \n", - "0 Nov-24-2024 \n", - "1 Nov-17-2024 \n", - "2 Nov-17-2024 \n", - "3 Nov-17-2024 \n", - "4 Nov-17-2024 \n", - ".. ... \n", - "268 Nov-17-2024 \n", - "269 Nov-17-2024 \n", - "270 Dec-15-2024 \n", - "271 Nov-17-2024 \n", - "272 Nov-17-2024 \n", + " market_creator request_date staking month_year_week trader_type \\\n", + "0 quickstart 2024-11-14 non_staking Nov-17-2024 Olas \n", + "1 quickstart 2024-11-14 non_staking Nov-17-2024 Olas \n", + "2 quickstart 2024-11-14 non_staking Nov-17-2024 Olas \n", + "3 quickstart 2024-11-14 quickstart Nov-17-2024 Olas \n", + "4 quickstart 2024-11-14 non_staking Nov-17-2024 Olas \n", "\n", - "[273 rows x 3 columns]" + " cohort_week \n", + "0 Nov-17-2024 \n", + "1 Nov-17-2024 \n", + "2 Nov-17-2024 \n", + "3 Nov-17-2024 \n", + "4 Nov-17-2024 " ] }, - "execution_count": 67, + "execution_count": 156, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "first_trades" + "cohort_data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate week number since first activity\n", + "cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", + "cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", + "cohort_data[\"week_number\"] = (\n", + " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cohort_data.head()" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024', 'Dec-08-2024',\n", - " 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024', 'Jan-05-2025',\n", - " 'Jan-12-2025', 'Jan-19-2025'], dtype=object)" - ] - }, - "execution_count": 99, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "all_weeks = olas_data[\"month_year_week\"].unique()\n", - "all_weeks" + "cohort_data.loc[cohort_data[\"trader_address\"]==\"0x59fab0cc4dd160862a55e5cf8b37719f156111a4\"]" ] }, { "cell_type": "code", - "execution_count": 101, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "all_weeks = olas_data[\"month_year_week\"].unique()\n", - "weeks_datetime = pd.to_datetime(all_weeks)\n", - "sorted_weeks_idx = weeks_datetime.argsort()\n", - "all_weeks = all_weeks[sorted_weeks_idx]" + "cohort_data.loc[cohort_data[\"cohort_week\"]==\"Jan-05-2025\"]" ] }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 163, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "array(['Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024', 'Dec-08-2024',\n", - " 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024', 'Jan-05-2025',\n", - " 'Jan-12-2025', 'Jan-19-2025'], dtype=object)" - ] - }, - "execution_count": 102, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "cohort_week\n", + "Dec-01-2024 12\n", + "Dec-08-2024 12\n", + "Dec-15-2024 10\n", + "Dec-22-2024 2\n", + "Dec-29-2024 1\n", + "Jan-05-2025 1\n", + "Jan-19-2025 1\n", + "Nov-17-2024 202\n", + "Nov-24-2024 30\n", + "Name: trader_address, dtype: int64\n" + ] } ], "source": [ - "all_weeks" - ] - }, - { - "cell_type": "code", - "execution_count": 103, - "metadata": {}, - "outputs": [], - "source": [ - "# Create mapping from week string to numeric index\n", - "week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", - "\n", - "# Merge back to get all activities\n", - "cohort_data = pd.merge(\n", - " olas_data,\n", - " first_trades[[\"trader_address\", \"cohort_week\"]],\n", - " on=\"trader_address\",\n", - ")\n", + "cohort_sizes = cohort_data.groupby(\"cohort_week\")[\"trader_address\"].nunique()\n", "\n", - "# Calculate week number since first activity\n", - "cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", - "cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", - "cohort_data[\"week_number\"] = (\n", - " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", - ")" + "print(cohort_sizes)" ] }, { @@ -2745,21 +4307,290 @@ } ], "source": [ - "cohort_sizes = cohort_data.groupby(\"cohort_week\")[\"trader_address\"].nunique()\n", - "\n", - "print(cohort_sizes)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - " retention_matrix = cohort_data.groupby([\"cohort_week\", \"week_number\"])[\n", - " \"trader_address\"\n", - " ].nunique()\n", - " retention_matrix = retention_matrix.unstack(fill_value=0)" + "cohort_sizes = cohort_data.groupby(\"cohort_week\")[\"trader_address\"].nunique()\n", + "# these are the new users each week\n", + "print(cohort_sizes)" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": {}, + "outputs": [], + "source": [ + "retention_matrix = cohort_data.groupby([\"cohort_week\", \"week_number\"])[\n", + " \"trader_address\"\n", + " ].nunique()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "cohort_week week_number\n", + "Dec-01-2024 0 12\n", + " 1 6\n", + " 2 7\n", + " 3 6\n", + " 4 4\n", + " 5 4\n", + " 6 2\n", + " 7 2\n", + "Dec-08-2024 0 12\n", + " 1 9\n", + " 2 8\n", + " 3 8\n", + " 4 5\n", + " 5 6\n", + " 6 7\n", + "Dec-15-2024 0 10\n", + " 1 4\n", + " 2 3\n", + " 3 3\n", + " 4 2\n", + "Dec-22-2024 0 2\n", + "Dec-29-2024 0 1\n", + "Jan-05-2025 0 1\n", + " 1 1\n", + "Jan-19-2025 0 1\n", + "Nov-17-2024 0 202\n", + " 1 191\n", + " 2 181\n", + " 3 187\n", + " 4 175\n", + " 5 166\n", + " 6 152\n", + " 7 153\n", + " 8 147\n", + " 9 121\n", + "Nov-24-2024 0 30\n", + " 1 9\n", + " 2 28\n", + " 3 26\n", + " 4 28\n", + " 5 26\n", + " 6 27\n", + " 7 27\n", + " 8 22\n", + "Name: trader_address, dtype: int64" + ] + }, + "execution_count": 165, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retention_matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [], + "source": [ + "retention_matrix = retention_matrix.unstack(fill_value=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
week_number0123456789
cohort_week
Dec-01-202412676442200
Dec-08-202412988567000
Dec-15-202410433200000
Dec-22-20242000000000
Dec-29-20241000000000
Jan-05-20251100000000
Jan-19-20251000000000
Nov-17-2024202191181187175166152153147121
Nov-24-2024309282628262727220
\n", + "
" + ], + "text/plain": [ + "week_number 0 1 2 3 4 5 6 7 8 9\n", + "cohort_week \n", + "Dec-01-2024 12 6 7 6 4 4 2 2 0 0\n", + "Dec-08-2024 12 9 8 8 5 6 7 0 0 0\n", + "Dec-15-2024 10 4 3 3 2 0 0 0 0 0\n", + "Dec-22-2024 2 0 0 0 0 0 0 0 0 0\n", + "Dec-29-2024 1 0 0 0 0 0 0 0 0 0\n", + "Jan-05-2025 1 1 0 0 0 0 0 0 0 0\n", + "Jan-19-2025 1 0 0 0 0 0 0 0 0 0\n", + "Nov-17-2024 202 191 181 187 175 166 152 153 147 121\n", + "Nov-24-2024 30 9 28 26 28 26 27 27 22 0" + ] + }, + "execution_count": 167, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retention_matrix" ] }, { @@ -2769,20 +4600,6 @@ "outputs": [], "source": [] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": 54, @@ -3060,317 +4877,574 @@ "4 Nov-17-2024 " ] }, - "execution_count": 55, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_trades.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [], + "source": [ + "all_weeks = all_traders[\"month_year_week\"].unique()\n", + "weeks_datetime = pd.to_datetime(all_weeks)\n", + "sorted_weeks_idx = weeks_datetime.argsort()\n", + "all_weeks = all_weeks[sorted_weeks_idx]" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Nov-10-2024', 'Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024',\n", + " 'Dec-08-2024', 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024',\n", + " 'Jan-05-2025', 'Jan-12-2025'], dtype=object)" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "# Create mapping from week string to numeric index\n", + "week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", + "\n", + "# Merge back to get all activities\n", + "cohort_data = pd.merge(\n", + " all_traders, first_trades[[\"trader_address\", \"cohort_week\"]], on=\"trader_address\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", + "cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", + "cohort_data[\"week_number\"] = (\n", + " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "cohort_retention = calculate_cohort_retention(all_traders)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
week_number0123456789
cohort_week
2024-11-10100.091.8381.7156.4286.7782.8880.5470.0464.5941.25
2024-11-17100.075.0045.0066.8867.5067.5051.2548.1233.750.00
2024-11-24100.051.7275.8672.4175.8665.5262.0751.720.000.00
2024-12-01100.0100.0090.4880.9566.6771.4352.380.000.000.00
2024-12-08100.088.8286.4785.8878.2470.590.000.000.000.00
\n", + "
" + ], + "text/plain": [ + "week_number 0 1 2 3 4 5 6 7 8 \\\n", + "cohort_week \n", + "2024-11-10 100.0 91.83 81.71 56.42 86.77 82.88 80.54 70.04 64.59 \n", + "2024-11-17 100.0 75.00 45.00 66.88 67.50 67.50 51.25 48.12 33.75 \n", + "2024-11-24 100.0 51.72 75.86 72.41 75.86 65.52 62.07 51.72 0.00 \n", + "2024-12-01 100.0 100.00 90.48 80.95 66.67 71.43 52.38 0.00 0.00 \n", + "2024-12-08 100.0 88.82 86.47 85.88 78.24 70.59 0.00 0.00 0.00 \n", + "\n", + "week_number 9 \n", + "cohort_week \n", + "2024-11-10 41.25 \n", + "2024-11-17 0.00 \n", + "2024-11-24 0.00 \n", + "2024-12-01 0.00 \n", + "2024-12-08 0.00 " + ] + }, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "first_trades.head()" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [], - "source": [ - "all_weeks = all_traders[\"month_year_week\"].unique()\n", - "weeks_datetime = pd.to_datetime(all_weeks)\n", - "sorted_weeks_idx = weeks_datetime.argsort()\n", - "all_weeks = all_weeks[sorted_weeks_idx]" + "cohort_retention.head()" ] }, { - "cell_type": "code", - "execution_count": 58, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['Nov-10-2024', 'Nov-17-2024', 'Nov-24-2024', 'Dec-01-2024',\n", - " 'Dec-08-2024', 'Dec-15-2024', 'Dec-22-2024', 'Dec-29-2024',\n", - " 'Jan-05-2025', 'Jan-12-2025'], dtype=object)" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "all_weeks" + "## Wow retention by cohorts" ] }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 199, "metadata": {}, "outputs": [], "source": [ - "# Create mapping from week string to numeric index\n", - "week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", + "def calculate_cohort_retention(\n", + " df: pd.DataFrame, market_creator: str, trader_type: str\n", + ") -> pd.DataFrame:\n", + " df_filtered = df.loc[\n", + " (df[\"market_creator\"] == market_creator) & (df[\"trader_type\"] == trader_type)\n", + " ]\n", + " df_filtered = df_filtered.sort_values(by=\"creation_timestamp\", ascending=True)\n", + " # Get first week of activity for each trader\n", + " first_activity = (\n", + " df_filtered.groupby(\"trader_address\")\n", + " .agg({\"creation_timestamp\": \"min\", \"month_year_week\": \"first\"})\n", + " .reset_index()\n", + " )\n", + " first_activity.columns = [\"trader_address\", \"first_activity\", \"cohort_week\"]\n", "\n", - "# Merge back to get all activities\n", - "cohort_data = pd.merge(\n", - " all_traders, first_trades[[\"trader_address\", \"cohort_week\"]], on=\"trader_address\"\n", - ")" + " # Get ordered list of unique weeks - converting to datetime for proper sorting\n", + " all_weeks = df_filtered[\"month_year_week\"].unique()\n", + " weeks_datetime = pd.to_datetime(all_weeks)\n", + " sorted_weeks_idx = weeks_datetime.argsort()\n", + " all_weeks = all_weeks[sorted_weeks_idx]\n", + "\n", + " # Create mapping from week string to numeric index\n", + " week_to_number = {week: idx for idx, week in enumerate(all_weeks)}\n", + "\n", + " # Merge back to get all activities\n", + " cohort_data = pd.merge(\n", + " df_filtered,\n", + " first_activity[[\"trader_address\", \"cohort_week\"]],\n", + " on=\"trader_address\",\n", + " )\n", + "\n", + " # Calculate week number since first activity\n", + " cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", + " cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", + " cohort_data[\"week_number\"] = (\n", + " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", + " )\n", + "\n", + " # Get all unique weeks and cohorts\n", + " all_cohorts = cohort_data[\"cohort_week\"].unique()\n", + " print(f\"all cohorts = {all_cohorts}\")\n", + " retention_data = []\n", + "\n", + " for cohort in all_cohorts:\n", + " print(f\"analyzing cohort {cohort}\")\n", + " # Get all traders in this cohort\n", + " cohort_traders = set(\n", + " cohort_data[cohort_data[\"cohort_week\"] == cohort][\"trader_address\"]\n", + " )\n", + " cohort_size = len(cohort_traders)\n", + " print(f\"cohort size = {cohort_size}\")\n", + "\n", + " if cohort_size == 0:\n", + " print(f\"NO new traders for cohort week={cohort}\")\n", + " continue\n", + "\n", + " # Calculate retention for each week after the cohort week\n", + " for week_idx, week in enumerate(all_weeks):\n", + " print(f\"Analyzing week = {week}\")\n", + " weeks_since_cohort = week_idx - week_to_number[cohort]\n", + " if weeks_since_cohort < 0:\n", + " print(\"Skipping\")\n", + " continue\n", + " # Get active traders from the cohort in current week\n", + " current_traders = set(\n", + " cohort_data[\n", + " (cohort_data[\"cohort_week\"] == cohort)\n", + " & (cohort_data[\"month_year_week\"] == week)\n", + " ][\"trader_address\"]\n", + " )\n", + "\n", + " # Get active traders from the cohort in previous week\n", + " if week == cohort:\n", + " # For the first week, retention is 100% by definition\n", + " retained = len(current_traders)\n", + " retention_rate = 100 if len(current_traders) > 0 else 0\n", + " \n", + " elif week_idx > 0:\n", + " previous_week = all_weeks[week_idx - 1]\n", + " previous_traders = set(\n", + " cohort_data[\n", + " (cohort_data[\"cohort_week\"] == cohort)\n", + " & (cohort_data[\"month_year_week\"] == previous_week)\n", + " ][\"trader_address\"]\n", + " )\n", + " retained = len(current_traders.intersection(previous_traders))\n", + " retention_rate = (\n", + " (retained / len(previous_traders)) * 100\n", + " if len(previous_traders) > 0\n", + " else 0\n", + " )\n", + " print(f\"Retention rate = {retention_rate}\")\n", + "\n", + "\n", + " retention_data.append(\n", + " {\n", + " \"cohort_week\": cohort,\n", + " \"week\": week,\n", + " \"weeks_since_cohort\": weeks_since_cohort,\n", + " \"cohort_size\": cohort_size,\n", + " \"active_traders\": len(current_traders),\n", + " \"retained_traders\": retained,\n", + " \"previous_traders\": (\n", + " len(previous_traders) if week_idx > 0 else cohort_size\n", + " ),\n", + " \"retention_rate\": round(retention_rate, 2),\n", + " }\n", + " )\n", + " return pd.DataFrame(retention_data)" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 200, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "all cohorts = ['Nov-17-2024' 'Nov-24-2024' 'Dec-01-2024' 'Dec-08-2024' 'Dec-15-2024'\n", + " 'Dec-22-2024' 'Dec-29-2024' 'Jan-19-2025']\n", + "analyzing cohort Nov-17-2024\n", + "cohort size = 133\n", + "Analyzing week = Nov-17-2024\n", + "Analyzing week = Nov-24-2024\n", + "Retention rate = 91.72932330827066\n", + "Analyzing week = Dec-01-2024\n", + "Retention rate = 96.72131147540983\n", + "Analyzing week = Dec-08-2024\n", + "Retention rate = 94.35483870967742\n", + "Analyzing week = Dec-15-2024\n", + "Retention rate = 90.83333333333333\n", + "Analyzing week = Dec-22-2024\n", + "Retention rate = 89.38053097345133\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 84.90566037735849\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 91.30434782608695\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 91.48936170212765\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 71.42857142857143\n", + "analyzing cohort Nov-24-2024\n", + "cohort size = 13\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Analyzing week = Dec-01-2024\n", + "Retention rate = 69.23076923076923\n", + "Analyzing week = Dec-08-2024\n", + "Retention rate = 88.88888888888889\n", + "Analyzing week = Dec-15-2024\n", + "Retention rate = 81.81818181818183\n", + "Analyzing week = Dec-22-2024\n", + "Retention rate = 88.88888888888889\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 72.72727272727273\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 88.88888888888889\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 90.0\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 50.0\n", + "analyzing cohort Dec-01-2024\n", + "cohort size = 9\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Analyzing week = Dec-08-2024\n", + "Retention rate = 66.66666666666666\n", + "Analyzing week = Dec-15-2024\n", + "Retention rate = 100.0\n", + "Analyzing week = Dec-22-2024\n", + "Retention rate = 83.33333333333334\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 80.0\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 75.0\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 50.0\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 50.0\n", + "analyzing cohort Dec-08-2024\n", + "cohort size = 6\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Skipping\n", + "Analyzing week = Dec-08-2024\n", + "Analyzing week = Dec-15-2024\n", + "Retention rate = 83.33333333333334\n", + "Analyzing week = Dec-22-2024\n", + "Retention rate = 80.0\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 75.0\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 50.0\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 100.0\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 100.0\n", + "analyzing cohort Dec-15-2024\n", + "cohort size = 10\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Skipping\n", + "Analyzing week = Dec-08-2024\n", + "Skipping\n", + "Analyzing week = Dec-15-2024\n", + "Analyzing week = Dec-22-2024\n", + "Retention rate = 40.0\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 50.0\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 66.66666666666666\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 33.33333333333333\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 0.0\n", + "analyzing cohort Dec-22-2024\n", + "cohort size = 2\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Skipping\n", + "Analyzing week = Dec-08-2024\n", + "Skipping\n", + "Analyzing week = Dec-15-2024\n", + "Skipping\n", + "Analyzing week = Dec-22-2024\n", + "Analyzing week = Dec-29-2024\n", + "Retention rate = 0.0\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 0\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 0\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 0\n", + "analyzing cohort Dec-29-2024\n", + "cohort size = 1\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Skipping\n", + "Analyzing week = Dec-08-2024\n", + "Skipping\n", + "Analyzing week = Dec-15-2024\n", + "Skipping\n", + "Analyzing week = Dec-22-2024\n", + "Skipping\n", + "Analyzing week = Dec-29-2024\n", + "Analyzing week = Jan-05-2025\n", + "Retention rate = 0.0\n", + "Analyzing week = Jan-12-2025\n", + "Retention rate = 0\n", + "Analyzing week = Jan-19-2025\n", + "Retention rate = 0\n", + "analyzing cohort Jan-19-2025\n", + "cohort size = 1\n", + "Analyzing week = Nov-17-2024\n", + "Skipping\n", + "Analyzing week = Nov-24-2024\n", + "Skipping\n", + "Analyzing week = Dec-01-2024\n", + "Skipping\n", + "Analyzing week = Dec-08-2024\n", + "Skipping\n", + "Analyzing week = Dec-15-2024\n", + "Skipping\n", + "Analyzing week = Dec-22-2024\n", + "Skipping\n", + "Analyzing week = Dec-29-2024\n", + "Skipping\n", + "Analyzing week = Jan-05-2025\n", + "Skipping\n", + "Analyzing week = Jan-12-2025\n", + "Skipping\n", + "Analyzing week = Jan-19-2025\n" + ] + } + ], "source": [ - "cohort_data[\"cohort_number\"] = cohort_data[\"cohort_week\"].map(week_to_number)\n", - "cohort_data[\"activity_number\"] = cohort_data[\"month_year_week\"].map(week_to_number)\n", - "cohort_data[\"week_number\"] = (\n", - " cohort_data[\"activity_number\"] - cohort_data[\"cohort_number\"]\n", - ")" + "pearl_result = calculate_cohort_retention(df=all_traders, market_creator=\"pearl\", trader_type=\"Olas\")" ] }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 189, "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
trader_addressmarket_creatortrade_idcreation_timestamptitlemarket_statuscollateral_amountoutcome_indextrade_fee_amountoutcomes_tokens_traded...mech_fee_amountnet_earningsroistakingtrader_typemonth_year_weekcohort_weekcohort_numberactivity_numberweek_number
00x1c1bb5398ba525c5bca07eeade45958e455de4b3quickstart0x50ac9248cf115f69238d9c506f22c223cc9ec20d0x1c...2024-11-08 00:01:05+00:00Will any new information regarding the selecti...CLOSED0.77272600.0077272.087857...0.06-0.840453-1.000000non_stakingOlasNov-10-2024Nov-10-2024000
10x2db124224a640765df2842325ab1ab3ec45ebd47quickstart0xcd00e854ebc743b8a023c9c780d68cb5610fb2160x2d...2024-11-08 00:01:15+00:00Will the CDC confirm the source of the E. coli...CLOSED1.53441800.0153443.814142...0.022.2443801.429758non_stakingOlasNov-10-2024Nov-10-2024000
20xa156f5e98383c3e2a70faef71cc420780809e130quickstart0x50ac9248cf115f69238d9c506f22c223cc9ec20d0xa1...2024-11-08 00:04:25+00:00Will any new information regarding the selecti...CLOSED0.41501310.0041500.672596...0.020.2334330.531542non_stakingOlasNov-10-2024Nov-10-2024000
30x211957119a92bd2bb22f835aefae66683428ddd7quickstart0xcd00e854ebc743b8a023c9c780d68cb5610fb2160x21...2024-11-08 00:12:05+00:00Will the CDC confirm the source of the E. coli...CLOSED0.60031110.0060031.069992...0.02-0.626314-1.000000non_stakingOlasNov-10-2024Nov-10-2024000
40xd71b78ce490776a8f0cad6876ea79bc190f7bccepearl0x868c0dd6983e9b33543471779ff52c814db90fe30xd7...2024-11-08 00:15:55+00:00Will a peer-reviewed journal publish a follow-...CLOSED0.02500010.0002500.050876...0.010.0156260.443287pearlOlasNov-10-2024Nov-10-2024000
\n", - "

5 rows × 27 columns

\n", - "
" - ], - "text/plain": [ - " trader_address market_creator \\\n", - "0 0x1c1bb5398ba525c5bca07eeade45958e455de4b3 quickstart \n", - "1 0x2db124224a640765df2842325ab1ab3ec45ebd47 quickstart \n", - "2 0xa156f5e98383c3e2a70faef71cc420780809e130 quickstart \n", - "3 0x211957119a92bd2bb22f835aefae66683428ddd7 quickstart \n", - "4 0xd71b78ce490776a8f0cad6876ea79bc190f7bcce pearl \n", - "\n", - " trade_id \\\n", - "0 0x50ac9248cf115f69238d9c506f22c223cc9ec20d0x1c... \n", - "1 0xcd00e854ebc743b8a023c9c780d68cb5610fb2160x2d... \n", - "2 0x50ac9248cf115f69238d9c506f22c223cc9ec20d0xa1... \n", - "3 0xcd00e854ebc743b8a023c9c780d68cb5610fb2160x21... \n", - "4 0x868c0dd6983e9b33543471779ff52c814db90fe30xd7... \n", - "\n", - " creation_timestamp \\\n", - "0 2024-11-08 00:01:05+00:00 \n", - "1 2024-11-08 00:01:15+00:00 \n", - "2 2024-11-08 00:04:25+00:00 \n", - "3 2024-11-08 00:12:05+00:00 \n", - "4 2024-11-08 00:15:55+00:00 \n", - "\n", - " title market_status \\\n", - "0 Will any new information regarding the selecti... CLOSED \n", - "1 Will the CDC confirm the source of the E. coli... CLOSED \n", - "2 Will any new information regarding the selecti... CLOSED \n", - "3 Will the CDC confirm the source of the E. coli... CLOSED \n", - "4 Will a peer-reviewed journal publish a follow-... CLOSED \n", - "\n", - " collateral_amount outcome_index trade_fee_amount outcomes_tokens_traded \\\n", - "0 0.772726 0 0.007727 2.087857 \n", - "1 1.534418 0 0.015344 3.814142 \n", - "2 0.415013 1 0.004150 0.672596 \n", - "3 0.600311 1 0.006003 1.069992 \n", - "4 0.025000 1 0.000250 0.050876 \n", - "\n", - " ... mech_fee_amount net_earnings roi staking trader_type \\\n", - "0 ... 0.06 -0.840453 -1.000000 non_staking Olas \n", - "1 ... 0.02 2.244380 1.429758 non_staking Olas \n", - "2 ... 0.02 0.233433 0.531542 non_staking Olas \n", - "3 ... 0.02 -0.626314 -1.000000 non_staking Olas \n", - "4 ... 0.01 0.015626 0.443287 pearl Olas \n", - "\n", - " month_year_week cohort_week cohort_number activity_number week_number \n", - "0 Nov-10-2024 Nov-10-2024 0 0 0 \n", - "1 Nov-10-2024 Nov-10-2024 0 0 0 \n", - "2 Nov-10-2024 Nov-10-2024 0 0 0 \n", - "3 Nov-10-2024 Nov-10-2024 0 0 0 \n", - "4 Nov-10-2024 Nov-10-2024 0 0 0 \n", - "\n", - "[5 rows x 27 columns]" - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "all cohorts = ['Nov-17-2024' 'Nov-24-2024' 'Dec-01-2024' 'Dec-08-2024' 'Jan-05-2025']\n", + "analyzing cohort Nov-17-2024\n", + "cohort size = 69\n", + "analyzing cohort Nov-24-2024\n", + "cohort size = 17\n", + "analyzing cohort Dec-01-2024\n", + "cohort size = 3\n", + "analyzing cohort Dec-08-2024\n", + "cohort size = 6\n", + "analyzing cohort Jan-05-2025\n", + "cohort size = 1\n" + ] } ], "source": [ - "cohort_data.head()" + "result = calculate_cohort_retention(df=all_traders, market_creator=\"quickstart\", trader_type=\"Olas\")" ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 190, "metadata": {}, "outputs": [ { @@ -3391,239 +5465,107 @@ " }\n", "\n", "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", "
trader_addressmarket_creatortrade_idcreation_timestamptitlemarket_statuscollateral_amountoutcome_indextrade_fee_amountoutcomes_tokens_traded...mech_fee_amountnet_earningsroistakingtrader_typemonth_year_week
cohort_weekcohort_numberactivity_numberweek_numberweekweeks_since_cohortcohort_sizeactive_tradersretained_tradersprevious_tradersretention_rate
889280xa8efa5bb5c6ad476c9e0377dbf66cc41cb6d5bddquickstart0xfc75b4d9aadde4ca459b64fb51088ef38bf442830xa8...2025-01-07 10:54:40+00:00Will a recall of Tesla Cybertruck vehicles be ...CLOSED1.969849e+000Nov-17-2024Nov-17-202401.969849e-024.510793...0.02.521246e+001.267246non_OlasunclassifiedJan-12-2025Dec-08-202449569696969100.0
889290x3e013a3ca156032005c239de6d84badd3f9b13a9quickstart0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0x3e...2025-01-07 12:17:25+00:00Will Gazprom announce a new pipeline project a...CLOSED5.098594e-0305.098594e-050.007520...0.02.370460e-030.460321non_OlasunclassifiedJan-12-2025Dec-08-20244951Nov-17-2024Nov-24-2024169696969100.0
889300xd4fc4305dc1226c38356024c26cde985817f137fquickstart0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xd4...2025-01-07 13:55:00+00:00Will Gazprom announce a new pipeline project a...CLOSED2.000000e+002Nov-24-2024Nov-24-202401717002.000000e-021.980169...0.0-3.983078e-02-0.019718non_OlasunclassifiedJan-12-2025Dec-22-2024693
889310xc918c15b87746e6351e5f0646ddcaaca11af8568quickstart0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xc9...2025-01-07 15:14:50+00:00Will Gazprom announce a new pipeline project a...CLOSED5.566732e-0715.566732e-091.081069...5Dec-01-2024Dec-01-2024033000.0-5.622399e-07-1.000000non_OlasunclassifiedJan-12-2025Dec-08-2024495
889320xf758c18402ddef2d231911c4c326aa46510788f0quickstart0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xf7...2025-01-07 22:00:55+00:00Will Gazprom announce a new pipeline project a...CLOSED1.000000e-056Dec-01-2024Dec-08-202411.000000e-070.820458...30030.0-1.010000e-05-1.000000non_OlasunclassifiedJan-12-2025Dec-08-2024495
\n", - "

5 rows × 27 columns

\n", "" ], "text/plain": [ - " trader_address market_creator \\\n", - "88928 0xa8efa5bb5c6ad476c9e0377dbf66cc41cb6d5bdd quickstart \n", - "88929 0x3e013a3ca156032005c239de6d84badd3f9b13a9 quickstart \n", - "88930 0xd4fc4305dc1226c38356024c26cde985817f137f quickstart \n", - "88931 0xc918c15b87746e6351e5f0646ddcaaca11af8568 quickstart \n", - "88932 0xf758c18402ddef2d231911c4c326aa46510788f0 quickstart \n", - "\n", - " trade_id \\\n", - "88928 0xfc75b4d9aadde4ca459b64fb51088ef38bf442830xa8... \n", - "88929 0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0x3e... \n", - "88930 0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xd4... \n", - "88931 0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xc9... \n", - "88932 0x0b2f7c5f872b9f0323422f3b5c3b44676baf26ca0xf7... \n", - "\n", - " creation_timestamp \\\n", - "88928 2025-01-07 10:54:40+00:00 \n", - "88929 2025-01-07 12:17:25+00:00 \n", - "88930 2025-01-07 13:55:00+00:00 \n", - "88931 2025-01-07 15:14:50+00:00 \n", - "88932 2025-01-07 22:00:55+00:00 \n", - "\n", - " title market_status \\\n", - "88928 Will a recall of Tesla Cybertruck vehicles be ... CLOSED \n", - "88929 Will Gazprom announce a new pipeline project a... CLOSED \n", - "88930 Will Gazprom announce a new pipeline project a... CLOSED \n", - "88931 Will Gazprom announce a new pipeline project a... CLOSED \n", - "88932 Will Gazprom announce a new pipeline project a... CLOSED \n", - "\n", - " collateral_amount outcome_index trade_fee_amount \\\n", - "88928 1.969849e+00 0 1.969849e-02 \n", - "88929 5.098594e-03 0 5.098594e-05 \n", - "88930 2.000000e+00 0 2.000000e-02 \n", - "88931 5.566732e-07 1 5.566732e-09 \n", - "88932 1.000000e-05 1 1.000000e-07 \n", - "\n", - " outcomes_tokens_traded ... mech_fee_amount net_earnings roi \\\n", - "88928 4.510793 ... 0.0 2.521246e+00 1.267246 \n", - "88929 0.007520 ... 0.0 2.370460e-03 0.460321 \n", - "88930 1.980169 ... 0.0 -3.983078e-02 -0.019718 \n", - "88931 1.081069 ... 0.0 -5.622399e-07 -1.000000 \n", - "88932 0.820458 ... 0.0 -1.010000e-05 -1.000000 \n", - "\n", - " staking trader_type month_year_week cohort_week cohort_number \\\n", - "88928 non_Olas unclassified Jan-12-2025 Dec-08-2024 4 \n", - "88929 non_Olas unclassified Jan-12-2025 Dec-08-2024 4 \n", - "88930 non_Olas unclassified Jan-12-2025 Dec-22-2024 6 \n", - "88931 non_Olas unclassified Jan-12-2025 Dec-08-2024 4 \n", - "88932 non_Olas unclassified Jan-12-2025 Dec-08-2024 4 \n", + " cohort_week week weeks_since_cohort cohort_size active_traders \\\n", + "0 Nov-17-2024 Nov-17-2024 0 69 69 \n", + "1 Nov-17-2024 Nov-24-2024 1 69 69 \n", + "2 Nov-24-2024 Nov-24-2024 0 17 17 \n", + "5 Dec-01-2024 Dec-01-2024 0 3 3 \n", + "6 Dec-01-2024 Dec-08-2024 1 3 0 \n", "\n", - " activity_number week_number \n", - "88928 9 5 \n", - "88929 9 5 \n", - "88930 9 3 \n", - "88931 9 5 \n", - "88932 9 5 \n", - "\n", - "[5 rows x 27 columns]" + " retained_traders previous_traders retention_rate \n", + "0 69 69 100.0 \n", + "1 69 69 100.0 \n", + "2 0 0 0.0 \n", + "5 0 0 0.0 \n", + "6 0 3 0.0 " ] }, - "execution_count": 62, + "execution_count": 190, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cohort_data.tail()" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "cohort_retention = calculate_cohort_retention(all_traders)" + "result.head()" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 202, "metadata": {}, "outputs": [ { @@ -3646,132 +5588,119 @@ "\n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
week_number0123456789
cohort_weekcohort_weekweekweeks_since_cohortcohort_sizeactive_tradersretained_tradersprevious_tradersretention_rate
2024-11-10100.091.8381.7156.4286.7782.8880.5470.0464.5941.250Nov-17-2024Nov-17-20240133133133133100.00
2024-11-17100.075.0045.0066.8867.5067.5051.2548.1233.750.001Nov-17-2024Nov-24-2024113312212213391.73
2024-11-24100.051.7275.8672.4175.8665.5262.0751.720.000.002Nov-17-2024Dec-01-2024213312411812296.72
2024-12-01100.0100.0090.4880.9566.6771.4352.380.000.000.003Nov-17-2024Dec-08-2024313312011712494.35
2024-12-08100.088.8286.4785.8878.2470.590.000.000.000.004Nov-17-2024Dec-15-2024413311310912090.83
\n", "" ], "text/plain": [ - "week_number 0 1 2 3 4 5 6 7 8 \\\n", - "cohort_week \n", - "2024-11-10 100.0 91.83 81.71 56.42 86.77 82.88 80.54 70.04 64.59 \n", - "2024-11-17 100.0 75.00 45.00 66.88 67.50 67.50 51.25 48.12 33.75 \n", - "2024-11-24 100.0 51.72 75.86 72.41 75.86 65.52 62.07 51.72 0.00 \n", - "2024-12-01 100.0 100.00 90.48 80.95 66.67 71.43 52.38 0.00 0.00 \n", - "2024-12-08 100.0 88.82 86.47 85.88 78.24 70.59 0.00 0.00 0.00 \n", + " cohort_week week weeks_since_cohort cohort_size active_traders \\\n", + "0 Nov-17-2024 Nov-17-2024 0 133 133 \n", + "1 Nov-17-2024 Nov-24-2024 1 133 122 \n", + "2 Nov-17-2024 Dec-01-2024 2 133 124 \n", + "3 Nov-17-2024 Dec-08-2024 3 133 120 \n", + "4 Nov-17-2024 Dec-15-2024 4 133 113 \n", "\n", - "week_number 9 \n", - "cohort_week \n", - "2024-11-10 41.25 \n", - "2024-11-17 0.00 \n", - "2024-11-24 0.00 \n", - "2024-12-01 0.00 \n", - "2024-12-08 0.00 " + " retained_traders previous_traders retention_rate \n", + "0 133 133 100.00 \n", + "1 122 133 91.73 \n", + "2 118 122 96.72 \n", + "3 117 124 94.35 \n", + "4 109 120 90.83 " ] }, - "execution_count": 65, + "execution_count": 202, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cohort_retention.head()" + "pearl_result.head()" ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 174, "metadata": {}, "outputs": [ { @@ -3794,124 +5723,188 @@ "\n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
week_numbertrader_addresscreation_timestampmonth_year_week
00x006f70b4e3c3a3648f31ec16b2e7106fc58166f22024-11-20 07:26:35+00:00Nov-24-2024
10x00897abcbbefe4f558956b7a9d1b7819677e4d902024-11-15 09:01:10+00:00Nov-17-2024
20x01c72d0743a22b70d73c76c5e16ba7524e20e0c02024-11-14 18:53:00+00:00Nov-17-2024
30x0244169d0fe1014b9e71f71070099d9c2364af282024-11-16 06:06:20+00:00Nov-17-2024
4567890x047f8663b254d90d28af6d8ca7181947e94577ce2024-11-14 16:55:25+00:00Nov-17-2024
cohort_week............
Dec-01-2024100.0100.0090.4880.9566.6771.4352.380.00.00.01700xf792f6a308525b72b5d47f12798668c140f5968e2024-11-16 11:15:40+00:00Nov-17-2024
Dec-08-2024100.088.8286.4785.8878.2470.590.000.00.00.01710xf8e68d9f66d2534df36c23db6770467da1c1ff1b2024-11-15 01:19:25+00:00Nov-17-2024
Dec-15-2024100.068.7537.5025.009.380.000.000.00.00.01720xfaa64c148c32af3552413438ec78599bffbd077a2024-11-20 16:07:55+00:00Nov-24-2024
Dec-22-2024100.059.3850.0025.000.000.000.000.00.00.01730xfe16926cefc4db4a7496bfc3e961445228fbbf392024-12-15 12:47:10+00:00Dec-15-2024
Dec-29-2024100.069.230.000.000.000.000.000.00.00.01740xfe94203ab2c1c22fe8585cbebf865f7b69eb70272024-11-14 04:05:45+00:00Nov-17-2024
\n", + "

175 rows × 3 columns

\n", "" ], "text/plain": [ - "week_number 0 1 2 3 4 5 6 7 8 9\n", - "cohort_week \n", - "Dec-01-2024 100.0 100.00 90.48 80.95 66.67 71.43 52.38 0.0 0.0 0.0\n", - "Dec-08-2024 100.0 88.82 86.47 85.88 78.24 70.59 0.00 0.0 0.0 0.0\n", - "Dec-15-2024 100.0 68.75 37.50 25.00 9.38 0.00 0.00 0.0 0.0 0.0\n", - "Dec-22-2024 100.0 59.38 50.00 25.00 0.00 0.00 0.00 0.0 0.0 0.0\n", - "Dec-29-2024 100.0 69.23 0.00 0.00 0.00 0.00 0.00 0.0 0.0 0.0" + " trader_address creation_timestamp \\\n", + "0 0x006f70b4e3c3a3648f31ec16b2e7106fc58166f2 2024-11-20 07:26:35+00:00 \n", + "1 0x00897abcbbefe4f558956b7a9d1b7819677e4d90 2024-11-15 09:01:10+00:00 \n", + "2 0x01c72d0743a22b70d73c76c5e16ba7524e20e0c0 2024-11-14 18:53:00+00:00 \n", + "3 0x0244169d0fe1014b9e71f71070099d9c2364af28 2024-11-16 06:06:20+00:00 \n", + "4 0x047f8663b254d90d28af6d8ca7181947e94577ce 2024-11-14 16:55:25+00:00 \n", + ".. ... ... \n", + "170 0xf792f6a308525b72b5d47f12798668c140f5968e 2024-11-16 11:15:40+00:00 \n", + "171 0xf8e68d9f66d2534df36c23db6770467da1c1ff1b 2024-11-15 01:19:25+00:00 \n", + "172 0xfaa64c148c32af3552413438ec78599bffbd077a 2024-11-20 16:07:55+00:00 \n", + "173 0xfe16926cefc4db4a7496bfc3e961445228fbbf39 2024-12-15 12:47:10+00:00 \n", + "174 0xfe94203ab2c1c22fe8585cbebf865f7b69eb7027 2024-11-14 04:05:45+00:00 \n", + "\n", + " month_year_week \n", + "0 Nov-24-2024 \n", + "1 Nov-17-2024 \n", + "2 Nov-17-2024 \n", + "3 Nov-17-2024 \n", + "4 Nov-17-2024 \n", + ".. ... \n", + "170 Nov-17-2024 \n", + "171 Nov-17-2024 \n", + "172 Nov-24-2024 \n", + "173 Dec-15-2024 \n", + "174 Nov-17-2024 \n", + "\n", + "[175 rows x 3 columns]" + ] + }, + "execution_count": 174, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "market_creator=\"pearl\"\n", + "trader_type= \"Olas\"\n", + "df_filtered = all_traders.loc[\n", + " (all_traders[\"market_creator\"] == market_creator) & (all_traders[\"trader_type\"] == trader_type)\n", + "]\n", + "df_filtered = df_filtered.sort_values(by=\"creation_timestamp\", ascending=True)\n", + "# Get first week of activity for each trader\n", + "first_activity = (\n", + " df_filtered.groupby(\"trader_address\")\n", + " .agg({\"creation_timestamp\": \"min\", \"month_year_week\": \"first\"})\n", + " .reset_index()\n", + ")\n", + "first_activity" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['Nov-24-2024', 'Nov-17-2024', 'Dec-01-2024', 'Dec-15-2024',\n", + " 'Dec-08-2024', 'Jan-19-2025', 'Dec-22-2024', 'Dec-29-2024'],\n", + " dtype=object)" ] }, - "execution_count": 52, + "execution_count": 176, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cohort_retention.head()" + "first_activity.month_year_week.unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 193, + "metadata": {}, + "outputs": [], + "source": [ + "def create_retention_matrix(cohort_retention_df: pd.DataFrame) -> pd.DataFrame:\n", + " # Pivot the data to create the retention matrix\n", + " retention_matrix = cohort_retention_df.pivot(\n", + " index='cohort_week',\n", + " columns='weeks_since_cohort',\n", + " values='retention_rate'\n", + " )\n", + " \n", + " # Sort index chronologically\n", + " retention_matrix.index = pd.to_datetime(retention_matrix.index)\n", + " retention_matrix = retention_matrix.sort_index()\n", + " \n", + " # Rename columns to show week numbers\n", + " retention_matrix.columns = [f'Week {i}' for i in retention_matrix.columns]\n", + " \n", + " return retention_matrix\n", + "\n", + "# Example usage:\n", + "# cohort_retention = calculate_cohort_wow_retention(df, market_creator)\n", + "# retention_matrix = create_retention_matrix(cohort_retention)" ] }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 203, "metadata": {}, "outputs": [ { @@ -3934,17 +5927,17 @@ "\n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -3962,101 +5955,175 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
week_number0123456789Week 0Week 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8Week 9
cohort_week
Jan-05-20252024-11-17100.042.860.000.000.000.000.000.000.000.0091.7396.7294.3590.8389.3884.9191.391.4971.43
Jan-12-20252024-11-24100.00.000.000.000.000.000.000.000.000.0069.2388.8981.8288.8972.7388.8990.050.00NaN
Nov-10-20242024-12-01100.091.8381.7156.4286.7782.8880.5470.0464.5941.2566.67100.0083.3380.0075.0050.0050.0NaNNaN
Nov-17-20242024-12-08100.083.3380.0075.0045.0066.8867.5067.5051.2548.1233.7550.00100.00100.00NaNNaNNaN
2024-12-15100.040.0050.0066.6733.330.00NaNNaNNaNNaN
Nov-24-20242024-12-22100.00.000.000.000.00NaNNaNNaNNaNNaN
2024-12-29100.051.7275.8672.4175.8665.5262.0751.720.000.000.00NaNNaNNaNNaNNaNNaN
2025-01-19100.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "" ], "text/plain": [ - "week_number 0 1 2 3 4 5 6 7 8 \\\n", - "cohort_week \n", - "Jan-05-2025 100.0 42.86 0.00 0.00 0.00 0.00 0.00 0.00 0.00 \n", - "Jan-12-2025 100.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 \n", - "Nov-10-2024 100.0 91.83 81.71 56.42 86.77 82.88 80.54 70.04 64.59 \n", - "Nov-17-2024 100.0 75.00 45.00 66.88 67.50 67.50 51.25 48.12 33.75 \n", - "Nov-24-2024 100.0 51.72 75.86 72.41 75.86 65.52 62.07 51.72 0.00 \n", + " Week 0 Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 \\\n", + "cohort_week \n", + "2024-11-17 100.0 91.73 96.72 94.35 90.83 89.38 84.91 91.3 \n", + "2024-11-24 100.0 69.23 88.89 81.82 88.89 72.73 88.89 90.0 \n", + "2024-12-01 100.0 66.67 100.00 83.33 80.00 75.00 50.00 50.0 \n", + "2024-12-08 100.0 83.33 80.00 75.00 50.00 100.00 100.00 NaN \n", + "2024-12-15 100.0 40.00 50.00 66.67 33.33 0.00 NaN NaN \n", + "2024-12-22 100.0 0.00 0.00 0.00 0.00 NaN NaN NaN \n", + "2024-12-29 100.0 0.00 0.00 0.00 NaN NaN NaN NaN \n", + "2025-01-19 100.0 NaN NaN NaN NaN NaN NaN NaN \n", "\n", - "week_number 9 \n", - "cohort_week \n", - "Jan-05-2025 0.00 \n", - "Jan-12-2025 0.00 \n", - "Nov-10-2024 41.25 \n", - "Nov-17-2024 0.00 \n", - "Nov-24-2024 0.00 " + " Week 8 Week 9 \n", + "cohort_week \n", + "2024-11-17 91.49 71.43 \n", + "2024-11-24 50.00 NaN \n", + "2024-12-01 NaN NaN \n", + "2024-12-08 NaN NaN \n", + "2024-12-15 NaN NaN \n", + "2024-12-22 NaN NaN \n", + "2024-12-29 NaN NaN \n", + "2025-01-19 NaN NaN " ] }, - "execution_count": 53, + "execution_count": 203, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cohort_retention.tail()" + "retention_matrix = create_retention_matrix(pearl_result)\n", + "retention_matrix" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {},