شعار Backtest Determinism And Reproducibility

Backtest Determinism And Reproducibility

المجتمع
HimanshuJ16
backtest-determinism-and-reproducibility

استخدم هذه المهارة عندما تنتج شيفرة الاختبار التاريخي وبياناته المتطابقة قيمًا مختلفة للربح والخسارة أو Sharpe بين عمليات التشغيل، ما يجعل التحسين غير موثوق: تهيئة عشوائية حتمية، وترتيب صارم للمدخلات، وساعة محاكاة تحل محل قراءات ساعة النظام، واكتشاف الاختلافات بين عمليات التشغيل.

نظرة عامة

الناشرHimanshuJ16
المستودعAlgo-Trading-Skills
اسم المهارةbacktest-determinism-and-reproducibility
النجوم
50
التفريعات
7
الملفات المرفقة
5
الترخيصApache-2.0
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 5

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها HimanshuJ16 على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Backtest Determinism And Reproducibility في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtest-determinism-and-reproducibility
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/backtest-determinism-and-reproducibility .claude/skills/backtest-determinism-and-reproducibility
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Backtest Determinism And Reproducibility في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Backtest Determinism And Reproducibility تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Backtest Determinism And Reproducibility بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

When to Use

Invoke this skill when building backtest simulation engines or CI regression suites. If backtest runs produce varying P&L curves or Sharpe ratios across identical code and data, parameter optimization becomes impossible to trust — you cannot tell an improvement from noise. Non-determinism comes from unseeded RNGs, set iteration order, unordered event streams, wall-clock reads, and floating-point accumulation order.

What This Can and Cannot Guarantee

It cannot guarantee bit-identical results in general, and no tool can. PyTorch's reproducibility guidance states plainly that "completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms," and that results may differ between CPU and GPU "even when using identical seeds." The same holds for BLAS thread counts, SIMD code paths, and library versions.

Determinism is a property of a pinned environment — same platform, same library versions, same thread configuration. This skill does two things within that envelope:

  1. Eliminates the controllable sources: seeding, event ordering, clock reads.
  2. Detects divergence when it happens, by comparing exact float bits.

Point 2 is the part that must not be compromised. Earlier versions of this skill rounded every float to 6 decimals before hashing, which meant the canonical non-determinism signature — sum([0.1]*10) (0.9999999999999999) versus 0.1*10 (1.0) — was reported as bit-identical. A detector that cannot see the thing it was built to detect is worse than no detector, because it produces confident false assurance.

When NOT to Use

  • As a tamper-evident audit record. The checksum is an unkeyed SHA256: anyone can edit a trade log and recompute it. For an authenticated record see backtest-audit-trail-for-regulatory-review.
  • To compare runs across different environments. Differing Python/NumPy/BLAS versions or thread counts will legitimately diverge; that is an environment-pinning problem, not something a checksum can fix.
  • To validate strategy correctness. A perfectly reproducible backtest can be reproducibly wrong — see lookahead-bias-elimination.

Prerequisites

  • A master integer seed (e.g. 42).
  • PYTHONHASHSEED set in the environment before the interpreter starts.
  • Pinned library versions and a fixed thread configuration for any run you intend to compare.

Workflow

  1. Set PYTHONHASHSEED before launching Python. This is the trap that catches people: hash randomization is fixed at interpreter startup, so os.environ["PYTHONHASHSEED"] = "0" inside running code does nothing while looking like it works. Launch as PYTHONHASHSEED=0 python backtest.py. check_hash_seed() reports whether the current process is safe; it cannot fix it.
  2. Seed the RNGs — and know what seeding misses. apply_master_seeds() seeds random, NumPy's legacy global RandomState, and torch when present. NumPy documents np.random.seed as a legacy function and recommends a dedicated Generator; code calling np.random.default_rng() draws fresh OS entropy and stays non-deterministic no matter how often you seed the global. Use make_numpy_generator() and thread it through explicitly.
  3. Sort the event stream by (timestamp, symbol, sequence_id). All three keys are required — a missing timestamp is rejected rather than defaulted to 0.0, which would silently move that event to the front. Duplicate sort keys are also rejected: Python's sort is stable, so tied events would keep their input order and the result would depend on how the file happened to be read.
  4. Replace wall-clock reads with SimulatedClock. Inject it rather than monkey-patching time.time() — patching a global affects every library in the process, including ones whose correctness depends on real time. The clock refuses to move backwards, which surfaces an unsorted stream immediately.
  5. Checksum with exact float bits and compare runs. audit_reproducibility() reports is_bit_identical and, on failure, first_divergence_index so you can go straight to the offending trade instead of staring at two mismatched hex strings.

