From d8165652fcc92d32011e7781bcb0cfc693d67537 Mon Sep 17 00:00:00 2001 From: Markus Bilz Date: Mon, 4 Dec 2023 10:15:44 +0100 Subject: [PATCH] Deployed 599e356 with MkDocs version: 1.5.3 --- 404.html | 21 +- index.html | 149 ++++++++++++- naming_conventions/index.html | 382 ++++++++++++++++++++++++++++++++++ reference/index.html | 36 +++- search/search_index.json | 2 +- sitemap.xml | 9 +- sitemap.xml.gz | Bin 218 -> 237 bytes 7 files changed, 581 insertions(+), 18 deletions(-) create mode 100644 naming_conventions/index.html diff --git a/404.html b/404.html index 1e0ccf6..123f350 100644 --- a/404.html +++ b/404.html @@ -145,7 +145,7 @@
- +
karelze/tclf @@ -190,7 +190,7 @@
- +
@@ -290,7 +305,7 @@

404 - Not found

- + diff --git a/index.html b/index.html index 67fbd2f..9455392 100644 --- a/index.html +++ b/index.html @@ -152,7 +152,7 @@
- +
karelze/tclf @@ -197,7 +197,7 @@
- +
@@ -311,6 +347,27 @@
    +
  • + + Installation + + +
  • + +
  • + + Minimal Example + + +
  • + +
  • + + Advanced Example + + +
  • +
  • Supported Algorithms @@ -340,15 +397,89 @@ -

    Trade classification for python

    -

    tclf is scikit-learn-compatible implementation of popular trade classification algorithms to classify financial markets transactions into buyer- and seller-initiated trades.

    +

    Trade classification for python 🐍

    +

    GitHubActions +Codecov

    +

    tclf is a scikit-learn-compatible implementation of trade classification algorithms to classify financial markets transactions into buyer- and seller-initiated trades.

    +

    The key features are:

    +
      +
    • Easy: Easy to use and learn.
    • +
    • Sklearn-compatible: Compatible to the sklearn API. Use sklearn metrics and visualizations.
    • +
    • Feature complete: Wide range of supported algorithms. Use the algorithms individually or stack them like LEGO blocks.
    • +
    +

    Installation

    +
    $ pip install .
    +---> 100%
    +Successfully installed tclf-0.0.0
    +
    +

    Minimal Example

    +

    Let's start off simple: classify all trades by the quote rule and all other trades, which cannot be classified by the quote rule, randomly.

    +

    Create a main.py with: +

    import numpy as np
    +import pandas as pd
    +
    +from tclf.classical_classifier import ClassicalClassifier
    +
    +X = pd.DataFrame(
    +    [
    +        [1.5, 1, 3],
    +        [2.5, 1, 3],
    +        [1.5, 3, 1],
    +        [2.5, 3, 1],
    +        [1, np.nan, 1],
    +        [3, np.nan, np.nan],
    +    ],
    +    columns=["trade_price", "bid_ex", "ask_ex"],
    +)
    +y = pd.Series([1, 1, 1, 1, 1, 1])
    +
    +clf = ClassicalClassifier(layers=[("quote", "ex")], strategy="random")
    +clf.fit(X, y)
    +probs = clf.predict_proba(X)
    +print(probs)
    +
    +Run your script with +
    python main.py
    +
    +In this example, input data is available as a pd.DataFrame/Series with columns conforming to our naming conventions.

    +

    The parameter layers=[("quote", "ex")] sets the quote rule at the exchange level and strategy="random" specifies the fallback strategy for unclassified trades. The true label y is not used in classification and only for API consistency by convention.

    +

    Advanced Example

    +

    Often it is desirable to classify both on exchange level data and nbbo data. Also, data might only be available as a numpy array. So let's extend the previous example by classifying using the quote rule at exchange level, then at nbbo and all other trades randomly.

    +

    import numpy as np
    +from sklearn.metrics import accuracy_score
    +
    +from tclf.classical_classifier import ClassicalClassifier
    +
    +X = np.array(
    +    [
    +        [1.5, 1, 3, 2, 2.5],
    +        [2.5, 1, 3, 1, 3],
    +        [1.5, 3, 1, 1, 3],
    +        [2.5, 3, 1, 1, 3],
    +        [1, np.nan, 1, 1, 3],
    +        [3, np.nan, np.nan, 1, 3],
    +    ]
    +)
    +y_true = np.array([-1, 1, 1, -1, -1, 1])
    +features = ["trade_price", "bid_ex", "ask_ex", "bid_best", "ask_best"]
    +
    +clf = ClassicalClassifier(
    +    layers=[("quote", "ex"), ("quote", "best")], strategy="const", features=features
    +)
    +clf.fit(X, y_true)
    +
    +y_pred = clf.predict(X)
    +print(accuracy_score(y_true, y_pred))
    +
    +In this example, input data is available as np.arrays with both exchange ("ex") and nbbo data ("best"). We set the layers parameter to layers=[("quote", "ex"), ("quote", "best")] to classify trades first on subset "ex" and remaining trades on subset "best". Additionally, we have to set ClassicalClassifier(..., features=features) to pass column information to the classifier.

    +

    Like before, column/feature names must follow our naming conventions.

    Supported Algorithms

      -
    • Tick test
    • +
    • (Rev.) Tick test
    • Quote rule
    • -
    • LR algorithm
    • -
    • EMO rule
    • -
    • CLNV rule
    • +
    • (Rev.) LR algorithm
    • +
    • (Rev.) EMO rule
    • +
    • (Rev.) CLNV rule
    • Depth rule
    • Tradesize rule
    @@ -424,7 +555,7 @@

    References - + diff --git a/naming_conventions/index.html b/naming_conventions/index.html new file mode 100644 index 0000000..0d8dd25 --- /dev/null +++ b/naming_conventions/index.html @@ -0,0 +1,382 @@ + + + + + + + + + + + + + + + + + + + + Naming conventions - tclf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + +
    +
    + + + +
    +
    +
    + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    + + + + +

    Naming conventions

    + + + + + + + + +
    +
    + + +
    + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + \ No newline at end of file diff --git a/reference/index.html b/reference/index.html index 7379d35..11e3469 100644 --- a/reference/index.html +++ b/reference/index.html @@ -152,7 +152,7 @@
    - +

@@ -2258,6 +2273,21 @@