[Python] Minimal Modification Approach to Port Python Factor Calculation to DolphinDB with...

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python-based factor expression that I want to port to DolphinDB with minimal modifications while leveraging DolphinDB’s parallel computation engine. Could you advise on the most straightforward way to achieve this?

    The factor calculates a cumulative bid/ask volume ratio with exponential decay. Here’s the Python implementation:

    ask = df["av1"]
    bid = df["bv1"]
    p = df["mp"].iloc[0] # Scalar from the first value of 'mp'
    for i in range(2, 11):
    decay = np.exp(-10 * (i - 1) / p)
    ask += decay * df[f"av{i}"]
    bid += decay * df[f"bv{i}"]
    vol_diff = 0.5 * np.log(bid / ask)


    Assume df has columns:

    • mp (scalar-like, same value for all rows)
    • av1, av2, …, av10 (ask volumes)
    • bv1, bv2, …, bv10 (bid volumes)

    Expected Output:

    A DolphinDB script that replicates the logic of the Python code while adhering to DolphinDB best practices (vectorization, parallelization if beneficial).

    I’m aware of DolphinDB’s SQL-like syntax and vector programming features but need help with:

    • How to replicate the loop over columns av2-av10/bv2-bv10 concisely.
    • Proper syntax and functions for exponential decay and column arithmetic.
    • Whether parallelization requires explicit configuration (e.g., ploop, partitioning).

    Continue reading...

Compartilhe esta Página