Full procedure: see references/workflows.md. Standards and sources: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Rounding before hashing. Any tolerance applied before comparison erases exactly the sub-ulp divergences that signal non-determinism. float_precision exists for callers who explicitly want tolerant comparison, and it logs a warning saying what it costs.
  • Setting PYTHONHASHSEED from inside Python. It has no effect. The assignment succeeds, the variable reads back correctly, and set iteration order stays random.
  • Assuming dicts and sets behave alike. Dicts have preserved insertion order since Python 3.7 and are deterministic. Sets are not — iterating a symbol universe as a set gives a different order per process. With PYTHONHASHSEED at 0, 1, and 2, {'AAPL','MSFT','GOOG','TSLA'} iterates in three different orders. Iterate a sorted list.
  • Seeding only the NumPy global. np.random.seed() does not affect any Generator created by default_rng().
  • NaN in a trade log. json.dumps renders every NaN as the same token, so two runs that both corrupted to NaN hash identically and are declared reproducible. Non-finite values are now rejected outright.
  • Unsigned notional mistaken for P&L. Summing quantity * price across a round trip gives gross turnover, not equity: BUY 100@150 then SELL 100@155 sums to 30,500 while the realized P&L is 500. Cash flow must carry the side's sign.
  • Monte Carlo without a fixed seed. Slippage or execution-timing perturbations reseeded per run make every comparison meaningless.
  • Treating a matching checksum as proof of correctness. It proves two runs agreed, nothing more.

Verification

  • Run python -m unittest discover -s skills/backtest-determinism-and-reproducibility/scripts — 40 tests, 100% pass rate.
  • The test that matters: feed sum([0.1]*10) and 0.1*10 as prices for otherwise identical runs and confirm is_bit_identical is False. Pre-2.0 this returned True.
  • Run a backtest twice with identical inputs and confirm matching checksums; change the master seed and confirm the checksum shifts.
  • Confirm a missing timestamp or a duplicate (timestamp, symbol, sequence_id) raises DeterminismError rather than sorting silently.
  • Confirm SimulatedClock.advance_to() rejects a backwards jump.

Related Skills

  • walk-forward-validation-setup
  • monte-carlo-strategy-robustness-testing
  • vectorized-vs-event-driven-backtest-tradeoffs
  • backtest-audit-trail-for-regulatory-review — for an authenticated audit record, which this skill's unkeyed checksum is not
  • reproducible-ml-training-pipelines — the same problem for model training
  • dependency-pinning-and-reproducible-builds — pinning the environment determinism depends on

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Backtest Determinism And Reproducibility؟

استخدم هذه المهارة عندما تنتج شيفرة الاختبار التاريخي وبياناته المتطابقة قيمًا مختلفة للربح والخسارة أو Sharpe بين عمليات التشغيل، ما يجعل التحسين غير موثوق: تهيئة عشوائية حتمية، وترتيب صارم للمدخلات، وساعة محاكاة تحل محل قراءات ساعة النظام، واكتشاف الاختلافات بين عمليات التشغيل.

لماذا تستخدم Backtest Determinism And Reproducibility على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Backtest Determinism And Reproducibility عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Backtest Determinism And Reproducibility في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtest-determinism-and-reproducibility. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Backtest Determinism And Reproducibility؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Backtest Determinism And Reproducibility؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Backtest Determinism And Reproducibility معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Backtest Determinism And Reproducibility مجانية؟

نعم. نشرها HimanshuJ16 على GitHub بموجب ترخيص Apache-2.0. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