Saturday 16 December 2017

Quantstrat - الفوركس تداول


استخدام كوانسترات. لتقييم استراتيجيات التداول خلال اليوم. هذا الإصدار: 1 استخدام كوانسترات لتقييم استراتيجيات التداول اللحظي هذا الإصدار: 2 محتويات إنشاء استراتيجية أدوات R استراتيجية الأقصر: تنفيذ بسيط تحسين المعلمات الخروج وإدارة المخاطر المشي إلى الأمام تحليل الملحق 3 نظرة عامة وقال ريتشارد فينمان أن العلم كان عملية أول تخمين ، ثم حساب عواقب ذلك تخمين (بناء نموذج)، وأخيرا تأكيد أو رفض تخمين مع التجربة. ما الذي نتمنى تحقيقه ما هي األدوات التي نستخدمها تخلق نهجا علميا يستند إلى الفرضية إلى االستراتيجية الكمية 4 إنشاء االستراتيجية: صياغة مسار فكرة فكرة الفرضية في منصة البحث) R، البيانات التاريخية) مثل رويترز ( صقل إذا كان الوعد (أو الأفكار الجديدة تشير إلى أنفسهم أثناء الاختبار) ترفض بسرعة إن لم تكن واعدة فإن الأغلبية الساحقة (90) من الأفكار لن تعمل على أداء متانة المعلمة والمشي قدما الاختبار الأمثل عندما يكون لديك نموذج بحث موثوق (كود الكوانت الخاص بك)، وتنفيذ لطرح الإنتاج أفكار في استراتيجيات الخروج 5 إنشاء الاستراتيجية. اختبار المنتج اختبار المنتج يمكن القيام به قبل وبعد طرح الإنتاج تحديد الفرضيات حول آلية عمل الاستراتيجية. كيف استراتيجيتكم كسب المال إنشاء قوائم من الأدوات التي قد تكون خاضعة لنفس الطريقة من العمل اختبار الأدوات المستهدفة تبدأ مع المعايير القياسية أو نطاقات المعلمة المدى المعلمة المتانة والمشي قدما إلى الأمام الأمثل على الأصول واعدة طرح أدوات جديدة للإنتاج 6 تحسين الاستراتيجية يتم تنفيذ أي استراتيجية حتى إيقاف تشغيله جمع الأفكار حول تحسين استراتيجية إضفاء الطابع الرسمي الفرضيات من الأفكار تحديد الاختبارات التي من شأنها أن تظهر التحسن على أساس فرضية تحديد معايير النجاح لقياس فرضية تحسين فرضية النتائج في تنفيذ البحوث المرجعية للاستراتيجية أداء التحسينات القياسية على الأدوات التي يتم تداولها حاليا في الاستراتيجية تقييم الأداء: إذا تحسنت أداء العينة، أدخلت تغييرات في الشفرات لوضعها في الإنتاج صياغة الفرضية حدد الاختبارات تطبيق الاختبارات هل تحسين الأداء نعم تطبيق الإستراتيجية لا 7 أدوات R كيف سنفعل كل هذا 8 المحاكاة التجارية سلسلة الأدوات M أنيج داتا إيفالوات داتا تحديد الصفقات الحجم الصفقات حساب الأداء تحليل الأداء تحديد مواصفات العقد حساب العوائد والمخاطر التقاط الصفقات مقارنة مع المعايير حساب المواقف توفير الإسناد حساب بامبل تحليل المخاطر أنواع الأنشطة الاتصال بقاعدة البيانات حساب المؤشرات تقدير التسعير بريتريد تحسين محفظة تحميل البيانات التاريخية تحويل الأسعار العائد المتوقع مخاطر الميزانية تقدير التقلب مخاطر التنبؤ تنظيف ومحاذاة البيانات الرسوم البيانية والمؤشرات حساب حجم زائدة تقييم القواعد توليد إشارات حساب الهدف الهدف حساب حجم التجارة تقييم تكاليف التداول الحافظة الإجمالية مثال R الحزم الفهرسة كتمود رتاق شتس. تر سيغنالكستراكتيون أوركا. كوانسترات كوانتمود لسبم المحفظةناليتيكش نفق بارما تحليلات أداء الأدوات المالية 9 مؤشرات كوانستراتس إشارات قواعد - القيمة الكمية المستمدة من بيانات السوق - تطبق بطريقة متجه أو متدفقة - يفترض أن تكون قادرة على أن تحسب بطريقة باثندبندنت - لا معرفة الوضع الحالي أو الصفقات - أمثلة: المتوسطات المتحركة، نطاقات التقلب، مؤشر القوة النسبية، مؤشر الماكد، القنوات، أي مؤشرات التحليل الفني - وصف التفاعل بين بيانات السوق والمؤشرات - وصف الرغبة المحتملة لاتخاذ إجراء، ولكن قد لا تكون قابلة للتنفيذ - تطبق بطريقة متجهية أو متدفقة تستخدم ل إبلاغ قرارات القواعد أمثلة: عمليات الانتقال، عتبات، مضاعفات - تقييمها بطريقة تعتمد على مسار - هل لديك جميع بيانات السوق المتاحة قبل المراقبة الحالية - هل علم بالوضع الحالي في وقت التقييم - توليد أوامر الدخول والخروج وإدارة المخاطر - قد إدخال أوامر جديدة أو تعديل أوامر القائمة - أنواع: الدخول، الخروج، المخاطر، إعادة التوازن، سلسلة ديس استعملت واستخدمت لاستراتيجيات كمية حقيقية في جميع الترددات العديد من الاستراتيجيات يمكن أن تكون مبنية من جميع المكونات مفتوحة المصدر استراتيجيات الملكية إضافة مؤشرات مخصصة وظائف إشارة ترتيب منطق التحجيم 10 تركيب حزمة كوانترسترات بلوتر، كوانتمود، فينانسيالينسترومنت، شت كران كوانتسترات ليس (حتى الآن) متوفرة على كران تارزيب: سفن سن كو سفن: r-forge. r-project. orgsvnrootblotter جيثوبيلكترادربلوترويكيينستالاشيون غايد-فور-ويندوز القائمة البريدية: 11 استراتيجية الأقصر تنفيذ بسيط انظر: أنظمة التداول: نهج جديد لتطوير النظام وتحسين المحفظة بي إميليو توماسيني، أوربان جيكل - هاريمان هاوس لندن إيسبن (s). 12 حول التعليمات البرمجية لا قطع ولصق رمز من هذه الشرائح أحدث رمز لهذه الوظائف في مستودع حزمة على R - فورج سيتم الحفاظ على التجريبي الأقصر العثور على البرامج النصية في الدليل التجريبي كوانسترات لا يزال في التنمية، وسوف والاستمرار في تغيير في الطرق الصغيرة (وأحيانا كبيرة) التوافق الوراء أمر مهم، ولكن لن نضحى ملامح التوافق 13 استراتيجية كوتلوكسوركوت بيانات الرمز: غبوسد 30 دقيقة أوهلك معبر 2 سما: سما n10 (كوتفكوت) سما n30 (كوتسلوكوت) منطق الإدخال : طويل: وقف الحد عند أعلى من شريط العبور سما قصيرة: وقف الحد عند أدنى شريط عبور سما 14 فينانسيالينسترومنت مخازن البيانات الوصفية. تحديد الأدوات، أي. العملات: تتطلب عملة (فينانسيالينستروتمنت) (c (غب، أوسد)) إما التبادل (بريماليديغبوسد، تيكسيز 0،0001) أو إكسهانجيرات (كيرنسيوسد، كونتيركورنسيغبب، ticksize0.0001) في بيئة الإنتاج، وكنت أشبه استخدام سافينسترومنتس () و لوادينسترومنتس () لإعادة استخدام بيئة الجهاز بالكامل 15 استرجاع بيانات الرمز data. dir lt - R. symbols for example. from lt -.to lt-itsymbols. fi (سيمبولسغبوسد، dirdata. dir، from. from، to. to) أو (أكثر عمومية) setymbollookup. fi (baseird. d.d، سيمبولسغبوسد) جيتسيمبولز (غبوسد، from. from، to. to) أو (كوانستراتديمو) gotymbols. fi (سيمبولسغبوسد، dirsystem. file (إكستداتا، باكاجكانتسترات)، from. rom، to. to) 16 شتس غبوسد كائن البيانات غ gtymbols. fi (سيمبولسغسبوسد، dirsystem. file (إكستداتا، باكاجكانتسترات)، من، إلى) تحميل غبوسد. نحن لا نحتاج جيتسيمبولز ()، كل هذا يمكن القيام به مع حفظ () وتحميل () ضبط فترات تغيير توقيت الدورية ضبط المحاذاة (اختياري) القراءة الجنيه الاسترليني. فعله. قراءة الجنيه الأمريكي. فعله. لتر. غ القراءة جنيه استرليني. فعله. قراءة الجنيه الأمريكي. فعله. ربيندينغ البيانات. فعله. 1 غتبوسدكوت غ غبوسد to. minutes30 (غبوسد) غ غبوسد align. time (غبوسد، 1800) غ غب (غبوسد) أوبين هاي لو كلوز حجم: 30. 00. 30. 00. 30. 00: قد تكون بياناتك مختلفة، ولكن تنسيقها وفقا ل is. ohlc () أو is. bbo () من كوانتمود سيجعل حياتك أسهل 17 إنشاء استراتيجية كائن استراتيجية جديدة (ناملوكسور، ستوريترو). ستراتيغي كائن إستراتيجية البيئة (ستوريترو) مكونات عنصر الكائن أورديربوك مؤشرات إشارات قواعد بارامسيتس يخلق كائن مكداتا 18 كائن مكداتا كستس جدول البيانات واستراتيجية سكراتشباد في البداية: بيانات رمز من محفظة غ رأس (غبوسد) فتح عالية منخفضة إغلاق حجم: 01. 02. 04. 05. 06: مؤشرات ستضيف أعمدة إشارات ستضيف أعمدة المستخدم قد تضيف أعمدة 19 كوانسترات جميع كوانسترات هو مؤشرات وحدات - القيمة الكمية المستمدة من بيانات السوق - تطبق بطريقة متجه أو متدفقة - يفترض أن تكون قادرة على سبيل المثال لا الحصر في الوضع الحالي أو الصفقات - أمثلة: المتوسطات المتحركة، فرق التقلبات، مؤشر القوة النسبية، ماسد، القنوات، أي مؤشرات التحليل الفني إشارات - وصف التفاعل بين بيانات السوق والمؤشرات - وصف الرغبة المحتملة لاتخاذ إجراء ، ولكن قد لا يكون قابلا للتنفيذ - التطبيقية في متجه أو تدفق الأزياء تستخدم لإبلاغ قرارات الحكم أمثلة: عمليات الانتقال، عتبات، مضاعفات قواعد - تقييمها بطريقة تعتمد على مسار - هل لديك جميع بيانات السوق المتاحة قبل المراقبة الحالية - هل علم من الحالية موقف في وقت التقييم - توليد أوامر الدخول والخروج، وإدارة المخاطر - قد أدخل أوامر جديدة أو تعديل الأوامر القائمة - أنواع: دخول، خروج، ريس k، إعادة التوازن، السلسلة اسم خاصية معظم وظائف كوانتستراتس يسم دالة للاتصال استفد من التنفيذ المتأخر يمكن تطبيق مواصفات الإستراتيجية الخاصة بك على أدوات مختلفة أو أطر زمنية مختلفة 20 المؤشرات المؤشر: الحساب الرياضي استنادا إلى حجم الأمان وحجم أندور (إنفستوبيديا) على سبيل المثال. ما، ماسد، مؤشر القوة النسبية، مؤشرات مخصصة توفر حزمة تر العديد من المؤشرات الكلاسيكية، a. o. ما، ماسد، رسي الخ العديد من استراتيجيات الملكية استخدام مؤشرات مخصصة 21 كوانسترات :: add. indicator () add. indicator (استراتيجية الأقصر، اسم سما، قائمة الحجج (س اقتباس (كل (مكداتا)، 1)، ن 10)، تيلكوتنفاستكوت ) سما ()، إما () رسي () ستوش () داتا add. indicator (ستاتيك لوكسور، نيم سما، أرغمنتس ليست (x كوت (كل (مكداتا)، 1)، n 30)، لابيلوتنسلوكوت) . مؤشرات تر استخدام كائن مكداتا تطبيق كل () الدالة: العمود الأول اسمه كلوز اقتباس (): تقييم لاحقا تسمية اسم مكداتا عمود 22 إشارات إنفستوبيديا: علامة، عادة ما تكون على أساس المؤشرات الفنية، أنه هو الوقت المناسب لشراء أو بيع أمن خاص كوانتسترات: تشير الإشارات إلى الأوقات التي قد ترغب الاستراتيجية في اتخاذ إجراء بشأنها. مثلا سيغكروسوفر ()، سيغكسترول ()، سيغفورمولا () 23 كوانسترات :: add. signal () add. signal (ستراتيجيلوكسور، نامسيكروسروس، قائمة الوسيطات (كولومنسك (كوتنفاستكوت، كوتنسلكوت)، ريلاتيونشيكوتغتكوت، لابيلونغ) add. signal (ستراتيجيلوكسور، نامسيكروسوفر ، قائمة الحجج (أعمدة (كوتنفاستكوت، كوتنسلكوت)، ريلاتيونشيكوتلتكوت)، لابيلشورت) وظائف العينة: سيغكروسوفر () سيغكشولد () سيغكبارشون () سيغفورمولا () سيغبيك () وسيطات: الأعمدة العلاقة، كوتغكوت، كوتلوت، كوتكوت، مكان في مكداتا 24 قواعد القواعد هي مسار تعتمد، والوصول إلى السوق الحالية وحالة محفظة عادة ما تسببها أنواع قاعدة إشارة خطر ترتيب إعادة التوازن الخروج قواعد سلسلة هي النقطة التي الاستراتيجية قد تضع أو إلغاء أمر 25 كوانسترات :: إضافة. rule () add. rule (إستراتيجية، وظيفة لتطبيق، قائمة الوسيطات للدالة لتطبيق النوع، التسمية) الدالة: عادة رولزسينال () نوع القاعدة: إدخال، خروج، خطر. التسمية: يظهر في كتاب النظام إذا لم يكن استخدام قواعد، استخدام وظيفة مع توقيع حجة مماثلة للاستفادة من الحد من البعد 26 كوانستراتال :: قواعد () قواعد (سيغكولونغ، سيغفالترو، أوديسيديلونغ، أورديرتيبيستوبليميت، بريفيرهي، point0.0005، orderqty100000 ، ريبلاسفالس) أورديرتيبس: الحد ستوبليميت السوق ستوبترايلينغ المعاملات على الباروبس المقبل. الافتراضي بريفلكلوس فيض يفضل: عمود السعر لاستخدامها من عتبة كائن البيانات: إضافة إلى السعر 27 add. rule () - قواعد دخول الأقصر add. rule (ستراتيلوكسور، ناموليزينال، أرغمنتليست (سيغكولونغ، سيغفالترو، أوديزديلونغ، أورديرتيبيستوبليميت، بريفرهيغ، عتبة. ثريشولد ، orderqty. orderqty، ريبلاسفالس)، تيلنتر، لابيلنترلونغ) add. rule (ستراتيلوكسور، ناموليزينال، أرغمنتسليست (سيغكولشورت، سيغفالترو، أوردرزديتشورت، أوردرتيبيستوبليميت، بريفيرلو، عتبة-. عتبة، أورديركتي-.orderqty، ريبلاسفالس)، تيبنتر، لابيلنتيرشورت) ستوبليميت (عتبة منخفضة) كما سعر الحد نحن لا نريد أن تحل محل أي أوامر الخروج المعلقة 28 add. rule () - قواعد الخروج لوكسور add. rule (استراتيجية. ست، ناموليزينال، أرغمنتليست (سيغكولونغ، سيغفالترو، أوردرزديتشورت، أورديرتيبيماركيت ، أورديركتال، TxnFees. txn. fees، ريبلاسيترو)، تيبكسيت، labelexit2long) add. rule (strategic. st، ناموليزينال، أرغمنتليست (سيغكولشورت، سيغفالترو، أوردرزديلونغ، أورديرتيبماركيت، أوردي ركيتال، ماركيتال تسنفيس فقط على قواعد الخروج: نهاية علامة تجارية للتجارة () استبدال أي المعلقة (فتح) أوامر الدخول TxnFees. txn. fees، ريبلاسيترو)، تيبكسيت، labelexit2short) بالتناوب، استخدم ميثودتراد ل ترادستاتس () 29 كوانسترات :: (غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد كوت إيت إيت ترادس 1 كوت: 30: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد كوت 1 كوت : 00: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد كوت 1 كوت: 00: 00 غبوسد 1.553quot 1 كوت: 00:00 غبوسد 1.553quot 1 كوت: 00: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد كوت 1 كوت: 30: 00 غبوسد 1.555quot 1 كوت: 00: 00 غبوسد كوت 1 كوت: 30:00 غبوسد النقص في المعاملات عند هذه النقطة ربما يعني أن لديك مشكلة 30 كائن مكداتا: غ عرض (مكداتا) 31 كوانسترات :: جيتورديربوك () غ عرض (جيتوردربوك (portfolio. st) الفوركس فوريكسغبوسد) 32 بلوتر :: أوبداتيبورتف () أوبدات إيبورتف (portfolioportfolio. st، سيمبولسغبوسد، ديستيباست (::، as. Date (Sys. time ())، سيب)) غ لصق (::، as. date (sys. time ())، سيب) 1 كوت. (أوبتيونبورتف) (علامة كتاب المحفظة مع مختلف التدابير المحاسبية إذا كنت تعمل مع بيانات عالية التردد، فمن الشائع بمناسبة الكتاب على الترددات المنخفضة اختيار تردد بمناسبة الكتاب على لا يغير أي بيانات التجارة، والتي قد (ترادستاتس (فوريكس))) ترادستاتس () يحسب الاحصاءات التي يشاهدها عادة في تقارير الاستراتيجية من الكتب ومنصات التنفيذ يتم حساب الصفقات مسطح إلى مسطح لهذا التقرير، وهو ما يمثل كامل ذهابا وإيابا يتم شرح جميع الإحصاءات بالكامل في وثائق 36 النشاف :: بيرترادستاتس () بيرترادستاتس () بجمع إحصاءات عن الصفقات مسطحة إلى مسطحة دعا من قبل charts. me للبيانات الخام تلك الرسوم البيانية من رسم يمكنك استخدام هذه الصفقات الفردية كما المدخلات لتحليل مونت كارلو لاستراتيجيتك 37 كوانسترات :: حفظ. استراتيجية () حفظ استراتيجية، حتى نتمكن من تحميله في وقت لاحق وإضافة المزيد من المكونات، أو تنطبق على سيناريوهات مختلفة save. strategy (strategic. st) لس - l الأقصر. rdata - rw-r - r-- 1 جان المستخدمين أبريل 7 22:53 luxor. rdata load. strategy (strategic. st) 38 كوانسترات تحسين المعلمات 39 المعلمة الأمثل جميع الاستراتيجيات لديها معلمات: ما هي الصحيحة تلك أعداد أكبر من المعلمات الحرة زيادة كبيرة في كمية البيانات التي تحتاج إليها، وخفض درجات الحرية الخاصة بك وزيادة فرصتك في الإفراط في الحياكة حتى اختيارات المعلمة الأولية الخاصة بك هي الأمثل، يويف اختيار القيم التي تعتقد قد يكون الأمثل الأمثل المعلمة فقط يضيف العملية والأدوات لقرار الاستثمار الخاص 40 المعلمة مجموعات تحسين معلمات الإستراتيجية مجموعات المعلمات هي جزء من إستراتيجية paramset. label توزيعات سما فاستسما تتراوح من 1 إلى 30 نطاق سلوسما من 20 إلى 80 قيود فاستسما لوت سلوسما application. paramset () تستدعي أبليستراتيغي () اختيار عشوائي أو جميع المجموعات 41 تحسين قيم الأقصر سما . فاستسما (1:30).SlowSMA (20:80) add. constraint (s، paramset. label سما، Distribution. label.1 فاست، load. strategy (strategic. st) Distribution. label.2 نسلو، أوبيراتور لوت، add. distribution (Strong. st، لابيل سما) paramset. label سما، المكون. النوع، save. strategy (strategic. st) المكون. ملف ناستف، قائمة المتغير (n. FastSMA)، تسمية نفاست) add. distribution (ستراتيجيك. ست، paramset. label سما، المكون. النوع، المكون. ملف نسلو، نريد حذف هذه القائمة المتغيرة للمعلمة (n. SlowSMA)، التسمية نسلو) delete. paramset (ستراتيجيك. ست، سما) 42 فوريش باكيج هجين من معيار حلقة و وظيفة لابلي يسهل الموازاة إرجاع دالة فالويبين الافتراضي قائمة بعض الموازين الخلفية: ريجيستيردوسق (): الخلفية الخلفية (متتابعة) دومكدوباراليل: وحدات المعالجة المركزية متعددة أو النوى دورديس: عبر منصة الخلفية ريديس الخادم ريديس العمال 43 application. paramset (ريسيددومك (cores8) load. strategy (survey. st) النتائج lt - application. paramset (ستاتيستيكش. st، paramset. labelsma، portfolio. stportfolio. st، نسمبلز 80، أوديت نول، فيربوسيترو) برينت (ريسولسترادستاتس ) يخلق بارامبوس من التوزيعات والمعوقات قيد التطبيق () على المحفظة لكل معلمة. كومبو نامسامبلز: يوجه تدقيق الاختيار العشوائي: اسم الملف لتخزين جميع المحافظات والكتب 44 تراكستاتس معلمات سما () عرض (t (ريسولسترادستاتس)) 45 كوانسترات :: ترادغرافس () عرض الرسوم البيانية التجارية من احصائيات ترادغرافس (ستاتس ستاتس، free. params c (كوتارام. إنديكاتور .1.nFastquot، كوتارام. إنديكاتور .2.nSlowquot)، إحصائيات c (كوتنيت. Trading. PLquot، كوتاكسراودونكوت، كوتافغ. تريد. بلكوت، كوتنوم. تريدسوت، كوتبرويت. فاكتوركوت)، العنوان الأقصر سما المعلمة المسح الضوئي) يخلق عرض 3-D من سطح المعلمة بشكل مثالي، فإن الاستراتيجية تكون المعلمة قوية على نحو سلس نسبيا لا قمم ضخمة على أساس التغييرات الصغيرة ترادغرافس () يمكن أن تولد الرسوم البيانية متعددة مع مكالمة واحدة يتطلب حزمة رغل 47 كوانسترات الخروج وإدارة المخاطر 48 طلب مجموعات مجموعة تتكون من واحد أو أكثر أوامر أوكو أوكو - واحد يلغي الآخر إذا يحصل على شغل واحد، يتم إلغاء جميع الآخرين التي حددها أوسكيت اسم العلامة على سبيل المثال. أمر وقف الخسارة أمر ترتيب الربح (أوديتسيتشولونغ). عادة ما يتم دمجها مع سلاسل الطلبات 49 ترتيب سلاسل حكم ملء ملء الطلب من أمر واحد بإنشاء أمر جديد (الأوامر) أمر الأم التي تم تحديدها من قبل أوامر الأطفال كوتللكوت استخدام المعلمة كوتارنتكوت للإشارة إلى الوالد عادة جنبا إلى جنب مع مجموعات النظام 50 أوردرزيتس أمب أوردرشينز وقف الحد من أجل الدخول أورديرشين الوالدين أورديرسيت ترتيب سلسلة ستوبليميت النظام كوتستوب فاكتوت ستوبليميت النظام كوتستوب ترايلكوت الحد من أجل اقتباس بروفيكوت 51 قاعدة لوقف الخسارة add. rule (ستراتيغي. ست اسم قاعدة، ريجيمنتليست (سيغكولونغ ، سيغفالترو، ريبلاسيفالز، إمبليديلونغ، أوردرتيبيستوبليميت، تمولترو، ثيرمنتكوت (.stoploss)، TxnFees. txnfees، أورديركتيل، أوديسيتكولونغ)، تيبشين، بارنتنتيرلونغ، لابيلستوبلوسلونغ، إنابلدفالز) add. rule (ستراتيجيك. ست، نيم رولزينيال، أرغمنتسليست (سيغكولشورت، سيغفالترو ، ريبلاسفالس، أوردرزديشورت، أورديرتيبيستوبليميت، تمولترو، ثيردكوت (.stoploss)، TxnFees. txnfees، أورديركتال l، أوديسيتوكوشورت)، تيبشين، بارتنتيرشورت، لابيلستوبلوسشورت، إنابلدفالز) نوع أمر السلسلة عتبة الأصل تمولت عتبة الاقتباس () تمكين استبدال يجب أن يكون فالس (أوديسيتس) 52 ترتيب ترتيب التحجيم التحجيم، مثل كل شيء آخر في كوانسترات، هو وحدات. يمكنك كتابة وظائف التحجيم النظام الخاص بك. وشملت ما يلي: قواعد () يتضمن أوسفون حجة أوسنوب () أي عملية، أوسماكسبوس الافتراضي () تنفذ مستويات بسيطة على أساس الحد الأقصى يعمل مع أدبوسليميت () و جيتبوسليميت () 53 أدبوسليميت () أمب أوزماكسوس () أدبوسليميت (portfolioportfolio. st، سيمبولغببوسد ، تيمستامبينيتدات، maxpos. orderqty يفصل الحد الأقصى من المواقف من القواعد) add. rule (ستراتيجيك. ست، اسم القواعد، سيغكولونغست (سيغكولونغ، سيغفالترو، ريبلاسفالس، أوديسيديلونغ، أورديرتيبيستوبليميت، بريفيرهي، يجعل القرارات على أساس الوضع الحالي، وليس عتبة أوامر مفتوحة. عتبة، TxnFees0، orderqty. orderqty، مطلوب مع أوسديتس أوسفونوسماكسوس، أوديسيتولوكونغ)، تيبنتر، تيمسبان، تيمبيان، لابيلنترلونغ) وظائف التحجيم ترتيب أخرى ممكنة، أوسماكسبوس () مثال 54 نهج التجارة الأمثل معلمات نهج فورسكيوت كوتوروت يغطي جزء كبير من إجمالي المعلمة الفضاء ميمف - كوتغرافسكوت كوانتيليز - كوتاتاتيستيكوت استخدام البيانات من باكتست أو إنتاج التجارة إلى إيفالوا تي حيث يمكن إضافة وقف الخسارة أو أوامر أخذ الأرباح المشي إلى الأمام الاستفادة من وظيفة موضوعية لتغيير المعلمات من خلال الوقت 55 وقف الخسارة باستخدام المعلمة paramsets. stoploss (0.05، 2.4، length. out48) 100 تتطلب (فوريتش) تتطلب (دومك) إضافة (stes. st، ريجيستيردومك (cores8) paramset. label ستوبلوس، المكون. سلسلة النوع، plug. label ستوبلوسلونغ، قائمة المتغير (العتبة. StopLoss)، النتائج lt - application. paramset (strategic. st، paramset. labelstoploss، بورتفوليو. stportfolio. st، account. staccount. st، nsamples80، فيربوسيترو) لابيل ستوبلوسلونغ بلوت (100resultstradestatsstoplosslong، statsnet. trading. pl، تيبب، زلابستوبلوس، ylabnet. trading. pl، مينلوكسور)) add. distribution (strategic. st، بارامسيت. التسمية ستوبلوس، المكون. نوع السلسلة، المكون. ملف ستوبلوسشورت، قائمة المتغير (العتبة. StopLoss)، التسمية ستوبلوسشورت) add. constraint (ستاتيست. st، paramset. label ستوبلوس، Distribution. label.1 ستوبلوسلونغ، Distribution. label.2 ستوبلوسشورت ، المشغل، التسمية ستوبلو سس) 56 تراديستاتس المتوقف عن الخسارة () عرض (t (ريسولتسترادستاتس)) 57 مي: ماكس أدفيرز إكسكورسيون chart. me (بورتفوليوفوريكس، سيمبولغبوسد، تيبيماي، سليبيرسنت) الصفقات على محور قطري مغلقة على أدنى مستوياتها تداول على المحور الرأسي شهدت أي تراجع نوع chart. ME مي ميف في المئة النقدية في المئة علامة 58 مي باستخدام 0.4 وقف الخسارة 59 مف: ماكس مواتية الرحلات chart. me (بورتفوليولوكسور، سيمبولغبوسد، تيبيمف، سليبيرسنت) الصفقات على محور قطري مغلقة على ارتفاعاتها يتداول على المحور الرأسي من ذوي الخبرة لا موجب بامبل الخط الأفقي يدل على تأثير وقف في هذه المجموعة من البيانات 60 أخذ الربح باستخدام بارامسيتس مؤامرة (100statstakeprofitlong، statsnet. trading. pl، تيبب، زلابتيكيستروفيت، ylabnet. trading. pl، مينلوكسور) مؤامرة (100statstakeprofitlong، ستاتسماكس. دراوديلون، تايب، xlabmax. drawdown، ylabmax. drawdown، مينلوكسور) 61 بيرفورمانساناليتيكش :: chart. Histogram غ بس lt - بيرتراديستاتس (فوريكس، سيمبولغبوسد) غ chart. histogram (pspct. trading. pl، ميثودسك (add. normal)، مينلوكسور إعادة تورنيس) قم بإيقاف الذروة: وقف الخسارة جني الأرباح ملاحظة أخرى: الانحراف السلبي التعرية الإيجابية الزائدة 62 نفاذة :: ترادكوانتيلز () غ ترادكوانتيلز (فوريكس، سيمبولغبوسد، سليبيرسنت، بروبسك (.5، .9، .99)) forex. gbpusd pospctpl 50 بوسبكتبل 90 بوسبكتبل 99 نيجبكتبل 50 نيجبكتبل 90 نيجبكتبل 99 بوسبتمف 50 بوسبتمف 90 بوسبتمف 99 بوسبتماي 50 بوسبتماي 90 بوسبتماي 99 نيجبتمف 50 نيجبتمف 90 نيجبتمف 99 نيجبتكماي 50 نيجبتكماي 90 نيجبتماي 99 ترادكوانتيلز () بحساب وإرجاع إحصاءات كوانتيليز من الإيجابية والسلبية بامبل مي مف مي خط ماكس يلتقط ذروة التوزيع (مع الكمال بعد الأوان) مي ماكس (كمبل) خيارات أخرى تشمل كوانتيليز كما القراد، أو النقدية بامبل 63 كوانسترات المشي التحليلي إلى الأمام 64 المشي إلى الأمام تحليل المشي المشي إلى الأمام إعادة صياغة ديباراميترزس استراتيجية في الإنتاج بشكل دوري، وهذا يمكن أن يتم يوميا والأسبوعية والشهرية، أو الفصلية تحليل نافذة المتداول هو الأكثر شيوعا، ويفترض تطور المعلمة الفضاء تحليل الراسية يفترض أن بقايا معلومات آل من الفترات السابقة يساعدك على اتخاذ القرارات الآن 65 walk. forward () إس lt - فونكتيون (account. st، portfolio. st) my. obj. func lt - فونكتيون (x) walk. forward (strategic. st، بارامسيت. account. stportfolio. st، account. staccount. st، بيريودونثس، k. training3، k. testing1، obj. funcmy. obj. func، obj. argslist (شكوت (resultapply. paramset))، user. funcess، وسر. أرغزليست (account. staccount. st، portfolio. stportfolio. st)، audit. prefixwfa. ples، أنكوريدفالس) chart. posn (portfolio. st) عرض (t (تراستاتس (portfolio. st))) وظيفة الهدف فترة الدالة (يعمل على سيد) وظيفة المستخدم الاختيارية (يعمل على العبيد) audit. prefix الراسية 66 walk. forward () الرسوم البيانية chart. forward. testing (wfa. trading. pl. results. rdata) رديتا) chart. forward. testing (wfa. max. drawdown. النتائج. 67 walk. forward () باستخدام إس اختيار وظيفة الهدف الخاص بك هو مهم جدا للمشي قدما التحليل في هذه الحالة، وظيفة الهدف يختار بدلا من الفقراء خارج العينة المعلمات مطاردة أعلى إنزامبل End. Eq لا يعمل. 68 التذييل أشياء أخرى نحن على الأرجح ليس لديهم الوقت ل 69 السرعة: مما يجعلها أسرع كوانستراتس السرعة هي وظيفة خطي تقريبا لعدد من التقييمات القاعدة وهذا يعني أنه يجب عليك الحرص على عدم إضافة قواعد لا داعي لها يجب عليك أيضا النظر في مرحلة ما قبل تجهيز الإشارات الخاصة بك عبر عمليات منطقية ونوع من الممكن الحصول على سرعات دقيقة واحدة لكل رمز في اليوم الواحد على البيانات عالية التردد 70 تحليل عوائد العمل كواترسترات (وفلوتر) في كوتريس والتجارة الفضاء في بعض الأحيان تحتاج إلى القيام بتحليل في كورتورنز سباسكوت وظيفة بورتفريتورنز () يولد عوائد من محفظة الأسهم علما أن هذا حساس لبدء الأسهم انظر التجريبي (رسي) والتجريبي (فابر) للحصول على أمثلة يجعل كل تحليل العائد على أساس حزم مثل بيرفورمانساناليتيكش أو بورتفوليواناليتيكش متاح 71 إعادة التوازن كيف يمكنك تخصيص رأس المال بين الصكوك المختلفة في استراتيجية تطبق دوريا قاعدة إعادة التوازن وتشمل كوانستراتات خاص إعادة التوازن نوع القاعدة ونسخة خاصة من applystrategy (). applystrategy. إعادة التوازن () مثال إعادة التوازن قواعد القواعد و يتم توفير قاعدة الوزن انظر عرض (فابيربال) على سبيل المثال التخصيص عبر استراتيجيات ربما يتطلب بورتفولياناليتيكش، وليس فقط إعادة التوازن قواعد 72 الاشياء العمل المزيد كانوا يعملون على أو ترغب في تجميع أبليترولز نقل حلقة تعتمد على مسار الدولة آلة إلى أسرع تهيئة التعليمات البرمجية المترجمة والتخفيضات التفاف أسفل على رمز نمطي من شأنه أن يقلل من الازدواجية رمز في سبيل المثال بارامسيتس مونتي كارلو أو تحركات عشوائية على غرار بيرنز تحليل الهدف المعمم للسير إلى الأمام تحليل موسوعة استراتيجيات التداول تتورط كتابة العروض التي يمكن أن تدرج في الحزمة 73 خاتمة اتباع نهج علمي ل باكتستينغ: تخمين بناء نموذج اختبار الفرضية الخاصة بك من خلال التجربة بقايا التجربة خطر محاولة لجعل أكبر عدد ممكن من الافتراضات الخاصة بك ممكن صريح وليس ضمني باكتست أن يجعل المال يتيح لك إمكانية لكسب المال في الإنتاج مع النموذج الخاص بك، وخسارة باكتست يكاد يكون ضمانة لخسائر الإنتاج الأكبر 74 ملخص إنشاء استراتيجية R أدوات استراتيجية الأقصر: تنفيذ بسيط تحسين المعلمات الخروج وإدارة المخاطر المشي إلى الأمام تحليل الملحق 75 شكرا لكم على اهتمامكم 76 بيوس جان هوم تاجر المالية المستقلة عالم الكمبيوتر ومطوري البرمجيات حزمة كوانسترات المشارك المشارك براين G. بيترسون شريك ومدير تجارة الكمية في دف للتجارة في شيكاغو المؤلف أو كو-أو ثور أكثر من 10 حزم R للتمويل يكتب بانتظام ويتحدث على بناء محفظة والمخاطر 77 الموارد R-فورج r-forge. r-project. orgprojectsblotter R-سيغ-المالية القائمة البريدية stat. ethz. chmailmanlistinfor - سيغ التمويل مدونات جيثب، ستاكوفيرفلو، إلخ. أوس 78 لينك تو سليدس أحدث الشرائح المتوفرة على غوغل دريف هنا: docs. googlepresentationd1fgzdclffcqjkhhzaonspux1ttm1eb5hlvcedsz7zwpub هذه الرسالة سوف تعرض آلية آلية إهلر 8217s جون Ehlers8217s أوتوريلاتيون بيريودوغرام المصممة لإيجاد فترة استرجاعية ديناميكية. وهذا هو، المعلمة الأكثر شيوعا الأمثل في باكتيستس هي فترة الاسترجاع. قبل البدء في هذا المنصب، يجب أن أعطي الائتمان حيث انها 8217s المستحقة، إلى واحد السيد فابريزيو ماكاليني. رئيس مشتقات منظمة في أسواق نوردا في لندن. يمكنك العثور على بقية المستودع فعله للدكتور جون Ehlers8217s دورة تحليلات للتجار على جيثب له. وأنا ممتن وتكريم أن هؤلاء الأفراد ذكاء وذوي الخبرة تساعد على جلب بعض طرق الدكتور Ehlers8217s إلى R. نقطة إهلرز الترابط الذاتي بيريودوغرام هو تعيين حيوي فترة بين الحد الأدنى وطول الفترة القصوى. بينما أترك التفسير الدقيق للميكانيكي لكتاب الدكتور Ehlers8217s، لجميع النوايا العملية والأغراض، في رأيي، و بونكلين من هذا الأسلوب هو محاولة لإزالة مصدر هائل من الإفراط في الحيازة من إنشاء نظام التداول 8211 ناملي تحديد فترة الرجعية. سما من 50 يوما 100 يوم 200 يوم حسنا، هذه الخوارزمية تأخذ هذا الاحتمال من الإفراط في التحميل من يديك. ببساطة، حدد الحد العلوي والسفلي لاسترجاع الخاص بك، وأنه لا بقية. كيف جيدا أنها تفعل ذلك هو موضوع مناقشة لأولئك على دراية جيدة في منهجيات الهندسة الكهربائية (I8217m لا)، لذلك لا تتردد في ترك التعليقات التي تناقش مدى خوارزمية القيام بعملها، وتتردد في بلوق عن ذلك كما حسنا. على أي حال، هنا 8217s رمز خوارزمية الأصلي، من باب المجاملة من السيد ماكاليني: شيء واحد أنا لا لاحظ هو أن هذا الرمز يستخدم حلقة تقول ل (ط 1 في: طول (فيلت))، وهو O (نقاط البيانات) حلقة، والتي أرى كما الطاعون في R. في حين I8217ve تستخدم ركب قبل، كان it8217s فقط لأبسط الحلقات، لذلك هذا هو بالتأكيد المكان حيث يمكن أن تقف خوارزمية إلى تحسين مع رسيب بسبب R8217s المتأصلة الفقراء حلقات. المهتمين في منطق الدقيق من الخوارزمية، مرة أخرى، العثور عليه في جون Ehlers8217s دورة تحليلات لكتاب التجار (انظر الرابط في وقت سابق من هذا المنصب). بطبيعة الحال، فإن أول شيء يجب القيام به هو اختبار مدى الخوارزمية يفعل ما يدعى القيام به، وهو لتملي فترة الاسترجاع من خوارزمية. Let8217s تشغيله على بعض البيانات. الآن، ماذا تبدو فترة الرجعية الخوارزمية مثل Let8217s التكبير في 2001 حتى 2003، عندما ذهبت الأسواق من خلال بعض الاضطرابات. في هذه الصورة المكبرة، يمكننا أن نرى أن تقديرات الخوارزمية 8217s تبدو ثابتة إلى حد ما. Here8217s بعض التعليمات البرمجية لتغذية تقديرات خوارزمية 8217s من ن إلى مؤشر لحساب مؤشر مع فترة الاسترجاع الديناميكي كما تم تعيينها من قبل Ehlers8217s أوتوريلاتيون بيريودوغرام. وهنا هي وظيفة تطبيقها مع سما، لضبط ما بين 120 و 252 يوما. كما رأينا، هذه الخوارزمية أقل اتساقا مما أود، على الأقل عندما يتعلق الأمر باستخدام المتوسط ​​المتحرك البسيط. في الوقت الراهن، I8217m الذهاب إلى ترك هذا الرمز هنا، والسماح الناس تجربة معها. آمل أن يجد شخص ما أن هذا المؤشر مفيد لهم. شكرا للقراءة. ملاحظات: أنا مهتم دائما في نيتوركينغميت المنبثقة في شمال شرق (فيلادلفياك). وعلاوة على ذلك، إذا كنت تعتقد أن شركتك سوف تستفيد من مهاراتي، لا تترددوا في التواصل معي. يمكن العثور على الملف الشخصي لينكدين هنا. وأخيرا، أنا التطوع لتنظيم قسم R للكتب عن الكوموقراطية. إذا كان لديك كتاب حول R التي يمكن أن تنطبق على التمويل، تأكد من اسمحوا لي أن أعرف عن ذلك، حتى أستطيع أن مراجعة ذلك وربما التوصية به. ثاكن لك. هذه المشاركة ستكون مراجعة متعمقة للكتاب ألفا Architect8217s الكم الكمومي. عموما، في رأيي، الكتاب رائع لأولئك الذين الممارسين في إدارة الأموال في الفضاء المساواة الفردية، ولا يزال يحتوي على أفكار تستحق التفكير خارج هذا الفضاء. ومع ذلك، فإن النظام المفصل في الكتاب يستفيد من ترتيب متداخل (رتبة على طول محور X، واتخاذ العشري الأعلى، مرتبة على طول محور Y داخل العشري الأعلى في X، واتخاذ العشري الأعلى على طول المحور Y، وتقييد أساسا اختيار إلى 1 من كون). وعلاوة على ذلك، فإن الكتاب لا تفعل الكثير للتعامل مع الضوابط التقلب، والتي قد عززت النظام الموجز بشكل كبير. قبل أن ندخل في وطأة هذا المنصب، I8217d ترغب في السماح للقراء يعرفون أنني جعلت بلدي المكسرات والمسامير من سلسلة كوانسترات من المشاركات كما داتاكامب بالطبع الرسمي. داتاكامب هو وسيلة رخيصة جدا لتعلم حفنة من R، والتطبيقات المالية هي من بين تلك المواضيع. بلدي بالطبع يغطي أساسيات كوانسترات، وإذا كان أولئك الذين يكملون الدورة مثل ذلك، وأنا قد تخلق بشكل جيد جدا وحدات كوانسترات أكثر تقدما على داتاكامب. I8217m على أمل أن الدورات المالية هي استقبالا حسنا، حيث أن هناك مواضيع مالية في R I8217d ترغب في معرفة نفسي أن محاضرة 45 دقيقة don8217t تكفي حقا ل (مثل الدكتور ديفيد ماتيسون 8217s نقاط التغيير السحر، بورتفوليواناليتيكش، وهلم جرا). في أي حال، هنا 8217s الارتباط. So, let8217s start with a summary of the book: Part 1 is several chapters that are the giant expose - of why momentum works (or at least, has worked for at least 20 years since 1993)8230namely that human biases and irrational behaviors act in certain ways to make the anomaly work. Then there8217s also the career risk (AKA it8217s a risk factor, and so, if your benchmark is SPY and you run across a 3 year period of underperformance, you have severe career risk), and essentially, a whole litany of why a professional asset manager would get fired but if you just stick with the anomaly over many many years and ride out multi-year stretches of relative underperformance, you8217ll come out ahead in the very long run. Generally, I feel like there8217s work to be done if this is the best that can be done, but okay, I8217ll accept it. Essentially, part 1 is for the uninitiated. For those that have been around the momentum block a couple of times, they can skip right past this. Unfortunately, it8217s half the book, so that leaves a little bit of a sour taste in the mouth. Next, part two is where, in my opinion, the real meat and potatoes of the book8211the 8220how8221. Essentially, the algorithm can be boiled down into the following: Taking the universe of large and mid-cap stocks, do the following: 1) Sort the stocks into deciles by 2-12 momentum8211that is, at the end of every month, calculate momentum by last month8217s closing price minus the closing price 12 months ago. Essentially, research states that there8217s a reversion effect on the 1-month momentum. However, this effect doesn8217t carry over into the ETF universe in my experience. 2) Here8217s the interesting part which makes the book worth picking up on its own (in my opinion): after sorting into deciles, rank the top decile by the following metric: multiply the sign of the 2-12 momentum by the following equation: ( negative returns 8211 positive). Essentially, the idea here is to determine smoothness of momentum. That is, in the most extreme situation, imagine a stock that did absolutely nothing for 230 days, and then had one massive day that gave it its entire price appreciation (think Google when it had a 10 jump off of better-than-expected numbers reports), and in the other extreme, a stock that simply had each and every single day be a small positive price appreciation. Obviously, you8217d want the second type of stock. That8217s this idea. Again, sort into deciles, and take the top decile. Therefore, taking the top decile of the top decile leaves you with 1 of the universe. Essentially, this makes the idea very difficult to replicate8211since you8217d need to track down a massive universe of stocks. That stated, I think the expression is actually a pretty good idea as a stand-in for volatility. That is, regardless of how volatile an asset is8211whether it8217s as volatile as a commodity like DBC, or as non-volatile as a fixed-income product like SHY, this expression is an interesting way of stating 8220this path is choppy8221 vs. 8220this path is smooth8221. I might investigate this expression on my blog further in the future. 3) Lastly, if the portfolio is turning over quarterly instead of monthly, the best months to turn it over are the months preceding end-of-quarter month (that is, February, May, August, November) because a bunch of amateur asset managers like to 8220window dress8221 their portfolios. That is, they had a crummy quarter, so at the last month before they have to send out quarterly statements, they load up on some recent winners so that their clients don8217t think they8217re as amateur as they really let on, and there8217s a bump for this. Similarly, January has some selling anomalies due to tax-loss harvesting. As far as practical implementations go, I think this is a very nice touch. Conceding the fact that turning over every month may be a bit too expensive, I like that Wes and Jack say 8220sure, you want to turn it over once every three months, but on which months8221. It8217s a very good question to ask if it means you get an additional percentage point or 150 bps a year from that, as it just might cover the transaction costs and then some. All in all, it8217s a fairly simple to understand strategy. However, the part that sort of gates off the book to a perfect replication is the difficulty in obtaining the CRSP data. However, I do commend Alpha Architect for disclosing the entire algorithm from start to finish. Furthermore, if the basic 2-12 momentum is not enough, there8217s an appendix detailing other types of momentum ideas (earnings momentum, ranking by distance to 52-week highs, absolute historical momentum, and so on). None of these strategies are really that much better than the basic price momentum strategy, so they8217re there for those interested, but it seems there8217s nothing really ground-breaking there. That is, if you8217re trading once a month, there8217s only so many ways of saying 8220hey, I think this thing is going up8221 I also like that Wes and Jack touched on the fact that trend-following, while it doesn8217t improve overall CAGR or Sharpe, does a massive amount to improve on max drawdown. That is, if faced with the prospect of losing 70-80 of everything, and losing only 30, that8217s an easy choice to make. Trend-following is good, even a simplistic version. All in all, I think the book accomplishes what it sets out to do, which is to present a well-researched algorithm. Ultimately, the punchline is on Alpha Architect8217s site (I believe they have some sort of monthly stock filter). Furthermore, the book states that there are better risk-adjusted returns when combined with the algorithm outlined in the 8220quantitative value8221 book. In my experience, I8217ve never had value algorithms impress me in the backtests I8217ve done, but I can chalk that up to me being inexperienced with all the various valuation metrics. My criticism of the book, however, is this: The momentum algorithm in the book misses what I feel is one key component: volatility targeting control. Simply, the paper 8220momentum has its moments8221 (which I covered in my hypothesis-driven development series of posts) essentially states that the usual Fama-French momentum strategy does far better from a risk-reward strategy by deleveraging during times of excessive volatility, and avoiding momentum crashes. I8217m not sure why Wes and Jack didn8217t touch upon this paper, since the implementation is very simple (targetrealized volatility leverage factor). Ideally, I8217d love if Wes or Jack could send me the stream of returns for this strategy (preferably daily, but monthly also works). Essentially, I think this book is very comprehensive. However, I think it also has a somewhat 8220don8217t try this at home8221 feel to it due to the data requirement to replicate it. Certainly, if your broker charges you 8 a transaction, it8217s not a feasible strategy to drop several thousand bucks a year on transaction costs that8217ll just give your returns to your broker. However, I do wonder if the QMOM ETF (from Alpha Architect, of course) is, in fact, a better version of this strategy, outside of the management fee. In any case, my final opinion is this: while this book leaves a little bit of knowledge on the table, on a whole, it accomplishes what it sets out to do, is clear with its procedures, and provides several worthwhile ideas. For the price of a non-technical textbook (aka those 60 books on amazon), this book is a steal. شكرا للقراءة. NOTE: While I am currently employed in a successful analytics capacity, I am interested in hearing about full-time positions more closely related to the topics on this blog. If you have a full-time position which can benefit from my current skills, please let me know. My Linkedin can be found here. This post will be about attempting to use the Depmix package for online state prediction. While the depmix package performs admirably when it comes to describing the states of the past, when used for one-step-ahead prediction, under the assumption that tomorrow8217s state will be identical to today8217s, the hidden markov model process found within the package does not perform to expectations. So, to start off, this post was motivated by Michael Halls-Moore, who recently posted some R code about using the depmixS4 library to use hidden markov models. Generally, I am loath to create posts on topics I don8217t feel I have an absolutely front-to-back understanding of, but I8217m doing this in the hope of learning from others on how to appropriately do online state-space prediction, or 8220regime switching8221 detection, as it may be called in more financial parlance. While I8217ve seen the usual theory of hidden markov models (that is, it can rain or it can be sunny, but you can only infer the weather judging by the clothes you see people wearing outside your window when you wake up), and have worked with toy examples in MOOCs (Udacity8217s self-driving car course deals with them, if I recall correctly8211or maybe it was the AI course), at the end of the day, theory is only as good as how well an implementation can work on real data. For this experiment, I decided to take SPY data since inception, and do a full in-sample 8220backtest8221 on the data. That is, given that the HMM algorithm from depmix sees the whole history of returns, with this 8220god8217s eye8221 view of the data, does the algorithm correctly classify the regimes, if the backtest results are any indication Here8217s the code to do so, inspired by Dr. Halls-Moore8217s. Essentially, while I did select three states, I noted that anything with an intercept above zero is a bull state, and below zero is a bear state, so essentially, it reduces to two states. With the result: So, not particularly terrible. The algorithm works, kind of, sort of, right Well, let8217s try online prediction now. So what I did here was I took an expanding window, starting from 500 days since SPY8217s inception, and kept increasing it, by one day at a time. My prediction, was, trivially enough, the most recent day, using a 1 for a bull state, and a -1 for a bear state. I ran this process in parallel (on a linux cluster, because windows8217s doParallel library seems to not even know that certain packages are loaded, and it8217s more messy), and the first big issue is that this process took about three hours on seven cores for about 23 years of data. Not exactly encouraging, but computing time isn8217t expensive these days. So let8217s see if this process actually works. First, let8217s test if the algorithm does what it8217s actually supposed to do and use one day of look-ahead bias (that is, the algorithm tells us the state at the end of the day8211how correct is it even for that day). With the result: So, allegedly, the algorithm seems to do what it was designed to do, which is to classify a state for a given data set. Now, the most pertinent question: how well do these predictions do even one day ahead You8217d think that state space predictions would be parsimonious from day to day, given the long history, correct With the result: That is, without the lookahead bias, the state space prediction algorithm is atrocious. Why is that Well, here8217s the plot of the states: In short, the online hmm algorithm in the depmix package seems to change its mind very easily, with obvious (negative) implications for actual trading strategies. So, that wraps it up for this post. Essentially, the main message here is this: there8217s a vast difference between loading doing descriptive analysis (AKA 8220where have you been, why did things happen8221) vs. predictive analysis (that is, 8220if I correctly predict the future, I get a positive payoff8221). In my opinion, while descriptive statistics have their purpose in terms of explaining why a strategy may have performed how it did, ultimately, we8217re always looking for better prediction tools. In this case, depmix, at least in this 8220out-of-the-box8221 demonstration does not seem to be the tool for that. If anyone has had success with using depmix (or other regime-switching algorithm in R) for prediction, I would love to see work that details the procedure taken, as it8217s an area I8217m looking to expand my toolbox into, but don8217t have any particular good leads. Essentially, I8217d like to think of this post as me describing my own experiences with the package. شكرا للقراءة. NOTE: On Oct. 5th, I will be in New York City. On Oct. 6th, I will be presenting at The Trading Show on the Programming Wars panel. NOTE: My current analytics contract is up for review at the end of the year, so I am officially looking for other offers as well. If you have a full-time role which may benefit from the skills you see on my blog, please get in touch with me. My linkedin profile can be found here. This post will introduce component conditional value at risk mechanics found in PerformanceAnalytics from a paper written by Brian Peterson, Kris Boudt, and Peter Carl. This is a mechanism that is an easy-to-call mechanism for computing component expected shortfall in asset returns as they apply to a portfolio. While the exact mechanics are fairly complex, the upside is that the running time is nearly instantaneous, and this method is a solid tool for including in asset allocation analysis. For those interested in an in-depth analysis of the intuition of component conditional value at risk, I refer them to the paper written by Brian Peterson, Peter Carl, and Kris Boudt. Essentially, here8217s the idea: all assets in a given portfolio have a marginal contribution to its total conditional value at risk (also known as expected shortfall)8211that is, the expected loss when the loss surpasses a certain threshold. For instance, if you want to know your 5 expected shortfall, then it8217s the average of the worst 5 returns per 100 days, and so on. For returns using daily resolution, the idea of expected shortfall may sound as though there will never be enough data in a sufficiently fast time frame (on one year or less), the formula for expected shortfall in the PerformanceAnalytics defaults to an approximation calculation using a Cornish-Fisher expansion, which delivers very good results so long as the p-value isn8217t too extreme (that is, it works for relatively sane p values such as the 1-10 range). Component Conditional Value at Risk has two uses: first off, given no input weights, it uses an equal weight default, which allows it to provide a risk estimate for each individual asset without burdening the researcher to create his or her own correlationcovariance heuristics. Secondly, when provided with a set of weights, the output changes to reflect the contribution of various assets in proportion to those weights. This means that this methodology works very nicely with strategies that exclude assets based on momentum, but need a weighting scheme for the remaining assets. Furthermore, using this methodology also allows an ex-post analysis of risk contribution to see which instrument contributed what to risk. First, a demonstration of how the mechanism works using the edhec data set. There is no strategy here, just a demonstration of syntax. This will assume an equal-weight contribution from all of the funds in the edhec data set. So tmp is the contribution to expected shortfall from each of the various edhec managers over the entire time period. Here8217s the output: The salient part of this is the percent contribution (the last output). Notice that it can be negative, meaning that certain funds gain when others lose. At least, this was the case over the current data set. These assets diversify a portfolio and actually lower expected shortfall. In this case, I equally weighted the first ten managers in the edhec data set, and put zero weight in the last three. Furthermore, we can see what happens when the weights are not equal. This time, notice that as the weight increased in the convertible arb manager, so too did his contribution to maximum expected shortfall. For a future backtest, I would like to make some data requests. I would like to use the universe found in Faber8217s Global Asset Allocation book. That said, the simulations in that book go back to 1972, and I was wondering if anyone out there has daily returns for those assetsindices. While some ETFs go back into the early 2000s, there are some that start rather late such as DBC (commodities, early 2006), GLD (gold, early 2004), BWX (foreign bonds, late 2007), and FTY (NAREIT, early 2007). As an eight-year backtest would be a bit short, I was wondering if anyone had data with more history. One other thing, I will in New York for the trading show. and speaking on the 8220programming wars8221 panel on October 6th. شكرا للقراءة. NOTE: While I am currently contracting, I am also looking for a permanent position which can benefit from my skills for when my current contract ends. If you have or are aware of such an opening, I will be happy to speak with you. This post will cover a function to simplify creating Harry Long type rebalancing strategies from SeekingAlpha for interested readers. As Harry Long has stated, most, if not all of his strategies are more for demonstrative purposes rather than actual recommended investments. So, since Harry Long has been posting some more articles on Seeknig Alpha, I8217ve had a reader or two ask me to analyze his strategies (again). Instead of doing that, however, I8217ll simply put this tool here, which is a wrapper that automates the acquisition of data and simulates portfolio rebalancing with one line of code. Here8217s the tool. It fetches the data for you (usually from Yahoo, but a big thank you to Mr. Helumth Vollmeier in the case of ZIV and VXX), and has the option of either simply displaying an equity curve and some statistics (CAGR, annualized standard dev, Sharpe, max Drawdown, Calmar), or giving you the return stream as an output if you wish to do more analysis in R. Here8217s an example of simply getting the statistics, with an 80 XLPSPLV (they8217re more or less interchangeable) and 20 TMF (aka 60 TLT, so an 8060 portfolio), from one of Harry Long8217s articles . Nothing out of the ordinary of what we might expect from a balanced equitybonds portfolio. Generally does well, has its largest drawdown in the financial crisis, and some other bumps in the road, but overall, I8217d think a fairly vanilla 8220set it and forget it8221 sort of thing. And here would be the way to get the stream of individual daily returns, assuming you wanted to rebalance these two instruments weekly, instead of yearly (as is the default). And now let8217s get some statistics. Turns out, moving the rebalancing from annually to weekly didn8217t have much of an effect here (besides give a bunch of money to your broker, if you factored in transaction costs, which this doesn8217t). So, that8217s how this tool works. The results, of course, begin from the latest instrument8217s inception. The trick, in my opinion, is to try and find proxy substitutes with longer histories for newer ETFs that are simply leveraged ETFs, such as using a 60 weight in TLT with an 80 weight in XLP instead of a 20 weight in TMF with 80 allocation in SPLV. For instance, here are some proxies: SPXL XLP SPXLUPRO SPY 3 TMF TLT 3 That said, I8217ve worked with Harry Long before, and he develops more sophisticated strategies behind the scenes, so I8217d recommend that SeekingAlpha readers take his publicly released strategies as concept demonstrations, as opposed to fully-fledged investment ideas, and contact Mr. Long himself about more customized, private solutions for investment institutions if you are so interested. شكرا للقراءة. NOTE: I am currently in the northeast. While I am currently contracting, I am interested in networking with individuals or firms with regards to potential collaboration opportunities. This post will demonstrate how to take into account turnover when dealing with returns-based data using PerformanceAnalytics and the Return. Portfolio function in R. It will demonstrate this on a basic strategy on the nine sector SPDRs. So, first off, this is in response to a question posed by one Robert Wages on the R-SIG-Finance mailing list. While there are many individuals out there with a plethora of questions (many of which can be found to be demonstrated on this blog already), occasionally, there will be an industry veteran, a PhD statistics student from Stanford, or other very intelligent individual that will ask a question on a topic that I haven8217t yet touched on this blog, which will prompt a post to demonstrate another technical aspect found in R. This is one of those times. So, this demonstration will be about computing turnover in returns space using the PerformanceAnalytics package. Simply, outside of the PortfolioAnalytics package, PerformanceAnalytics with its Return. Portfolio function is the go-to R package for portfolio management simulations, as it can take a set of weights, a set of returns, and generate a set of portfolio returns for analysis with the rest of PerformanceAnalytics8217s functions. Again, the strategy is this: take the 9 three-letter sector SPDRs (since there are four-letter ETFs now), and at the end of every month, if the adjusted price is above its 200-day moving average, invest into it. Normalize across all invested sectors (that is, 19th if invested into all 9, 100 into 1 if only 1 invested into, 100 cash, denoted with a zero return vector, if no sectors are invested into). It8217s a simple, toy strategy, as the strategy isn8217t the point of the demonstration. Here8217s the basic setup code: So, get the SPDRs, put them together, compute their returns, generate the signal, and create the zero vector, since Return. Portfolio treats weights less than 1 as a withdrawal, and weights above 1 as the addition of more capital (big FYI here). Now, here8217s how to compute turnover: So, the trick is this: when you call Return. portfolio, use the verbose TRUE option. This creates several objects, among them returns, BOP. Weight, and EOP. Weight. These stand for Beginning Of Period Weight, and End Of Period Weight. The way that turnover is computed is simply the difference between how the day8217s return moves the allocated portfolio from its previous ending point to where that portfolio actually stands at the beginning of next period. That is, the end of period weight is the beginning of period drift after taking into account the day8217s driftreturn for that asset. The new beginning of period weight is the end of period weight plus any transacting that would have been done. Thus, in order to find the actual transactions (or turnover), one subtracts the previous end of period weight from the beginning of period weight. This is what such transactions look like for this strategy. Something we can do with such data is take a one-year rolling turnover, accomplished with the following code: It looks like this: This essentially means that one year8217s worth of two-way turnover (that is, if selling an entirely invested portfolio is 100 turnover, and buying an entirely new set of assets is another 100, then two-way turnover is 200) is around 800 at maximum. That may be pretty high for some people. Now, here8217s the application when you penalize transaction costs at 20 basis points per percentage point traded (that is, it costs 20 cents to transact 100). So, at 20 basis points on transaction costs, that takes about one percent in returns per year out of this (admittedly, terrible) strategy. This is far from negligible. So, that is how you actually compute turnover and transaction costs. In this case, the transaction cost model was very simple. However, given that Return. portfolio returns transactions at the individual asset level, one could get as complex as they would like with modeling the transaction costs. شكرا للقراءة. NOTE: I will be giving a lightning talk at RFinance, so for those attending, you8217ll be able to find me there. This post will outline an easy-to-make mistake in writing vectorized backtests8211namely in using a signal obtained at the end of a period to enter (or exit) a position in that same period. The difference in results one obtains is massive. Today, I saw two separate posts from Alpha Architect and Mike Harris both referencing a paper by Valeriy Zakamulin on the fact that some previous trend-following research by Glabadanidis was done with shoddy results, and that Glabadanidis8217s results were only reproducible through instituting lookahead bias. The following code shows how to reproduce this lookahead bias. First, the setup of a basic moving average strategy on the SampP 500 index from as far back as Yahoo data will provide. And here is how to institute the lookahead bias. These are the 8220results8221: Of course, this equity curve is of no use, so here8217s one in log scale. As can be seen, lookahead bias makes a massive difference. Here are the numerical results: Again, absolutely ridiculous. Note that when using Return. Portfolio (the function in PerformanceAnalytics), that package will automatically give you the next period8217s return, instead of the current one, for your weights. However, for those writing 8220simple8221 backtests that can be quickly done using vectorized operations, an off-by-one error can make all the difference between a backtest in the realm of reasonable, and pure nonsense. However, should one wish to test for said nonsense when faced with impossible-to-replicate results, the mechanics demonstrated above are the way to do it. Now, onto other news: I8217d like to thank Gerald M for staying on top of one of the Logical Invest strategies8211namely, their simple global market rotation strategy outlined in an article from an earlier blog post. Up until March 2015 (the date of the blog post), the strategy had performed well. However, after said date It has been a complete disaster, which, in hindsight, was evident when I passed it through the hypothesis-driven development framework process I wrote about earlier. So, while there has been a great deal written about not simply throwing away a strategy because of short-term underperformance, and that anomalies such as momentum and value exist because of career risk due to said short-term underperformance, it8217s never a good thing when a strategy creates historically large losses, particularly after being published in such a humble corner of the quantitative financial world. In any case, this was a post demonstrating some mechanics, and an update on a strategy I blogged about not too long ago. شكرا للقراءة. NOTE: I am always interested in hearing about new opportunities which may benefit from my expertise, and am always happy to network. You can find my LinkedIn profile here . This post will shed light on the values of R2s behind two rather simplistic strategies 8212 the simple 10 month SMA, and its relative, the 10 month momentum (which is simply a difference of SMAs, as Alpha Architect showed in their book DIY Financial Advisor . Not too long ago, a friend of mine named Josh asked me a question regarding R2s in finance. He8217s finishing up his PhD in statistics at Stanford, so when people like that ask me questions, I8217d like to answer them. His assertion is that in some instances, models that have less than perfect predictive power (EG R2s of .4, for instance), can still deliver very promising predictions, and that if someone were to have a financial model that was able to explain 40 of the variance of returns, they could happily retire with that model making them very wealthy. Indeed. 4 is a very optimistic outlook (to put it lightly), as this post will show. In order to illustrate this example, I took two 8220staple8221 strategies 8212 buy SPY when i ts closing monthly price is above its ten month simple moving average, and when its ten month momentum (basically the difference of a ten month moving average and its lag) is positive. While these models are simplistic, they are ubiquitously talked about, and many momentum strategies are an improvement upon these baseline, 8220out-of-the-box8221 strategies. Here8217s the code to do that: And here are the results: In short, the SMA10 and the 10-month momentum (aka ROC 10 aka MOM10) both handily outperform the buy and hold, not only in absolute returns, but especially in risk-adjusted returns (Sharpe and Calmar ratios). Again, simplistic analysis, and many models get much more sophisticated than this, but once again, simple, illustrative example using two strategies that outperform a benchmark (over the long term, anyway). Now, the question is, what was the R2 of these models To answer this, I took a rolling five-year window that essentially asked: how well did these quantities (the ratio between the closing price and the moving average 8211 1, or the ten month momentum) predict the next month8217s returns That is, what proportion of the variance is explained through the monthly returns regressed against the previous month8217s signals in numerical form (perhaps not the best framing, as the signal is binary as opposed to continuous which is what is being regressed, but let8217s set that aside, again, for the sake of illustration). Here8217s the code to generate the answer. And the answer, in pictorial form: In short, even in the best case scenarios, namely, crises which provide momentumtrend-followingcall it what you will its raison d8217etre, that is, its risk management appeal, the proportion of variance explained by the actual signal quantities was very small. In the best of times, around 20. But then again, think about what the R2 value actually is8211it8217s the percentage of variance explained by a predictor. If a small set of signals (let alone one) was able to explain the majority of the change in the returns of the SampP 500, or even a not-insignificant portion, such a person would stand to become very wealthy. More to the point, given that two strategies that handily outperform the market have R2s that are exceptionally low for extended periods of time, it goes to show that holding the R2 up as some form of statistical holy grail certainly is incorrect in the general sense, and anyone who does so either is painting with too broad a brush, is creating disingenuous arguments, or should simply attempt to understand another field which may not work the way their intuition tells them. شكرا للقراءة. This review will review the 8220Adaptive Asset Allocation: Dynamic Global Portfolios to Profit in Good Times 8211 and Bad8221 book by the people at ReSolve Asset Management. Overall, this book is a definite must-read for those who have never been exposed to the ideas within it. However, when it comes to a solution that can be fully replicated, this book is lacking. Okay, it8217s been a while since I reviewed my last book, DIY Financial Advisor. from the awesome people at Alpha Architect. This book in my opinion, is set up in a similar sort of format. This is the structure of the book, and my reviews along with it: Part 1: Why in the heck you actually need to have a diversified portfolio, and why a diversified portfolio is a good thing. In a world in which there is so much emphasis put on single-security performance, this is certainly something that absolutely must be stated for those not familiar with portfolio theory. It highlights the example of two people8211one from Abbott Labs, and one from Enron, who had so much of their savings concentrated in their company8217s stock. Mr. Abbott got hit hard and changed his outlook on how to save for retirement, and Mr. Enron was never heard from again. Long story short: a diversified portfolio is good, and a properly diversified portfolio can offset one asset8217s zigs with another asset8217s zags. This is the key to establishing a stream of returns that will help meet financial goals. Basically, this is your common sense story (humans love being told stories) so as to motivate you to read the rest of the book. It does its job, though for someone like me, it8217s more akin to a big 8220wait for it, wait for it8230and there8217s the reason why we should read on, as expected8221. Part 2: Something not often brought up in many corners of the quant world (because it8217s real life boring stuff) is the importance not only of average returns, but when those returns are achieved. Namely, imagine your everyday saver. At the beginning of their careers, they8217re taking home less salary and have less money in their retirement portfolio (or speculation portfolio, but the book uses retirement portfolio). As they get into middle age and closer to retirement, they have a lot more money in said retirement portfolio. Thus, strong returns are most vital when there is more cash available to the portfolio, and the difference between mediocre returns at the beginning and strong returns at the end of one8217s working life as opposed to vice versa is astronomical and cannot be understated. Furthermore, once in retirement, strong returns in the early years matter far more than returns in the later years once money has been withdrawn out of the portfolio (though I8217d hope that a portfolio8217s returns can be so strong that one can simply 8220live off the interest8221). Or, put more intuitively: when you have 10,000 in your portfolio, a 20 drawdown doesn8217t exactly hurt because you can make more money and put more into your retirement account. But when you8217re 62 and have 500,000 and suddenly lose 30 of everything, well, that8217s massive. How much an investor wants to avoid such a scenario cannot be understated. Warren Buffett once said that if you can8217t bear to lose 50 of everything, you shouldn8217t be in stocks. I really like this part of the book because it shows just how dangerous the ideas of 8220a 50 drawdown is unavoidable8221 and other 8220stay invested for the long haul8221 refrains are. Essentially, this part of the book makes a resounding statement that any financial adviser keeping his or her clients invested in equities when they8217re near retirement age is doing something not very advisable, to put it lightly. In my opinion, those who advise pension funds should especially keep this section of the book in mind, since for some people, the long-term may be coming to an end, and what matters is not only steady returns, but to make sure the strategy doesn8217t fall off a cliff and destroy decades of hard-earned savings. Part 3: This part is also one that is a very important read. First off, it lays out in clear terms that the long-term forward-looking valuations for equities are at rock bottom. That is, the expected forward 15-year returns are very low, using approximately 75 years of evidence. Currently, according to the book, equity valuations imply a negative 15-year forward return. However, one thing I will take issue with is that while forward-looking long-term returns for equities may be very low, if one believed this chart and only invested in the stock market when forecast 15-year returns were above the long term average, one would have missed out on both the 2003-2007 bull runs, and the one since 2009 that8217s just about over. So, while the book makes a strong case for caution, readers should also take the chart with a grain of salt in my opinion. However, another aspect of portfolio construction that this book covers is how to construct a robust (assets for any economic environment) and coherent (asset classes balanced in number) universe for implementation with any asset allocation algorithm. I think this bears repeating: universe selection is an extremely important topic in the discussion of asset allocation, yet there is very little discussion about it. Most researchtopics simply take some 8220conventional universe8221, such as 8220all stocks on the NYSE8221, or 8220all the stocks in the SampP 5008221, or 8220the entire set of the 50-60 most liquid futures8221 without consideration for robustness and coherence. This book is the first source I8217ve seen that actually puts this topic under a magnifying glass besides 8220finger in the air pick and choose8221. Part 4: and here8217s where I level my main criticism at this book. For those that have read 8220Adaptive Asset Allocation: A Primer8221. this section of the book is basically one giant copy and paste. It8217s all one large buildup to 8220momentum rank min-variance optimization8221. All well and good, until there8217s very little detail beyond the basics as to how the minimum variance portfolio was constructed. Namely, what exactly is the minimum variance algorithm in use Is it one of the poor variants susceptible to numerical instability inherent in inverting sample covariance matrices Or is it a heuristic like David Varadi8217s minimum variance and minimum correlation algorithm The one feeling I absolutely could not shake was that this book had a perfect opportunity to present a robust approach to minimum variance, and instead, it8217s long on concept, short on details. While the theory of 8220maximize return for unit risk8221 is all well and good, the actual algorithm to implement that theory into practice is not trivial, with the solutions taught to undergrads and master8217s students having some well-known weaknesses. On top of this, one thing that got hammered into my head in the past was that ranking also had a weakness at the inclusionexclusion point. E. G. if, out of ten assets, the fifth asset had a momentum of say, 10.9, and the sixth asset had a momentum of 10.8, how are we so sure the fifth is so much better And while I realize that this book was ultimately meant to be a primer, in my opinion, it would have been a no-objections five-star if there were an appendix that actually went into some detail on how to go from the simple concepts and included a small numerical example of some algorithms that may address the well-known weaknesses. This doesn8217t mean Greekmathematical jargon. Just an appendix that acknowledged that not every reader is someone only picking up his first or second book about systematic investing, and that some of us are familiar with the 8220whys8221 and are more interested in the 8220hows8221. Furthermore, I8217d really love to know where the authors of this book got their data to back-date some of these ETFs into the 90s. Part 5: some more formal research on topics already covered in the rest of the book8211namely a section about how many independent bets one can take as the number of assets grow, if I remember it correctly. Long story short You easily get the most bang for your buck among disparate asset classes, such as treasuries of various duration, commodities, developed vs. emerging equities, and so on, as opposed to trying to pick among stocks in the same asset class (though there8217s some potential for alpha there8230just8230a lot less than you imagine). So in case the idea of asset class selection, not stock selection wasn8217t beaten into the reader8217s head before this point, this part should do the trick. The other research paper is something I briefly skimmed over which went into more depth about volatility and retirement portfolios, though I felt that the book covered this topic earlier on to a sufficient degree by building up the intuition using very understandable scenarios. So that8217s the review of the book. Overall, it8217s a very solid piece of writing, and as far as establishing the why, it does an absolutely superb job. For those that aren8217t familiar with the concepts in this book, this is definitely a must-read, and ASAP. However, for those familiar with most of the concepts and looking for a detailed 8220how8221 procedure, this book does not deliver as much as I would have liked. And I realize that while it8217s a bad idea to publish secret sauce, I bought this book in the hope of being exposed to a new algorithm presented in the understandable and intuitive language that the rest of the book was written in, and was left wanting. Still, that by no means diminishes the impact of the rest of the book. For those who are more likely to be its target audience, it8217s a 55. For those that wanted some specifics, it still has its gem on universe construction. Overall, I rate it a 45. Thanks for reading. Happy new year. This post will be a quick one covering the relationship between the simple moving average and time series momentum. The implication is that one can potentially derive better time series momentum indicators than the classical one applied in so many papers. Okay, so the main idea for this post is quite simple: I8217m sure we8217re all familiar with classical momentum. That is, the price now compared to the price however long ago (3 months, 10 months, 12 months, etc.). E. G. P(now) 8211 P(10) And I8217m sure everyone is familiar with the simple moving average indicator, as well. E. G. SMA(10). Well, as it turns out, these two quantities are actually related. It turns out, if instead of expressing momentum as the difference of two numbers, it is expressed as the sum of returns, it can be written (for a 10 month momentum) as: MOM10 return of this month return of last month return of 2 months ago 8230 return of 9 months ago, for a total of 10 months in our little example. This can be written as MOM10 (P(0) 8211 P(1)) (P(1) 8211 P(2)) 8230 (P(9) 8211 P(10)). (Each difference within parentheses denotes one month8217s worth of returns.) Which can then be rewritten by associative arithmetic as: (P(0) P(1) 8230 P(9)) 8211 (P(1) P(2) 8230 P(10)). In other words, momentum 8212 aka the difference between two prices, can be rewritten as the difference between two cumulative sums of prices. And what is a simple moving average Simply a cumulative sum of prices divided by however many prices summed over. Here8217s some R code to demonstrate. With the resulting number of times these two signals are equal: In short, every time. Now, what exactly is the punchline of this little example Here8217s the punchline: The simple moving average is8230fairly simplistic as far as filters go. It works as a pedagogical example, but it has some well known weaknesses regarding lag, windowing effects, and so on. Here8217s a toy example how one can get a different momentum signal by changing the filter. With the following results: While the difference of EMA10 strategy didn8217t do better than the difference of SMA10 (aka standard 10-month momentum), that8217s not the point. The point is that the momentum signal is derived from a simple moving average filter, and that by using a different filter, one can still use a momentum type of strategy. Or, put differently, the maingeneral takeaway here is that momentum is the slope of a filter, and one can compute momentum in an infinite number of ways depending on the filter used, and can come up with a myriad of different momentum strategies. شكرا للقراءة. NOTE: I am currently contracting in Chicago, and am always open to networking. Contact me at my email at ilya. kipnisgmail or find me on my LinkedIn here. Post navigation CategoriesCategory Archives: Trading This post will introduce John Ehlers8217s Autocorrelation Periodogram mechanism8211a mechanism designed to dynamically find a lookback period. That is, the most common parameter optimized in backtests is the lookback period. Before beginning this post, I must give credit where it8217s due, to one Mr. Fabrizio Maccallini. the head of structured derivatives at Nordea Markets in London. You can find the rest of the repository he did for Dr. John Ehlers8217s Cycle Analytics for Traders on his github. I am grateful and honored that such intelligent and experienced individuals are helping to bring some of Dr. Ehlers8217s methods into R. The point of the Ehlers Autocorrelation Periodogram is to dynamically set a period between a minimum and a maximum period length. While I leave the exact explanation of the mechanic to Dr. Ehlers8217s book, for all practical intents and purposes, in my opinion, the punchline of this method is to attempt to remove a massive source of overfitting from trading system creation8211namely specifying a lookback period. SMA of 50 days 100 days 200 days Well, this algorithm takes that possibility of overfitting out of your hands. Simply, specify an upper and lower bound for your lookback, and it does the rest. How well it does it is a topic of discussion for those well-versed in the methodologies of electrical engineering (I8217m not), so feel free to leave comments that discuss how well the algorithm does its job, and feel free to blog about it as well. In any case, here8217s the original algorithm code, courtesy of Mr. Maccallini: One thing I do notice is that this code uses a loop that says for(i in 1:length(filt)), which is an O(data points) loop, which I view as the plague in R. While I8217ve used Rcpp before, it8217s been for only the most basic of loops, so this is definitely a place where the algorithm can stand to be improved with Rcpp due to R8217s inherent poor looping. Those interested in the exact logic of the algorithm will, once again, find it in John Ehlers8217s Cycle Analytics For Traders book (see link earlier in the post). Of course, the first thing to do is to test how well the algorithm does what it purports to do, which is to dictate the lookback period of an algorithm. Let8217s run it on some data. Now, what does the algorithm-set lookback period look like Let8217s zoom in on 2001 through 2003, when the markets went through some upheaval. In this zoomed-in image, we can see that the algorithm8217s estimates seem fairly jumpy. Here8217s some code to feed the algorithm8217s estimates of n into an indicator to compute an indicator with a dynamic lookback period as set by Ehlers8217s autocorrelation periodogram. And here is the function applied with an SMA, to tune between 120 and 252 days. As seen, this algorithm is less consistent than I would like, at least when it comes to using a simple moving average. For now, I8217m going to leave this code here, and let people experiment with it. I hope that someone will find that this indicator is helpful to them. شكرا للقراءة. NOTES: I am always interested in networkingmeet-ups in the northeast (PhiladelphiaNYC). Furthermore, if you believe your firm will benefit from my skills, please do not hesitate to reach out to me. My linkedin profile can be found here. Lastly, I am volunteering to curate the R section for books on quantocracy. If you have a book about R that can apply to finance, be sure to let me know about it, so that I can review it and possibly recommend it. Thakn you. This post will be about attempting to use the Depmix package for online state prediction. While the depmix package performs admirably when it comes to describing the states of the past, when used for one-step-ahead prediction, under the assumption that tomorrow8217s state will be identical to today8217s, the hidden markov model process found within the package does not perform to expectations. So, to start off, this post was motivated by Michael Halls-Moore, who recently posted some R code about using the depmixS4 library to use hidden markov models. Generally, I am loath to create posts on topics I don8217t feel I have an absolutely front-to-back understanding of, but I8217m doing this in the hope of learning from others on how to appropriately do online state-space prediction, or 8220regime switching8221 detection, as it may be called in more financial parlance. While I8217ve seen the usual theory of hidden markov models (that is, it can rain or it can be sunny, but you can only infer the weather judging by the clothes you see people wearing outside your window when you wake up), and have worked with toy examples in MOOCs (Udacity8217s self-driving car course deals with them, if I recall correctly8211or maybe it was the AI course), at the end of the day, theory is only as good as how well an implementation can work on real data. For this experiment, I decided to take SPY data since inception, and do a full in-sample 8220backtest8221 on the data. That is, given that the HMM algorithm from depmix sees the whole history of returns, with this 8220god8217s eye8221 view of the data, does the algorithm correctly classify the regimes, if the backtest results are any indication Here8217s the code to do so, inspired by Dr. Halls-Moore8217s. Essentially, while I did select three states, I noted that anything with an intercept above zero is a bull state, and below zero is a bear state, so essentially, it reduces to two states. With the result: So, not particularly terrible. The algorithm works, kind of, sort of, right Well, let8217s try online prediction now. So what I did here was I took an expanding window, starting from 500 days since SPY8217s inception, and kept increasing it, by one day at a time. My prediction, was, trivially enough, the most recent day, using a 1 for a bull state, and a -1 for a bear state. I ran this process in parallel (on a linux cluster, because windows8217s doParallel library seems to not even know that certain packages are loaded, and it8217s more messy), and the first big issue is that this process took about three hours on seven cores for about 23 years of data. Not exactly encouraging, but computing time isn8217t expensive these days. So let8217s see if this process actually works. First, let8217s test if the algorithm does what it8217s actually supposed to do and use one day of look-ahead bias (that is, the algorithm tells us the state at the end of the day8211how correct is it even for that day). With the result: So, allegedly, the algorithm seems to do what it was designed to do, which is to classify a state for a given data set. Now, the most pertinent question: how well do these predictions do even one day ahead You8217d think that state space predictions would be parsimonious from day to day, given the long history, correct With the result: That is, without the lookahead bias, the state space prediction algorithm is atrocious. Why is that Well, here8217s the plot of the states: In short, the online hmm algorithm in the depmix package seems to change its mind very easily, with obvious (negative) implications for actual trading strategies. So, that wraps it up for this post. Essentially, the main message here is this: there8217s a vast difference between loading doing descriptive analysis (AKA 8220where have you been, why did things happen8221) vs. predictive analysis (that is, 8220if I correctly predict the future, I get a positive payoff8221). In my opinion, while descriptive statistics have their purpose in terms of explaining why a strategy may have performed how it did, ultimately, we8217re always looking for better prediction tools. In this case, depmix, at least in this 8220out-of-the-box8221 demonstration does not seem to be the tool for that. If anyone has had success with using depmix (or other regime-switching algorithm in R) for prediction, I would love to see work that details the procedure taken, as it8217s an area I8217m looking to expand my toolbox into, but don8217t have any particular good leads. Essentially, I8217d like to think of this post as me describing my own experiences with the package. شكرا للقراءة. NOTE: On Oct. 5th, I will be in New York City. On Oct. 6th, I will be presenting at The Trading Show on the Programming Wars panel. NOTE: My current analytics contract is up for review at the end of the year, so I am officially looking for other offers as well. If you have a full-time role which may benefit from the skills you see on my blog, please get in touch with me. My linkedin profile can be found here. This post will demonstrate how to take into account turnover when dealing with returns-based data using PerformanceAnalytics and the Return. Portfolio function in R. It will demonstrate this on a basic strategy on the nine sector SPDRs. So, first off, this is in response to a question posed by one Robert Wages on the R-SIG-Finance mailing list. While there are many individuals out there with a plethora of questions (many of which can be found to be demonstrated on this blog already), occasionally, there will be an industry veteran, a PhD statistics student from Stanford, or other very intelligent individual that will ask a question on a topic that I haven8217t yet touched on this blog, which will prompt a post to demonstrate another technical aspect found in R. This is one of those times. So, this demonstration will be about computing turnover in returns space using the PerformanceAnalytics package. Simply, outside of the PortfolioAnalytics package, PerformanceAnalytics with its Return. Portfolio function is the go-to R package for portfolio management simulations, as it can take a set of weights, a set of returns, and generate a set of portfolio returns for analysis with the rest of PerformanceAnalytics8217s functions. Again, the strategy is this: take the 9 three-letter sector SPDRs (since there are four-letter ETFs now), and at the end of every month, if the adjusted price is above its 200-day moving average, invest into it. Normalize across all invested sectors (that is, 19th if invested into all 9, 100 into 1 if only 1 invested into, 100 cash, denoted with a zero return vector, if no sectors are invested into). It8217s a simple, toy strategy, as the strategy isn8217t the point of the demonstration. Here8217s the basic setup code: So, get the SPDRs, put them together, compute their returns, generate the signal, and create the zero vector, since Return. Portfolio treats weights less than 1 as a withdrawal, and weights above 1 as the addition of more capital (big FYI here). Now, here8217s how to compute turnover: So, the trick is this: when you call Return. portfolio, use the verbose TRUE option. This creates several objects, among them returns, BOP. Weight, and EOP. Weight. These stand for Beginning Of Period Weight, and End Of Period Weight. The way that turnover is computed is simply the difference between how the day8217s return moves the allocated portfolio from its previous ending point to where that portfolio actually stands at the beginning of next period. That is, the end of period weight is the beginning of period drift after taking into account the day8217s driftreturn for that asset. The new beginning of period weight is the end of period weight plus any transacting that would have been done. Thus, in order to find the actual transactions (or turnover), one subtracts the previous end of period weight from the beginning of period weight. This is what such transactions look like for this strategy. Something we can do with such data is take a one-year rolling turnover, accomplished with the following code: It looks like this: This essentially means that one year8217s worth of two-way turnover (that is, if selling an entirely invested portfolio is 100 turnover, and buying an entirely new set of assets is another 100, then two-way turnover is 200) is around 800 at maximum. That may be pretty high for some people. Now, here8217s the application when you penalize transaction costs at 20 basis points per percentage point traded (that is, it costs 20 cents to transact 100). So, at 20 basis points on transaction costs, that takes about one percent in returns per year out of this (admittedly, terrible) strategy. This is far from negligible. So, that is how you actually compute turnover and transaction costs. In this case, the transaction cost model was very simple. However, given that Return. portfolio returns transactions at the individual asset level, one could get as complex as they would like with modeling the transaction costs. شكرا للقراءة. NOTE: I will be giving a lightning talk at RFinance, so for those attending, you8217ll be able to find me there. This post will outline an easy-to-make mistake in writing vectorized backtests8211namely in using a signal obtained at the end of a period to enter (or exit) a position in that same period. The difference in results one obtains is massive. Today, I saw two separate posts from Alpha Architect and Mike Harris both referencing a paper by Valeriy Zakamulin on the fact that some previous trend-following research by Glabadanidis was done with shoddy results, and that Glabadanidis8217s results were only reproducible through instituting lookahead bias. The following code shows how to reproduce this lookahead bias. First, the setup of a basic moving average strategy on the SampP 500 index from as far back as Yahoo data will provide. And here is how to institute the lookahead bias. These are the 8220results8221: Of course, this equity curve is of no use, so here8217s one in log scale. As can be seen, lookahead bias makes a massive difference. Here are the numerical results: Again, absolutely ridiculous. Note that when using Return. Portfolio (the function in PerformanceAnalytics), that package will automatically give you the next period8217s return, instead of the current one, for your weights. However, for those writing 8220simple8221 backtests that can be quickly done using vectorized operations, an off-by-one error can make all the difference between a backtest in the realm of reasonable, and pure nonsense. However, should one wish to test for said nonsense when faced with impossible-to-replicate results, the mechanics demonstrated above are the way to do it. Now, onto other news: I8217d like to thank Gerald M for staying on top of one of the Logical Invest strategies8211namely, their simple global market rotation strategy outlined in an article from an earlier blog post. Up until March 2015 (the date of the blog post), the strategy had performed well. However, after said date It has been a complete disaster, which, in hindsight, was evident when I passed it through the hypothesis-driven development framework process I wrote about earlier. So, while there has been a great deal written about not simply throwing away a strategy because of short-term underperformance, and that anomalies such as momentum and value exist because of career risk due to said short-term underperformance, it8217s never a good thing when a strategy creates historically large losses, particularly after being published in such a humble corner of the quantitative financial world. In any case, this was a post demonstrating some mechanics, and an update on a strategy I blogged about not too long ago. شكرا للقراءة. NOTE: I am always interested in hearing about new opportunities which may benefit from my expertise, and am always happy to network. You can find my LinkedIn profile here . Happy new year. This post will be a quick one covering the relationship between the simple moving average and time series momentum. The implication is that one can potentially derive better time series momentum indicators than the classical one applied in so many papers. Okay, so the main idea for this post is quite simple: I8217m sure we8217re all familiar with classical momentum. That is, the price now compared to the price however long ago (3 months, 10 months, 12 months, etc.). E. G. P(now) 8211 P(10) And I8217m sure everyone is familiar with the simple moving average indicator, as well. E. G. SMA(10). Well, as it turns out, these two quantities are actually related. It turns out, if instead of expressing momentum as the difference of two numbers, it is expressed as the sum of returns, it can be written (for a 10 month momentum) as: MOM10 return of this month return of last month return of 2 months ago 8230 return of 9 months ago, for a total of 10 months in our little example. This can be written as MOM10 (P(0) 8211 P(1)) (P(1) 8211 P(2)) 8230 (P(9) 8211 P(10)). (Each difference within parentheses denotes one month8217s worth of returns.) Which can then be rewritten by associative arithmetic as: (P(0) P(1) 8230 P(9)) 8211 (P(1) P(2) 8230 P(10)). In other words, momentum 8212 aka the difference between two prices, can be rewritten as the difference between two cumulative sums of prices. And what is a simple moving average Simply a cumulative sum of prices divided by however many prices summed over. Here8217s some R code to demonstrate. With the resulting number of times these two signals are equal: In short, every time. Now, what exactly is the punchline of this little example Here8217s the punchline: The simple moving average is8230fairly simplistic as far as filters go. It works as a pedagogical example, but it has some well known weaknesses regarding lag, windowing effects, and so on. Here8217s a toy example how one can get a different momentum signal by changing the filter. With the following results: While the difference of EMA10 strategy didn8217t do better than the difference of SMA10 (aka standard 10-month momentum), that8217s not the point. The point is that the momentum signal is derived from a simple moving average filter, and that by using a different filter, one can still use a momentum type of strategy. Or, put differently, the maingeneral takeaway here is that momentum is the slope of a filter, and one can compute momentum in an infinite number of ways depending on the filter used, and can come up with a myriad of different momentum strategies. شكرا للقراءة. NOTE: I am currently contracting in Chicago, and am always open to networking. Contact me at my email at ilya. kipnisgmail or find me on my LinkedIn here. This post will outline a first failed attempt at applying the ensemble filter methodology to try and come up with a weighting process on SPY that should theoretically be a gradual process to shift from conviction between a bull market, a bear market, and anywhere in between. This is a follow-up post to this blog post. So, my thinking went like this: in a bull market, as one transitions from responsiveness to smoothness, responsive filters should be higher than smooth filters, and vice versa, as there8217s generally a trade-off between the two. In fact, in my particular formulation, the quantity of the square root of the EMA of squared returns punishes any deviation from a flat line altogether (although inspired by Basel8217s measure of volatility, which is the square root of the 18-day EMA of squared returns), while the responsiveness quantity punishes any deviation from the time series of the realized prices. Whether these are the two best measures of smoothness and responsiveness is a topic I8217d certainly appreciate feedback on. In any case, an idea I had on the top of my head was that in addition to having a way of weighing multiple filters by their responsiveness (deviation from price action) and smoothness (deviation from a flat line), that by taking the sums of the sign of the difference between one filter and its neighbor on the responsiveness to smoothness spectrum, provided enough ensemble filters (say, 101, so there are 100 differences), one would obtain a way to move from full conviction of a bull market, to a bear market, to anything in between, and have this be a smooth process that doesn8217t have schizophrenic swings of conviction. Here8217s the code to do this on SPY from inception to 2003: And here8217s the very underwhelming result: Essentially, while I expected to see changes in conviction of maybe 20 at most, instead, my indicator of sum of sign differences did exactly as I had hoped it wouldn8217t, which is to be a very binary sort of mechanic. My intuition was that between an 8220obvious bull market8221 and an 8220obvious bear market8221 that some differences would be positive, some negative, and that they8217d net each other out, and the conviction would be zero. Furthermore, that while any individual crossover is binary, all one hundred signs being either positive or negative would be a more gradual process. Apparently, this was not the case. To continue this train of thought later, one thing to try would be an all-pairs sign difference. Certainly, I don8217t feel like giving up on this idea at this point, and, as usual, feedback would always be appreciated. شكرا للقراءة. NOTE: I am currently consulting in an analytics capacity in downtown Chicago. However, I am also looking for collaborators that wish to pursue interesting trading ideas. If you feel my skills may be of help to you, let8217s talk. You can email me at ilya. kipnisgmail, or find me on my LinkedIn here . This review will be about Inovance Tech8217s TRAIDE system. It is an application geared towards letting retail investors apply proprietary machine learning algorithms to assist them in creating systematic trading strategies. Currently, my one-line review is that while I hope the company founders mean well, the application is still in an early stage, and so, should be checked out by potential usersventure capitalists as something with proof of potential, rather than a finished product ready for mass market. While this acts as a review, it8217s also my thoughts as to how Inovance Tech can improve its product. A bit of background: I have spoken several times to some of the company8217s founders, who sound like individuals at about my age level (so, fellow millennials). Ultimately, the selling point is this: Systematic trading is cool. Machine learning is cool. Therefore, applying machine learning to systematic trading is awesome (And a surefire way to make profits, as Renaissance Technologies has shown.) While this may sound a bit snarky, it8217s also, in some ways, true. Machine learning has become the talk of the town, from IBM8217s Watson (RenTec itself hired a bunch of speech recognition experts from IBM a couple of decades back), to Stanford8217s self-driving car (invented by Sebastian Thrun, who now heads Udacity), to the Netflix prize, to god knows what Andrew Ng is doing with deep learning at Baidu. Considering how well machine learning has done at much more complex tasks than 8220create a half-decent systematic trading algorithm8221, it shouldn8217t be too much to ask this powerful field at the intersection of computer science and statistics to help the retail investor glued to watching charts generate a lot more return on his or her investments than through discretionary chart-watching and noise trading. To my understanding from conversations with Inovance Tech8217s founders, this is explicitly their mission. However, I am not sure that Inovance8217s TRAIDE application actually accomplishes this mission in its current state. Here8217s how it works: Users select one asset at a time, and select a date range (data going back to Dec. 31, 2009). Assets are currently limited to highly liquid currency pairs, and can take the following settings: 1 hour, 2 hour, 4 hour, 6 hour, or daily bar time frames. Users then select from a variety of indicators, ranging from technical (moving averages, oscillators, volume calculations, etc. Mostly an assortment of 20th century indicators, though the occasional adaptive moving average has managed to sneak in8211namely KAMA8211see my DSTrading package, and MAMA8211aka the Mesa Adaptive Moving Average, from John Ehlers) to more esoteric ones such as some sentiment indicators. Here8217s where things start to head south for me, however. Namely, that while it8217s easy to add as many indicators as a user would like, there is basically no documentation on any of them, with no links to reference, etc. so users will have to bear the onus of actually understanding what each and every one of the indicators they select actually does, and whether or not those indicators are useful. The TRAIDE application makes zero effort (thus far) to actually get users acquainted with the purpose of these indicators, what their theoretical objective is (measure conviction in a trend, detect a trend, oscillator type indicator, etc.) Furthermore, regarding indicator selections, users also specify one parameter setting for each indicator per strategy. E. G. if I had an EMA crossover, I8217d have to create a new strategy for a 20100 crossover, a 21100 crossover, rather than specifying something like this: short EMA: 20-60 long EMA: 80-200 Quantstrat itself has this functionality, and while I don8217t recall covering parameter robustness checksoptimization (in other words, testing multiple parameter sets8211whether one uses them for optimization or robustness is up to the user, not the functionality) in quantstrat on this blog specifically, this information very much exists in what I deem 8220the official quantstrat manual8221, found here. In my opinion, the option of covering a range of values is mandatory so as to demonstrate that any given parameter setting is not a random fluke. Outside of quantstrat, I have demonstrated this methodology in my Hypothesis Driven Development posts, and in coming up for parameter selection for volatility trading. Where TRAIDE may do something interesting, however, is that after the user specifies his indicators and parameters, its 8220proprietary machine learning8221 algorithms (WARNING: COMPLETELY BLACK BOX) determine for what range of values of the indicators in question generated the best results within the backtest, and assign them bullishness and bearishness scores. In other words, 8220looking backwards, these were the indicator values that did best over the course of the sample8221. While there is definite value to exploring the relationships between indicators and future returns, I think that TRAIDE needs to do more in this area, such as reporting P-values, conviction, and so on. For instance, if you combine enough indicators, your 8220rule8221 is a market order that8217s simply the intersection of all of the ranges of your indicators. For instance, TRAIDE may tell a user that the strongest bullish signal when the difference of the moving averages is between 1 and 2, the ADX is between 20 and 25, the ATR is between 0.5 and 1, and so on. Each setting the user selects further narrows down the number of trades the simulation makes. In my opinion, there are more ways to explore the interplay of indicators than simply one giant AND statement, such as an 8220OR8221 statement, of some sort. (E. G. select all values, put on a trade when 3 out of 5 indicators fall into the selected bullish range in order to place more trades). While it may be wise to filter down trades to very rare instances if trading a massive amount of instruments, such that of several thousand possible instruments, only several are trading at any given time, with TRAIDE, a user selects only one asset class (currently, one currency pair) at a time, so I8217m hoping to see TRAIDE create more functionality in terms of what constitutes a trading rule. After the user selects both a long and a short rule (by simply filtering on indicator ranges that TRAIDE8217s machine learning algorithms have said are good), TRAIDE turns that into a backtest with a long equity curve, short equity curve, total equity curve, and trade statistics for aggregate, long, and short trades. For instance, in quantstrat, one only receives aggregate trade statistics. Whether long or short, all that matters to quantstrat is whether or not the trade made or lost money. For sophisticated users, it8217s trivial enough to turn one set of rules on or off, but TRAIDE does more to hold the user8217s hand in that regard. Lastly, TRAIDE then generates MetaTrader4 code for a user to download. And that8217s the process. In my opinion, while what Inovance Tech has set out to do with TRAIDE is interesting, I wouldn8217t recommend it in its current state. For sophisticated individuals that know how to go through a proper research process, TRAIDE is too stringent in terms of parameter settings (one at a time), pre-coded indicators (its target audience probably can8217t program too well), and asset classes (again, one at a time). However, for retail investors, my issue with TRAIDE is this: There is a whole assortment of undocumented indicators, which then move to black-box machine learning algorithms. The result is that the user has very little understanding of what the underlying algorithms actually do, and why the logic he or she is presented with is the output. While TRAIDE makes it trivially easy to generate any one given trading system, as multiple individuals have stated in slightly different ways before, writing a strategy is the easy part. Doing the work to understand if that strategy actually has an edge is much harder. Namely, checking its robustness, its predictive power, its sensitivity to various regimes, and so on. Given TRAIDE8217s rather short data history (2010 onwards), and coupled with the opaqueness that the user operates under, my analogy would be this: It8217s like giving an inexperienced driver the keys to a sports car in a thick fog on a winding road. Nobody disputes that a sports car is awesome. However, the true burden of the work lies in making sure that the user doesn8217t wind up smashing into a tree. Overall, I like the TRAIDE application8217s mission, and I think it may have potential as something for the retail investors that don8217t intend to learn the ins-and-outs of coding a trading system in R (despite me demonstrating many times over how to put such systems together). I just think that there needs to be more work put into making sure that the results a user sees are indicative of an edge, rather than open the possibility of highly-flexible machine learning algorithms chasing ghosts in one of the noisiest and most dynamic data sets one can possibly find. My recommendations are these: 1) Multiple asset classes 2) Allow parameter ranges, and cap the number of trials at any given point (E. G. 4 indicators with ten settings each 10,000 possible trading systems blow up the servers). To narrow down the number of trial runs, use techniques from experimental design to arrive at decent combinations. (I wish I remembered my response surface methodology techniques from my master8217s degree about now) 3) Allow modifications of order sizing (E. G. volatility targeting, stop losses), such as I wrote about in my hypothesis-driven development posts. 4) Provide some sort of documentation for the indicators, even if it8217s as simple as a link to investopedia (preferably a lot more). 5) Far more output is necessary, especially for users who don8217t program. Namely, to distinguish whether or not there is a legitimate edge, or if there are too few observations to reject the null hypothesis of random noise. 6) Far longer data histories. 2010 onwards just seems too short of a time-frame to be sure of a strategy8217s efficacy, at least on daily data (may not be true for hourly). 7) Factor in transaction costs. Trading on an hourly time frame will mean far less PampL per trade than on a daily resolution. If MT4 charges a fixed ticket price, users need to know how this factors into their strategy. 8) Lastly, dogfooding. When I spoke last time with Inovance Tech8217s founders, they claimed they were using their own algorithms to create a forex strategy, which was doing well in live trading. By the time more of these suggestions are implemented, it8217d be interesting to see if they have a track record as a fund, in addition to as a software provider. If all of these things are accounted for and automated, the product will hopefully accomplish its mission of bringing systematic trading and machine learning to more people. I think TRAIDE has potential, and I8217m hoping that its staff will realize that potential. شكرا للقراءة. NOTE: I am currently contracting in downtown Chicago, and am always interested in networking with professionals in the systematic trading and systematic asset managementallocation spaces. Find my LinkedIn here. EDIT: Today in my email (Dec. 3, 2015), I received a notice that Inovance was making TRAIDE completely free. Perhaps they want a bunch more feedback on it This post will demonstrate a method to create an ensemble filter based on a trade-off between smoothness and responsiveness, two properties looked for in a filter. An ideal filter would both be responsive to price action so as to not hold incorrect positions, while also be smooth, so as to not incur false signals and unnecessary transaction costs. So, ever since my volatility trading strategy, using three very naive filters (all SMAs) completely missed a 27 month in XIV. I8217ve decided to try and improve ways to create better indicators in trend following. Now, under the realization that there can potentially be tons of complex filters in existence, I decided instead to focus on a way to create ensemble filters, by using an analogy from statisticsmachine learning. In static data analysis, for a regression or classification task, there is a trade-off between bias and variance. In a nutshell, variance is bad because of the possibility of overfitting on a few irregular observations, and bias is bad because of the possibility of underfitting legitimate data. Similarly, with filtering time series, there are similar concerns, except bias is called lag, and variance can be thought of as a 8220whipsawing8221 indicator. Essentially, an ideal indicator would move quickly with the data, while at the same time, not possess a myriad of small bumps-and-reverses along the way, which may send false signals to a trading strategy. So, here8217s how my simple algorithm works: The inputs to the function are the following: A) The time series of the data you8217re trying to filter B) A collection of candidate filters C) A period over which to measure smoothness and responsiveness, defined as the square root of the n-day EMA (2(n1) convention) of the following: a) Responsiveness: the squared quantity of pricefilter 8211 1 b) Smoothness: the squared quantity of filter(t)filter(t-1) 8211 1 (aka R8217s return. calculate) function D) A conviction factor, to which power the errors will be raised. This should probably be between .5 and 3 E) A vector that defines the emphasis on smoothness (vs. emphasis on responsiveness), which should range from 0 to 1. Here8217s the code: This gets SPY data, and creates two utility functions8211xtsApply, which is simply a column-based apply that replaces the original index that using a column-wise apply discards, and sumIsNa, which I use later for counting the numbers of NAs in a given row. It also creates my candidate filters, which, to keep things simple, are just SMAs 2-250. Here8217s the actual code of the function, with comments in the code itself to better explain the process from a technical level (for those still unfamiliar with R, look for the hashtags): The vast majority of the computational time takes place in the two xtsApply calls. On 249 different simple moving averages, the process takes about 30 seconds. Here8217s the output, using a conviction factor of 2: And here is an example, looking at SPY from 2007 through 2011. In this case, I chose to go from blue to green, orange, brown, maroon, purple, and finally red for smoothness emphasis of 0, 5, 25, 50, 75, 95, and 1, respectively. Notice that the blue line is very wiggly, while the red line sometimes barely moves, such as during the 2011 drop-off. One thing that I noticed in the course of putting this process together is something that eluded me earlier8211namely, that naive trend-following strategies which are either fully long or fully short based on a crossover signal can lose money quickly in sideways markets. However, theoretically, by finely varying the jumps between 0 to 100 emphasis on smoothness, whether in steps of 1 or finer, one can have a sort of 8220continuous8221 conviction, by simply adding up the signs of differences between various ensemble filters. In an 8220uptrend8221, the difference as one moves from the most responsive to most smooth filter should constantly be positive, and vice versa. In the interest of brevity, this post doesn8217t even have a trading strategy attached to it. However, an implied trading strategy can be to be long or short the SPY depending on the sum of signs of the differences in filters as you move from responsiveness to smoothness. Of course, as the candidate filters are all SMAs, it probably wouldn8217t be particularly spectacular. However, for those out there who use more complex filters, this may be a way to create ensembles out of various candidate filters, and create even better filters. Furthermore, I hope that given enough candidate filters and an objective way of selecting them, it would be possible to reduce the chances of creating an overfit trading system. However, anything with parameters can potentially be overfit, so that may be wishful thinking. All in all, this is still a new idea for me. For instance, the filter to compute the error terms can probably be improved. The inspiration for an EMA 20 essentially came from how Basel computes volatility (if I recall, correctly, it uses the square root of an 18 day EMA of squared returns), and the very fact that I use an EMA can itself be improved upon (why an EMA instead of some other, more complex filter). In fact, I8217m always open to how I can improve this concept (and others) from readers. شكرا للقراءة. NOTE: I am currently contracting in Chicago in an analytics capacity. If anyone would like to meet up, let me know. You can email me at ilya. kipnisgmail, or contact me through my LinkedIn here. This post will deal with a quick, finger in the air way of seeing how well a strategy scales8211namely, how sensitive it is to latency between signal and execution, using a simple volatility trading strategy as an example. The signal will be the VIXVXV ratio trading VXX and XIV, an idea I got from Volatility Made Simple8217s amazing blog. particularly this post. The three signals compared will be the 8220magical thinking8221 signal (observe the close, buy the close, named from the ruleOrderProc setting in quantstrat), buy on next-day open, and buy on next-day close. Let8217s get started. So here8217s the run-through. In addition to the magical thinking strategy (observe the close, buy that same close), I tested three other variants8211a variant which transacts the next open, a variant which transacts the next close, and the average of those two. Effectively, I feel these three could give a sense of a strategy8217s performance under more realistic conditions8211that is, how well does the strategy perform if transacted throughout the day, assuming you8217re managing a sum of money too large to just plow into the market in the closing minutes (and if you hope to get rich off of trading, you will have a larger sum of money than the amount you can apply magical thinking to). Ideally, I8217d use VWAP pricing, but as that8217s not available for free anywhere I know of, that means that readers can8217t replicate it even if I had such data. In any case, here are the results. Log scale (for Mr. Tony Cooper and others): My reaction The execute on next day8217s close performance being vastly lower than the other configurations (and that deterioration occurring in the most recent years) essentially means that the fills will have to come pretty quickly at the beginning of the day. While the strategy seems somewhat scalable through the lens of this finger-in-the-air technique, in my opinion, if the first full day of possible execution after signal reception will tank a strategy from a 1.44 Calmar to a .92, that8217s a massive drop-off, after holding everything else constant. In my opinion, I think this is quite a valid question to ask anyone who simply sells signals, as opposed to manages assets. Namely, how sensitive are the signals to execution on the next day After all, unless those signals come at 3:55 PM, one is most likely going to be getting filled the next day. Now, while this strategy is a bit of a tomato can in terms of how good volatility trading strategies can get (they can get a lot better in my opinion), I think it made for a simple little demonstration of this technique. Again, a huge thank you to Mr. Helmuth Vollmeier for so kindly keeping up his dropbox all this time for the volatility data Thanks for reading. NOTE: I am currently contracting in a data science capacity in Chicago. You can email me at ilya. kipnisgmail, or find me on my LinkedIn here. I8217m always open to beers after work if you8217re in the Chicago area. NOTE 2: Today, on October 21, 2015, if you8217re in Chicago, there8217s a Chicago R Users Group conference at Jaks Tap at 6:00 PM. Free pizza, networking, and R, hosted by Paul Teetor, who8217s a finance guy. Hope to see you there. This post deals with an impossible-to-implement statistical arbitrage strategy using VXX and XIV. The strategy is simple: if the average daily return of VXX and XIV was positive, short both of them at the close. This strategy makes two assumptions of varying dubiousness: that one can 8220observe the close and act on the close8221, and that one can short VXX and XIV. So, recently, I decided to play around with everyone8217s two favorite instruments on this blog8211VXX and XIV, with the idea that 8220hey, these two instruments are diametrically opposed, so shouldn8217t there be a stat-arb trade here8221 So, in order to do a lick-finger-in-the-air visualization, I implemented Mike Harris8217s momersion indicator . And then I ran the spread through it. In other words, this spread is certainly mean-reverting at just about all times. And here is the code for the results from 2011 onward, from when the XIV and VXX actually started trading. Here are the equity curves: With the following statistics: In other words, the short side is absolutely amazing as a trade8211except for the one small fact of having it be impossible to actually execute, or at least as far as I8217m aware. Anyhow, this was simply a for-fun post, but hopefully it served some purpose. شكرا للقراءة. NOTE: I am currently contracting and am looking to network in the Chicago area. You can find my LinkedIn here. Post navigation Categories

No comments:

Post a Comment