diff --git a/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb b/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb index 0f16cffb0..099e10b48 100644 --- a/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb +++ b/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb @@ -2732,8 +2732,6 @@ "r = O.margp_optimizer(\"WETH\", result=O.MO_DEBUG)\n", "assert isinstance(r, dict)\n", "prices0 = r[\"price_estimates_t\"]\n", - "dtknfromp_f = r[\"dtknfromp_f\"]\n", - "assert np.linalg.norm(dtknfromp_f(np.log10(prices0))) < 1e-6\n", "assert not prices0 is None, f\"prices0 must not be None [{prices0}]\"\n", "r1 = O.arb(\"WETH\")\n", "r2 = O.SelfFinancingConstraints.arb(\"WETH\")\n", @@ -2794,16 +2792,6 @@ "prices0" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "30424c63", - "metadata": {}, - "outputs": [], - "source": [ - "dtknfromp_f(np.log10(prices0))" - ] - }, { "cell_type": "code", "execution_count": 115, diff --git a/resources/NBTest/NBTest_002_CPCandOptimizer.py b/resources/NBTest/NBTest_002_CPCandOptimizer.py index 4e34b9a1e..b985dacf7 100644 --- a/resources/NBTest/NBTest_002_CPCandOptimizer.py +++ b/resources/NBTest/NBTest_002_CPCandOptimizer.py @@ -1278,8 +1278,6 @@ r = O.margp_optimizer("WETH", result=O.MO_DEBUG) assert isinstance(r, dict) prices0 = r["price_estimates_t"] -dtknfromp_f = r["dtknfromp_f"] -assert np.linalg.norm(dtknfromp_f(np.log10(prices0))) < 1e-6 assert not prices0 is None, f"prices0 must not be None [{prices0}]" r1 = O.arb("WETH") r2 = O.SelfFinancingConstraints.arb("WETH") @@ -1293,8 +1291,6 @@ prices0 -dtknfromp_f(np.log10(prices0)) - f = O.optimize("WETH", result=O.MO_DTKNFROMPF, params=dict(verbose=True, debug=False)) r3 = f(prices0, islog10=False) assert np.all(r3 == (0,0)) diff --git a/resources/NBTest/NBTest_003_Serialization.ipynb b/resources/NBTest/NBTest_003_Serialization.ipynb index fb042d8c0..d5b5680f6 100644 --- a/resources/NBTest/NBTest_003_Serialization.ipynb +++ b/resources/NBTest/NBTest_003_Serialization.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 58, + "execution_count": 1, "id": "be65f3d2-769a-449f-90cd-2633a11478d0", "metadata": {}, "outputs": [ @@ -10,7 +10,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "ConstantProductCurve v3.5 (22/Apr/2023)\n", + "imported m, np, pd, plt, os, sys, decimal; defined iseq, raises, require, Timer\n", + "ConstantProductCurve v3.4 (23/Jan/2024)\n", "CPCArbOptimizer v5.1 (15/Sep/2023)\n" ] } @@ -20,6 +21,7 @@ " from fastlane_bot.tools.cpc import ConstantProductCurve as CPC, CPCContainer\n", " from fastlane_bot.tools.optimizer import CPCArbOptimizer, cp, time\n", " from fastlane_bot.testing import *\n", + "\n", "except:\n", " from tools.cpc import ConstantProductCurve as CPC, CPCContainer\n", " from tools.optimizer import CPCArbOptimizer, cp, time\n", @@ -53,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 2, "id": "4030cea3-3e03-4e0f-8d80-7a2bcca05fcf", "metadata": {}, "outputs": [], @@ -63,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 3, "id": "8cb4f9bc-2f31-4eae-b77f-533aa188e49b", "metadata": {}, "outputs": [], @@ -82,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 4, "id": "a5ed0075-5ee5-4592-a192-e06d2b5af454", "metadata": {}, "outputs": [], @@ -93,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 5, "id": "1bf13d91-2bc0-4819-96b9-2712ef89b6f1", "metadata": {}, "outputs": [], @@ -103,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 6, "id": "ce05c578-5060-498e-b4eb-f55617d10cdd", "metadata": {}, "outputs": [], @@ -138,7 +140,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 7, "id": "41a5cdfe-fb7b-4c8b-a270-1a52f0765e94", "metadata": {}, "outputs": [ @@ -148,7 +150,7 @@ "ConstantProductCurve(k=10000, x=100, x_act=100, y_act=100, alpha=0.5, pair='TKNB/TKNQ', cid='1', fee=0, descr='UniV2', constr='uv2', params={})" ] }, - "execution_count": 64, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -172,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 8, "id": "ea3cdfbc-8edd-41f1-9703-0ae0d72fdb9a", "metadata": {}, "outputs": [ @@ -192,7 +194,7 @@ " 'params': {}}" ] }, - "execution_count": 65, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -203,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 9, "id": "595de023-5c66-40fc-928f-eca5fe6a50c9", "metadata": {}, "outputs": [], @@ -225,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 10, "id": "215b5105-08d9-4077-a51a-7658cafcffa9", "metadata": {}, "outputs": [], @@ -259,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 11, "id": "0963034a-b36c-4cfb-84da-ccb3c88c4389", "metadata": {}, "outputs": [], @@ -277,7 +279,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 12, "id": "eb5dd380-dd90-4a3b-b88a-5a697bdbc3a0", "metadata": {}, "outputs": [], @@ -308,7 +310,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 13, "id": "624b80f1-c811-483b-ba24-b76c72fe3e0c", "metadata": {}, "outputs": [], @@ -323,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 14, "id": "34d52402-18d6-4485-8e5c-6cb4f8af2ab2", "metadata": {}, "outputs": [ @@ -347,7 +349,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 15, "id": "85175836-0fa9-4f64-a42f-b5b787e622f0", "metadata": {}, "outputs": [], @@ -362,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 16, "id": "9753798a-b154-4865-a845-a1f5f1eb8e4b", "metadata": {}, "outputs": [ @@ -386,17 +388,17 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 17, "id": "5f683913-1799-4f3a-9473-a663d803448a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "ConstantProductCurve(k=0.01, x=0.0015438708879488485, x_act=0, y_act=1, alpha=0.5, pair='ETH/USDC', cid='4', fee=0, descr='Carbon', constr='carb', params={'y': 1, 'yint': 1, 'A': 10, 'B': 54.772255750516614, 'pa': 4195.445115010333, 'pb': 3000.0000000000005, 'minrw': 1e-06})" + "ConstantProductCurve(k=0.01, x=0.0015438708879488485, x_act=0, y_act=1, alpha=0.5, pair='ETH/USDC', cid='4', fee=0, descr='Carbon', constr='carb', params={'y': 1, 'yint': 1, 'A': 10, 'B': 54.772255750516614, 'pa': 4195.445115010333, 'pb': 3000.0000000000005})" ] }, - "execution_count": 74, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -410,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 18, "id": "cffdcaa4-f221-4bd7-bf2d-5418a33e3592", "metadata": {}, "outputs": [], @@ -429,35 +431,12 @@ "assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, A=100, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)\n", "assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, B=100, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)\n", "assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, A=100, B=100, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)\n", - "#assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)" - ] - }, - { - "cell_type": "markdown", - "id": "6d4698a1-5df9-4c5d-a1c9-7e48fd9aa580", - "metadata": {}, - "source": [ - "TODO" + "assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)" ] }, { "cell_type": "code", - "execution_count": 76, - "id": "c1b70bbc-2531-458a-a507-24d89559bf41", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair=\"ETH/USDC\", tkny=\"ETH\", cid=\"1\", descr=\"Carbon\", isdydx=False)\n", - "#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, descr=\"Carbon\", isdydx=False)\n", - "#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", isdydx=False)\n", - "#assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair=\"ETH/USDC\", tkny=\"ETH\", fee=0, cid=\"1\", descr=\"Carbon\", isdydx=False)" - ] - }, - { - "cell_type": "code", - "execution_count": 77, + "execution_count": 19, "id": "f66fc490-97e0-4c5e-958d-1e9014934d5c", "metadata": {}, "outputs": [], @@ -471,31 +450,13 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 20, "id": "465ff937-2382-4215-8e11-ec8096e1ea3d", "metadata": {}, "outputs": [], "source": [ "assert not raises(CPC.from_carbon, yint=1, y=1, pa=3100, pb=2900, pair=\"ETH/USDC\", tkny=\"USDC\", fee=0, cid=\"2\", descr=\"Carbon\", isdydx=True)\n", - "#assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair=\"ETH/USDC\", tkny=\"USDC\", fee=0, cid=\"2\", descr=\"Carbon\", isdydx=True)" - ] - }, - { - "cell_type": "markdown", - "id": "b0da3d2e-9b91-4c7a-89b8-8aa140901e32", - "metadata": {}, - "source": [ - "TODO" - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "id": "d30a97ad-0188-4388-a3f8-3efa1151aa4a", - "metadata": {}, - "outputs": [], - "source": [ - "#assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair=\"ETH/USDC\", tkny=\"USDC\", fee=0, cid=\"2\", descr=\"Carbon\", isdydx=True)" + "assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair=\"ETH/USDC\", tkny=\"USDC\", fee=0, cid=\"2\", descr=\"Carbon\", isdydx=True)" ] }, { @@ -508,7 +469,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 21, "id": "c5c8d6c3-0d15-4c3d-8852-b2870a7b4caa", "metadata": {}, "outputs": [], @@ -524,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 22, "id": "8296d087-d5a5-4b77-825a-dd53ed60d4bd", "metadata": {}, "outputs": [], @@ -542,7 +503,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 23, "id": "e72d0162-dd59-489c-8efb-dbb8327ff553", "metadata": {}, "outputs": [ @@ -606,7 +567,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 24, "id": "c2d5dc97-05e8-4eca-abc7-66eee6e7d706", "metadata": {}, "outputs": [], @@ -620,7 +581,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 25, "id": "9f467a32-370b-4634-bec8-3c28be84a0a0", "metadata": {}, "outputs": [], @@ -632,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 26, "id": "d7563934-5381-476d-b9cb-99b909691049", "metadata": {}, "outputs": [ @@ -642,7 +603,7 @@ "CPCContainer(curves=[ConstantProductCurve(k=2000, x=1, x_act=1, y_act=2000, alpha=0.5, pair='ETH/USDC', cid='1', fee=0.001, descr='UniV2', constr='uv2', params={'meh': 1}), ConstantProductCurve(k=8040, x=2, x_act=2, y_act=4020, alpha=0.5, pair='ETH/USDC', cid='2', fee=0.001, descr='UniV2', constr='uv2', params={}), ConstantProductCurve(k=1970, x=1, x_act=1, y_act=1970, alpha=0.5, pair='ETH/USDC', cid='3', fee=0.001, descr='UniV2', constr='uv2', params={})])" ] }, - "execution_count": 85, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -660,7 +621,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 27, "id": "131928b8-f927-4799-97c6-ec50631c7959", "metadata": {}, "outputs": [ @@ -762,7 +723,7 @@ "3 1970 1 1 1970 0.5 ETH/USDC 0.001 UniV2 uv2 {}" ] }, - "execution_count": 86, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -789,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 28, "id": "6cd062ae-c465-4102-a57c-587874023de5", "metadata": {}, "outputs": [], @@ -818,7 +779,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 29, "id": "8c046e70-ef8a-4de8-bd17-726afb617ea1", "metadata": {}, "outputs": [ @@ -827,7 +788,7 @@ "output_type": "stream", "text": [ "len 2355000\n", - "elapsed time: 0.34s\n" + "elapsed time: 0.29s\n" ] } ], @@ -853,7 +814,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 30, "id": "e892dc06-329d-477f-adcb-40a87eb7a009", "metadata": {}, "outputs": [ @@ -861,7 +822,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "elapsed time: 0.22s\n" + "elapsed time: 0.21s\n" ] }, { @@ -952,7 +913,7 @@ "2 3 1970 1 1 1970 0.5 ETH/USDC 0.001 UniV2 uv2 {}" ] }, - "execution_count": 89, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -978,7 +939,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 31, "id": "a2976017-2a84-4fba-885d-7680d9f61c3a", "metadata": {}, "outputs": [ @@ -986,7 +947,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "elapsed time: 0.16s\n" + "elapsed time: 0.17s\n" ] } ], @@ -1010,7 +971,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 32, "id": "ed5aaa2c-2f5a-4863-87cf-a77240826a85", "metadata": { "lines_to_next_cell": 2 @@ -1020,7 +981,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "elapsed time: 0.16s\n" + "elapsed time: 0.21s\n" ] } ], @@ -1044,7 +1005,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 33, "id": "f1507cc7-96ba-4342-bf1e-955b248bd8b4", "metadata": {}, "outputs": [], @@ -1069,7 +1030,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 34, "id": "a1c75dfe-ce14-4840-9c62-39a8d5cfc3ad", "metadata": {}, "outputs": [ @@ -1178,7 +1139,7 @@ "3 1970 1 1 1970 0.5 ETH/USDC 0.001 UniV2 uv2 {}" ] }, - "execution_count": 93, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -1195,9 +1156,7 @@ { "cell_type": "markdown", "id": "3cfc2ff5-bf9d-4684-9b8c-2aff57937a46", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "### Benchmarking\n", "\n", @@ -1215,7 +1174,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 35, "id": "c43b9431-603d-49af-b5fd-1975e9f59e2f", "metadata": {}, "outputs": [ @@ -1224,10 +1183,10 @@ "output_type": "stream", "text": [ " 2355000 .curves.json\n", - "-rw-r--r-- 1 skl staff 720055 1 May 15:40 .curves.csv\n", - "-rw-r--r-- 1 skl staff 2965 1 May 15:40 .curves.csv.gz\n", - "-rw-r--r-- 1 skl staff 961219 1 May 15:40 .curves.pkl\n", - "-rw-r--r-- 1 skl staff 720055 1 May 15:40 .curves.tsv\n" + "-rw-r--r-- 1 skl staff 720055 1 May 07:51 .curves.csv\n", + "-rw-r--r-- 1 skl staff 2965 1 May 07:51 .curves.csv.gz\n", + "-rw-r--r-- 1 skl staff 961219 1 May 07:51 .curves.pkl\n", + "-rw-r--r-- 1 skl staff 720055 1 May 07:51 .curves.tsv\n" ] } ], @@ -1268,14 +1227,6 @@ "metadata": {}, "outputs": [], "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "73a341c5-36e5-47c2-9fb0-0a63b589b98b", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/resources/NBTest/NBTest_003_Serialization.py b/resources/NBTest/NBTest_003_Serialization.py index d1530d580..95f7a43db 100644 --- a/resources/NBTest/NBTest_003_Serialization.py +++ b/resources/NBTest/NBTest_003_Serialization.py @@ -19,6 +19,7 @@ from fastlane_bot.tools.cpc import ConstantProductCurve as CPC, CPCContainer from fastlane_bot.tools.optimizer import CPCArbOptimizer, cp, time from fastlane_bot.testing import * + except: from tools.cpc import ConstantProductCurve as CPC, CPCContainer from tools.optimizer import CPCArbOptimizer, cp, time @@ -204,16 +205,7 @@ assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, A=100, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, B=100, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, A=100, B=100, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) -#assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) - -# TODO - -# + -#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair="ETH/USDC", tkny="ETH", cid="1", descr="Carbon", isdydx=False) -#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair="ETH/USDC", tkny="ETH", fee=0, descr="Carbon", isdydx=False) -#assert raises(CPC.from_carbon, yint=1, y=1, pa=1800, pb=2200, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", isdydx=False) -#assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) -# - +assert raises(CPC.from_carbon, yint=1, y=1, pb=1800, pa=2200, pair="ETH/USDC", tkny="ETH", fee=0, cid="1", descr="Carbon", isdydx=False) assert not raises(CPC.from_carbon, yint=1, y=1, A=1/10, B=m.sqrt(1/2000), pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) assert raises(CPC.from_carbon, yint=1, y=1, A=1/10, B=m.sqrt(1/2000), pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=False) @@ -222,13 +214,7 @@ assert raises(CPC.from_carbon, yint=1, y=1, A=-1/10, B=m.sqrt(1/2000), pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) assert not raises(CPC.from_carbon, yint=1, y=1, pa=3100, pb=2900, pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) -#assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) - -# TODO - -# + -#assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) -# - +assert raises(CPC.from_carbon, yint=1, y=1, pb=3100, pa=2900, pair="ETH/USDC", tkny="USDC", fee=0, cid="2", descr="Carbon", isdydx=True) # ## Charts [NOTEST] @@ -400,5 +386,3 @@ - -