Thursday, 8 March 2018

تعلم الآلة في استراتيجيات التداول


تعلم الآلة لدورة التداول.


نظرة عامة.


يقدم هذا المساق للطلاب تحديات العالم الحقيقي لتنفيذ استراتيجيات التعلم القائم على التعلم الآلي بما في ذلك الخطوات الحسابية من جمع المعلومات لأوامر السوق. وينصب التركيز على كيفية تطبيق نهج التعلم الآلي الاحتمالية لقرارات التداول. نحن نعتبر النهج الإحصائية مثل الانحدار الخطي، Q - التعلم، كن والأشجار الانحدار وكيفية تطبيقها على حالات تداول الأسهم الفعلية.


وتتكون هذه الدورة من ثلاث دورات مصغرة:


مجموعة من الملاحظات بالطبع ورمز المثال يمكن العثور عليها هنا: [[1]]


محتوى الفيديو.


محتوى الفيديو لهذه الدورة متاح مجانا في [أوداسيتي].


ملاحظة مهمة.


هذا بالطبع يصعد في صعوبة نحو النهاية. والمشاريع في الدورة النهائية من الدورة التدريبية الثالثة تمثل تحديات. كن مستعدا.


معلومات المعلم.


أستاذ، الحوسبة التفاعلية في جورجيا تيش.


كس 7646 بالطبع مصمم.


كس 7646 مدرس: ربيع 2018، خريف 2018، ربيع 2017، صيف 2017 (عبر الإنترنت)، خريف 2017.


باحث علمي، مركز تكنولوجيا الوسائط التفاعلية في جورجيا تيش.


كس 7646 معلم: صيف 2018، صيف 2017 (في الحرم الجامعي)


كس 7646 هيد تا: ربيع 2018، خريف 2018، خريف 2017.


المناهج والجدول الزمني لفصول دراسية محددة.


الكتب المدرسية، البرامج & أمب؛ مصادر أخرى.


سنستخدم الكتب المدرسية التالية:


فور ميني-كورس 1: بيثون للتمويل من قبل إيف هيلبيشش أمازون (اختياري) ل ميني-كورس 2: ما التحوط الأموال حقا القيام به من قبل روميرو و بالش الأمازون (مطلوب) ل ميني-كورس 3: التعلم الآلي بواسطة توم ميتشل (اختياري) شراء فإنه ل 218،00 $ في: الأمازون شراء نسخة غلاف ورقي ل 61،78 $. تحذيرات هامة: 1) أنها السفينة فقط إلى الولايات المتحدة 2) يستغرق منهم 3 أسابيع لطباعة الكتاب. إذا كنت من أجل من خارج الولايات المتحدة أنها سوف تقبل بهدوء أموالك ولكن أبدا السفينة الكتاب: نسخة أقل تكلفة في مكغراو هيل شراء نسخة غلاف دولي لل 19.10 $. لست متأكدا من موثوقية هذه الشركة: إنترناشونال.


ملاحظات الدورة التي وضعتها أوكتافيان بلاغا [docs. google] وثائق الباندا: [pandas. pydata] ديفيد بيرد الشرائح على كيفية متجه أساليب التحليل الفني: وسائل الإعلام: CDB_vectorize_me. pptx.


المتطلبات الأساسية / المشارك الشروط.


جميع أنواع الطلاب هي موضع ترحيب! قد تكون موضوعات التعلم الآلي "مراجعة" لطلاب كس، في حين أن أجزاء التمويل سوف تكون مراجعة لطلبة التمويل. ومع ذلك، حتى لو كان لديك خبرة في هذه الموضوعات، وسوف تجد أن نعتبرها بطريقة مختلفة مما كنت قد رأيت من قبل، وخاصة مع النظر نحو تنفيذ للتداول.


إذا أجبت ب "لا" على الأسئلة التالية، قد يكون من المفيد تحديث معرفتك بالمواد الأساسية قبل أخذ كس 7646:


هل لديك معرفة عملية بالإحصاءات الأساسية، بما في ذلك التوزيعات الاحتمالية (مثل العادي والموحد) والحساب والاختلافات بين المتوسط ​​والمتوسط ​​والوضع هل تفهم الفرق بين المتوسط ​​الهندسي والمتوسط ​​الحسابي؟ هل لديك مهارات برمجة قوية؟ خذ هذا الاختبار كومبينستي-prog - مسابقة إذا كنت ترغب في مساعدة تحديد قوة مهارات البرمجة الخاصة بك. هل أنت المختصة مع سطر الأوامر أونيكس؟


من هو هذا بالطبع ل: ويهدف الدورة للأشخاص الذين لديهم خبرة قوية في مجال البرمجة والبرمجيات والمعرفة المستوى التمهيدي من ممارسة الاستثمار. شرط أساسي هو الاهتمام والإثارة حول سوق الأسهم.


البرامج التي سوف نستخدمها: من أجل استكمال مهام البرمجة سوف تحتاج إلى بيئة تطوير كنت مرتاحا مع. نحن نستخدم أونيكس، ولكن يمكنك أيضا العمل مع بيئات ويندوز وماك أوس. يجب تحميل وتثبيت مجموعة من وحدات بايثون إلى جهاز الكمبيوتر الخاص بك (بما في ذلك نومبي، سسيبي، والباندا).


أومزكس: سوف نستخدم أوداسيتي لأشرطة الفيديو المحاضرة. تسجيل الدخول هنا باستخدام حساب غ الخاص بك: غ-أوداسيتي تسجيل الدخول (فيديو التعليمات)


ملاحظة: لا تقم بتسجيل الدخول باستخدام حساب أوداسيتي الشخصية، في حال كان لديك واحدة. الذهاب إلى الدورة على أوداسيتي (أو التنقل من خلال دوراتي): أوديسيتي / بالطبع / المشاهد #! / c - ud501 إذا كان لديك مشكلة في الوصول إلى محتوى أوداسيتي، يرجى حصة مشكلتك عبر البريد الإلكتروني مع دعم غتيش-أوداسيتي سوف نستخدم T - Square لجميع الطلبات: T - ساحة (اختيار موقع الدورة المناسبة) سوف نستخدم ساحة أو رديت للتفاعل والمناقشة. راجع صفحة الفصل الدراسي الحالي للرابط.


A: 90.0٪ وأعلی B: 80.0٪ وأعلی C: 70.0٪ وأعلی D: 60.0٪ وأعلی F: أقل من 60.0٪


الطلاب الذين يأخذون بالطبع تمرير / فشل يجب أن تكسب ما لا يقل عن 75٪ لتمرير.


نحن لا نشجع الطلاب "مراجعة الحسابات". إذا كنت في الدورة على حالة التدقيق، يجب أن تكسب على الأقل "ب" على منتصف المدة.


انظر منهج الفصل الدراسي لأوزان التعيين.


الحد الأدنى من المتطلبات التقنية.


المتصفح وسرعة الاتصال: يوصى بشدة بإصدار محدث من كروم أو فيريفوكس. كما أننا ندعم إنترنيت إكسبلورر 9 وإصدارات سطح المكتب من إنترنيت إكسبلورر 10 والإصدارات الأحدث (وليس إصدارات المترو). 2+ ميغابت في الثانية الموصى بها. على الأقل 0.768 ميغابت في الثانية سرعة التحميل. الأجهزة: جهاز كمبيوتر مع 4 غيغابايت على الأقل من ذاكرة الوصول العشوائي وسرعة وحدة المعالجة المركزية 2.5 غيغاهرتز على الأقل. من أجل تطوير التعليمات البرمجية والاختبار، سوف تعمل هذه التشكيلات الثلاثة بيسي: ويندوز زب أو أعلى مع أحدث التحديثات المثبتة ماك: أوس X 10.6 أو أعلى مع أحدث التحديثات المثبتة لينكس: أي التوزيع الأخير الذي يحتوي على المتصفحات المعتمدة تثبيت لإجراء اختبار على الانترنت (بروكتورراك) سوف تحتاج إلى واحد من: بيسي: ويندوز زب أو أعلى مع أحدث التحديثات المثبتة ماك: أوس X 10.6 أو أعلى مع أحدث التحديثات المثبتة لينكس غير معتمد.


ساعات العمل.


يتم تحديدها.


سرقة أدبية.


في معظم الحالات أتوقع أن يتم كتابة جميع التعليمات البرمجية المقدمة من قبلك. وسوف أقدم بعض المكتبات في الصف الذي يسمح لك لاستخدام (مثل الباندا و نومبي). خلاف ذلك، يجب أن تكون قد قمت بإنشاء كل شفرة المصدر والصور والكتابة المنبثقة التي تقدمها أنت وحدك.


تعلم الآلة للتجارة.


الذكاء الاصطناعي (منظمة العفو الدولية) وآلة التعلم (مل) هي ثورة بهدوء تقريبا جميع مجالات حياتنا. هل تعلم أن أحدث خوارزميات التداول تستخدم هذه التقنيات على نطاق واسع؟


قد يفاجأ أن تعلم أن صناديق التحوط التعلم الآلي تفوق بالفعل بشكل كبير صناديق التحوط المعمم، فضلا عن الأموال الكمية التقليدية، وفقا لتقرير فاليوالك. يمكن أن تكون أنظمة مل والذكاء الاصطناعي أدوات مفيدة بشكل لا يصدق للبشر التنقل في عملية صنع القرار المعنية مع الاستثمارات وتقييم المخاطر.


غالبا ما يكون تأثير العواطف البشرية على قرارات التداول أكبر عائق أمام التفوق في الأداء. الخوارزميات وأجهزة الكمبيوتر اتخاذ القرارات وتنفيذ الصفقات أسرع من أي إنسان يمكن، والقيام بذلك خالية من تأثير العواطف.


هناك العديد من أنواع مختلفة من التداول الخوارزمية. وفيما يلي بعض الأمثلة:


خوارزميات تنفيذ التجارة، والتي تفكك الصفقات إلى أوامر أصغر لتقليل التأثير على سعر السهم. ومن الأمثلة على ذلك استراتيجية متوسط ​​السعر المرجح (فواب) استراتيجية تنفيذ الخوارزميات التي تجعل الصفقات بناء على إشارات من بيانات السوق في الوقت الحقيقي. ومن الأمثلة على ذلك الاستراتيجيات القائمة على الاتجاهات التي تنطوي على المتوسطات المتحركة، وكسر القنوات، وحركات مستوى الأسعار والمؤشرات الفنية الأخرى. الخوارزميات الشبح / الألعاب التي تهدف إلى الكشف والاستفادة من تحركات الأسعار الناجمة عن الصفقات الكبيرة و / أو استراتيجيات خوارزمية أخرى. فرص المراجحة. على سبيل المثال، حيث يمكن أن يتداول السهم في سوقين منفصلين لسعرين مختلفين ويمكن التقاط الفرق في السعر عن طريق بيع المخزون الأعلى سعرا وشراء الأسهم الأقل سعرا.


عندما طرحت استراتيجيات التداول الخوارزمية لأول مرة، كانت مربحة بعنف وسرعان ما اكتسبت حصتها في السوق. في مايو 2017، قالت شركة أبحاث سوق رأس المال تب المجموعة أن التداول عالية التردد (هفت) شكلت 52٪ من متوسط ​​حجم التداول اليومي. ولكن مع ازدياد المنافسة، انخفضت الأرباح. في هذه البيئة الصعبة على نحو متزايد، يحتاج التجار إلى أداة جديدة لمنحهم ميزة تنافسية وزيادة الأرباح. والخبر السار هو أن الأداة هنا الآن: تعلم الآلة.


يتضمن التعلم الآلي تغذية عينات بيانات الخوارزمية، وعادة ما تكون مشتقة من الأسعار التاريخية. وتتكون عينات البيانات من متغيرات تسمى التنبؤات، فضلا عن متغير الهدف، وهو النتيجة المتوقعة. تتعلم الخوارزمية استخدام متغيرات التنبؤ للتنبؤ بالمتغير المستهدف.


يوفر التعلم الآلي عدد من المزايا الهامة على البرامج الخوارزمية التقليدية. يمكن لهذه العملية تسريع البحث عن استراتيجيات التداول خوارزمية فعالة من خلال أتمتة ما هو في كثير من الأحيان عملية شاقة، يدوية. كما أنه يزيد من عدد الأسواق التي يستطيع الفرد مراقبتها والاستجابة لها. والأهم من ذلك، أنها توفر القدرة على الانتقال من العثور على الجمعيات استنادا إلى البيانات التاريخية لتحديد والتكيف مع الاتجاهات عند تطورها. إذا كان بإمكانك أتمتة عملية أخرى يقوم بها يدويا؛ لديك ميزة تنافسية. إذا كنت تستطيع زيادة عدد الأسواق كنت في، لديك المزيد من الفرص. وفي عالم الصفر مجموع التداول، إذا كنت تستطيع التكيف مع التغيرات في الوقت الحقيقي في حين أن الآخرين يقفون لا يزال، صالحك سوف تترجم إلى الأرباح.


هناك العديد من الاستراتيجيات التي تستخدم تعلم الآلة لتحسين الخوارزميات، بما في ذلك: الانحدارات الخطية، والشبكات العصبية، والتعلم العميق، وآلات دعم ناقلات، و بايس ساذجة، على سبيل المثال لا الحصر. وتعمل صناديق معروفة مثل القلعة و رينيسانس تيشنولوجيز و بريدجواتر أسوسياتس و تو سيغما إنفستمينتس على اتباع استراتيجيات التعلم الآلي كجزء من نهجها الاستثماري. في سيغمودال، لدينا الخبرة والدراية لمساعدة التجار دمج مل في استراتيجيات التداول الخاصة بهم.


دراسة الحالة لدينا.


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


وكان نموذج قاعدة بيانات الذكاء الاصطناعي مسؤولا عن التنبؤ بعائدات الأصول استنادا إلى البيانات التاريخية. وقد تحقق ذلك من خلال تنفيذ وحدات الذاكرة الطويلة الأجل القصيرة، والتي هي تعميم متطور للشبكة العصبية المتكررة. هذا العمارة خاصة يمكن تخزين المعلومات لخطوات زمنية متعددة، والتي جعلت ممكنة من قبل خلية الذاكرة. هذه الخاصية تمكن النموذج من معرفة أنماط زمنية طويلة ومعقدة في البيانات. ونتيجة لذلك، تمكنا من التنبؤ بالعوائد المستقبلية للأصل، فضلا عن عدم اليقين من تقديراتنا باستخدام تقنية جديدة تسمى فارياتيونال دروبوت.


من أجل تعزيز توقعاتنا، استخدمنا ثروة من بيانات السوق، مثل العملات والمؤشرات، وما إلى ذلك في نموذجنا، بالإضافة إلى العائدات التاريخية للأصول ذات الصلة. وأدى ذلك إلى أكثر من 400 سمة استخدمناها لجعل التنبؤات النهائية. وبطبيعة الحال، فإن العديد من هذه السمات كانت مترابطة. تم تخفيف هذه المشكلة من خلال تحليل المكونات الرئيسية (يكا)، مما يقلل من أبعاد المشكلة و يميز الميزات.


ثم استخدمنا توقعات العودة والمخاطر (عدم اليقين) لجميع الأصول كمدخلات لخوارزمية تحسين التباين المتوسط، والتي تستخدم حلالا من الدرجة الثانية لتقليل المخاطر لعائد معين. وتحدد هذه الطريقة تخصيص الأصول، وهي متنوعة، وتضمن أدنى مستوى ممكن من المخاطر، بالنظر إلى توقعات العائدات.


وأدى الجمع بين هذه النماذج إلى وضع استراتيجية استثمارية ولدت عائدا سنويا بنسبة 8٪، وهو ما يزيد بنسبة 23٪ عن أي استراتيجية قياسية أخرى تم اختبارها على مدى فترة سنتين. اتصل بنا لمعرفة المزيد.


استراتيجيات منظمة العفو الدولية يتفوق.


ومن الصعب العثور على بيانات الأداء لاستراتيجيات منظمة العفو الدولية نظرا لطبيعتها الملكية، ولكن شركة أبحاث صندوق التحوط يوركيدج قد نشرت بعض البيانات الإعلامية. ويعرض الرسم البياني أدناه أداء مؤشر صندوق التحوط للتعلم الآلي / الآلي للآلة مقابل صناديق التحوط والتحصيل التقليدية من 2018 إلى 2018. ويتبع المؤشر 23 صندوقا في المجموع، منها 12 صندوقا لا يزال يعيش.


يلاحظ يوركاهيدج أن:


"لقد تفوقت صناديق التحوط للتعلم الآلي / الآلي على كل من الكوانت التقليدية ومتوسط ​​صندوق التحوط منذ عام 2018، حيث حققت عائدات سنوية بلغت 8.44٪ خلال هذه الفترة مقارنة مع 2.62٪ و 1.62٪ و 4.27٪ ل كتا ومتابعي الاتجاه ومتوسط ​​التحوط العالمي صندوق على التوالي ".


يوفر يوركاهيدج أيضا الجدول التالي مع الوجبات السريعة الرئيسية:


الجدول 1: الأداء بالأرقام - مؤشر صندوق التحوط للتعلم الآلي / مقابل التعلم الآلي مقابل المبالغ المتداولة وصناديق التحوط التقليدية.


وقد تفوقت صناديق التحوط للتعلم الآلي / الآلي على متوسط ​​صندوق التحوط العالمي لجميع السنوات باستثناء 2018.


وباستثناء عامي 2018 و 2017، تجاوزت عائدات صناديق التحویلات الخاصة بالتعلیم الآلي / التعلیم الآلي تلك الخاصة بالاستراتیجیات التقلیدیة للتحویلات النقدیة / إدارة العقود الآجلة، بینما کانت توجھات المنھج المنھجیة منخفضة الأداء بعد الاستراتیجیات لعام 2017 فقط عندما حققت ھذه المکاسب أرباحا قویة من العقود الآجلة للطاقة القصیرة.


وخالل الفرتة السنوية من خمس سنوات وثالثة وسنتني، تفوقت صناديق التحوط للتعلم اآللي / التعلم اآللي على كل من احلسابات التقليدية ومتوسط ​​صندوق التحوط العاملي الذي حقق مكاسب سنوية بلغت 7.35٪ و 9.57٪ و 10.56٪ على التوالي خالل هذه الفرتات.


كما سجلت صناديق التحوط للتعلم الآلي / التحصيل الآلي عوائد أفضل معدلة للمخاطر على مدى الفترتين السنويتين الأخيرتين و الثلاث سنوات الأخيرة مقارنة بجميع الأقران المبينة في الجدول أدناه، مع نسب شارب البالغة 1.51 و 1.53 على التوالي على التوالي.


وفي حين كانت العائدات أكثر تقلبا مقارنة بمتوسط ​​صندوق التحوط (مقارنة بمؤشر صندوق التحوط في يوركاهيدج)، فإن صناديق التعلم الآلي / الآلي قد نشرت تقلبات سنوية أقل بكثير مقارنة بالاتجاهات المنهجية التالية.


ويلاحظ يوركاهيدج أيضا أن صناديق التحوط للتعلم الآلي / الآلي "ترتبط ارتباطا سلبيا بمتوسط ​​صندوق التحوط (-0.267)" ولها "علاقة إيجابية إلى هامش هامشيا مع كتا / العقود الآجلة المدارة واتجاه الاستراتيجيات التالية"، والتي تشير إلى فوائد التنويع المحتملة لاستراتيجية الذكاء الاصطناعى.


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


هنا هو مثال لتطبيق أي في الممارسة العملية.


نظام النص المالي في أريزونا (أزفينتكست)


تخيل النظام الذي يمكن رصد أسعار الأسهم في الوقت الحقيقي، والتنبؤ تحركات أسعار الأسهم على أساس تيار الأخبار. هذا بالضبط ما يفعله أزفينتكست. تعيد هذه المقالة تجربة استخدام آلة ناقلات الدعم (سفم) لتداول S & أمب؛ P-500 وحققت نتائج ممتازة. وفيما يلي الجدول الذي يظهر كيف يؤديها بالنسبة إلى أعلى 10 صناديق الاستثمار الكمي في العالم:


إستراتيجية باستخدام مؤشرات غوغل.


استخدمت إستراتيجية التداول التجريبية الأخرى مؤشرات غوغل كمتغير. هناك عدد كبير من المقالات حول استخدام مؤشرات غوغل كمؤشر للمشاعر في السوق.


وتتبعت التجربة في هذه الورقة التغيرات في حجم البحث لمجموعة من 98 عبارة بحث (بعضها يتعلق بسوق الأوراق المالية). مصطلح & كوت؛ الدين & كوت؛ تبين أن يكون أقوى، مؤشر الأكثر موثوقية أوهن توقع تحركات الأسعار في دجيا.


في ما يلي مخطط أداء تراكمي. يعرض الخط الأحمر علامة & كوت؛ شراء مع الاستمرار & كوت؛ إستراتيجية. استفادت استراتيجية مؤشرات غوغل (الخط الأزرق) بشكل كبير من عائد بنسبة 326٪.


يمكنني تعلم مل نفسي؟


تطبيق آلة التعلم إلى التداول هو توبيس واسعة ومعقدة أن يأخذ من الوقت لإتقان. ولكن إذا كنت مهتما، كنقطة انطلاق نوصي:


مرة واحدة كنت على دراية هذه المواد، وهناك ألو دورة أوداسيتي شعبية على الساخن لتطبيق أساس التعلم آلة لتداول السوق.


إذا كنت ترغب في تسريع عملية التعلم حتى، يمكنك استئجار مستشار. تأكد من طرح أسئلة صعبة قبل بدء المشروع.


أو، يمكنك جدولة مكالمة قصيرة معنا لاستكشاف ما يمكن القيام به.


أحتاج إلى أمثلة أكثر تحديدا تنطبق في قطاعي.


من خلال دمج آلة التعلم في استراتيجيات التداول الخاصة بك، يمكن لمحفظتك التقاط المزيد من ألفا. ولكن تنفيذ استراتيجية استثمار ناجحة مل هو أمر صعب - ستحتاج إلى أشخاص غير عاديين موهوبين ذوي خبرة في مجال التجارة وعلوم البيانات للوصول إلى هناك. دعونا نساعدك على البدء.


تبحث عن آلة التعلم الاستشارات؟


شارك هذا المنشور.


الحصول على رؤى جديدة حول الحصول على البيانات للعمل!


الاشتراك في التحديثات سيغمويدال.


تجربتي مع دوكر سرب - كيفية معرفة متى كنت في حاجة إليها.


في هذا المنصب أنا ذاهب لتحليل دور عامل الميناء في كل مرحلة من مراحل دورة التطبيق و هيليب؛


التعلم العميق لرؤية الكمبيوتر - تتجاوز تصنيف الصور والانحدار.


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


بناء استراتيجيات أفضل! الجزء الرابع: تعلم الآلة.


وكان الأزرق العميق أول كمبيوتر فاز في بطولة العالم الشطرنج. كان ذلك عام 1996، واستغرق الأمر 20 عاما حتى برنامج آخر، ألفاغو، يمكن أن هزيمة أفضل لاعب غو الإنسان. كان الأزرق العميق نظاما يستند إلى نموذج مع قواعد الشطرنج هاردويريد. ألفاغو هو نظام استخراج البيانات، شبكة العصبية العميقة المدربة مع الآلاف من الألعاب الذهاب. لم تتحسن الأجهزة، ولكن انفراجة في البرنامج كان ضروريا لخطوة من الضرب كبار لاعبي الشطرنج لضرب كبار اللاعبين الذهاب.


في هذا الجزء 4 من سلسلة مصغرة نحن & # 8217؛ سوف ننظر في نهج استخراج البيانات لتطوير استراتيجيات التداول. هذا الأسلوب لا يهتم بآليات السوق. انها مجرد مسح منحنيات السعر أو مصادر البيانات الأخرى للنماذج التنبؤية. تعلم الآلة أو & # 8220؛ الذكاء الاصطناعي & # 8221؛ لا تشارك دائما في استراتيجيات استخراج البيانات. في الواقع الأكثر شعبية & # 8211؛ والمربحة بشكل مثير للدهشة & # 8211؛ طريقة استخراج البيانات يعمل دون أي الشبكات العصبية الهوى أو آلات ناقلات الدعم.


مبادئ التعلم الآلي.


يتم تغذية خوارزمية التعلم مع عينات البيانات، وعادة ما تستمد بطريقة ما من الأسعار التاريخية. وتتألف كل عينة من متغيرات n × 1 .. x n، والتي يطلق عليها عادة تنبؤات، وميزات، وإشارات، أو ببساطة إدخال. يمكن لهذه التنبؤات أن تكون عائدات السعر من آخر أشرطة n، أو مجموعة من المؤشرات الكلاسيكية، أو أي وظائف أخرى يمكن تخيلها من منحنى السعر (I & # 8217؛ حتى رأيت بكسل من صورة الرسم البياني للسعر المستخدمة كمنبؤات لعصبية شبكة الاتصال!). كل عينة تشمل عادة متغير الهدف y، مثل عودة التجارة القادمة بعد أخذ العينة، أو حركة السعر المقبل. في الأدب يمكنك أن تجد ذ اسمه أيضا تسمية أو موضوعية. في عملية التدريب، والخوارزمية يتعلم التنبؤ الهدف ذ من تنبؤات x 1 .. س ن. الذاكرة & # 8216؛ الذاكرة & # 8217؛ يتم تخزينها في بنية بيانات اسمها النموذج الذي هو محدد للخوارزمية (لا ينبغي الخلط بينه وبين نموذج مالي للاستراتيجيات القائمة على نموذج!). يمكن أن يكون نموذج التعلم الآلي وظيفة مع قواعد التنبؤ في رمز C، التي تم إنشاؤها بواسطة عملية التدريب. أو يمكن أن يكون مجموعة من أوزان الاتصال للشبكة العصبية.


يجب على التنبؤات، والميزات، أو ما تسمونه، يجب أن تحمل معلومات كافية للتنبؤ الهدف ذ مع بعض الدقة. كما أنها غالبا ما تفي بمتطلبين رسميين. أولا، يجب أن تكون جميع قيم التنبؤ في نفس النطاق، مثل -1 .. +1 (لمعظم خوارزميات R) أو -100 .. +100 (لخوارزميات زورو أو تسب). لذلك تحتاج إلى تطبيع لهم في بعض الطريق قبل إرسالها إلى الجهاز. ثانيا، يجب أن تكون العينات متوازنة، أي موزعة بالتساوي على جميع قيم المتغير المستهدف. لذلك يجب أن يكون هناك حول العديد من الفوز كما تفقد العينات. إذا لم تلاحظ هذين الشرطين، فإنك تتساءل عن سبب حصولك على نتائج سيئة من خوارزمية تعلم الآلة.


تتوقع خوارزميات الانحدار قيمة رقمية، مثل حجم وعلامة حركة السعر التالية. تتنبأ خوارزميات التصنيف بفئة عينة نوعية، على سبيل المثال، ما إذا كانت النتيجة تسبق الفوز أو الخسارة. بعض الخوارزميات، مثل الشبكات العصبية، أشجار القرار، أو دعم ناقلات الآلات، يمكن تشغيلها في كلا الوضعين.


وهناك عدد قليل من الخوارزميات تعلم تقسيم العينات إلى فئات دون الحاجة إلى أي هدف ذ. هذا التعلم غير الخاضع للرقابة، بدلا من التعلم تحت الإشراف باستخدام الهدف. في مكان ما في المنتصف هو التعلم التعزيز، حيث يقوم النظام بتدريب نفسه عن طريق تشغيل المحاكاة مع ميزات معينة، واستخدام النتيجة كهدف التدريب. ألفازيرو، خليفة ألفاغو، استخدم التعلم التعزيز من خلال اللعب الملايين من ألعاب الذهاب ضد نفسها. في مجال التمويل هناك عدد قليل من التطبيقات للتعلم غير الخاضعة للرقابة أو التعزيز. 99٪ من استراتيجيات التعلم الآلي تستخدم التعلم تحت الإشراف.


أيا كانت الإشارات التي نستخدمها للتنبؤات في التمويل، فإنها على الأرجح تحتوي على الكثير من الضجيج وقليل من المعلومات، وسوف تكون غير مستقرة على رأسها. لذلك التنبؤ المالي هو واحد من أصعب المهام في التعلم الآلي. الخوارزميات الأكثر تعقيدا لا تحقق بالضرورة نتائج أفضل. اختيار التنبؤات أمر بالغ الأهمية للنجاح. ليست فكرة جيدة لاستخدام الكثير من التنبؤات، لأن هذا يسبب ببساطة الإفراط في الفشل والفشل في الخروج من عملية العينة. لذلك استراتيجيات استخراج البيانات غالبا ما تطبق خوارزمية الاختيار الأولي الذي يحدد عدد قليل من التنبؤات من مجموعة من العديد. ويمكن أن يستند الاختيار المسبق إلى العلاقة بين المتنبئات، وعلى الأهمية، وعلى محتوى المعلومات، أو ببساطة على نجاح التنبؤ مع مجموعة اختبار. التجارب العملية مع اختيار ميزة يمكن العثور عليها في مقالة حديثة عن بلوق روبوت الثروة.


هنا & # 8217؛ s قائمة من الأكثر شعبية استخراج البيانات الطرق المستخدمة في التمويل.


1. حساء المؤشر.


معظم النظم التجارية نحن & # 8217؛ إعادة البرمجة للعملاء لا تستند إلى نموذج مالي. العميل يريد فقط إشارات التجارة من بعض المؤشرات الفنية، تصفيتها مع المؤشرات الفنية الأخرى في تركيبة مع المزيد من المؤشرات الفنية. وعندما سئل عن كيف يمكن لهذا الخليط من المؤشرات أن يكون استراتيجية مربحة، أجاب عادة: & # 8220؛ ثق بي. I & # 8217؛ م التداول يدويا، وأنه يعمل. & # 8221؛


لقد فعلت ذلك بالفعل. على الأقل في بعض الأحيان. على الرغم من أن معظم تلك النظم لم يمر اختبار وفا (وبعض حتى لا باكتست بسيط)، وعدد كبير من المستغرب فعلت. وكانت تلك أيضا في كثير من الأحيان مربحة في التداول الحقيقي. وقد أجرى العميل تجربة منهجية للمؤشرات الفنية حتى وجد مزيجا يعمل في التداول المباشر مع أصول معينة. هذه الطريقة من التحليل الفني التجريبي والخطأ هو نهج استخراج البيانات الكلاسيكية، مجرد إعدام من قبل الإنسان وليس من قبل آلة. لا أستطيع حقا أن أوصي هذا الأسلوب & # 8211؛ والكثير من الحظ، لا الكلام عن المال، وربما تشارك & # 8211؛ ولكن يمكنني أن أشهد أنه يؤدي أحيانا إلى أنظمة مربحة.


2. أنماط شمعة.


لا ينبغي الخلط مع تلك أنماط الشموع اليابانية التي كان لها أفضل قبل تاريخ طويل، منذ فترة طويلة. المعادل الحديث هو تداول حركة السعر. أنت & # 8217؛ لا تزال تبحث في مفتوحة، عالية، منخفضة، وإغلاق الشموع. أنت & # 8217؛ لا تزال تأمل في العثور على نمط يتنبأ بإتجاه السعر. ولكن أنت & # 8217؛ الآن استخراج البيانات المعاصرة السعر المنحنيات لجمع تلك الأنماط. وهناك حزم برامج لهذا الغرض. يبحثون عن أنماط مربحة من قبل بعض المعايير المعرفة من قبل المستخدم، واستخدامها لبناء وظيفة كشف نمط معين. يمكن أن يبدو مثل هذا واحد (من زورو & # 8217؛ ق نمط محلل):


ترجع الدالة C 1 عندما تطابق الإشارات أحد الأنماط، وإلا 0. يمكنك أن ترى من الشفرة الطويلة أن هذه ليست أسرع طريقة للكشف عن الأنماط. طريقة أفضل، التي يستخدمها زورو عندما لا يتم تصدير وظيفة الكشف، هو فرز الإشارات من حيث حجمها والتحقق من ترتيب الفرز. ومثال على هذا النظام يمكن العثور عليها هنا.


يمكن سعر التداول العمل حقا العمل؟ تماما مثل حساء المؤشر، فإنه لا يستند إلى أي نموذج مالي عقلاني. يمكن للمرء أن يتصور في أفضل الأحوال أن تسلسل تحركات الأسعار يسبب المشاركين في السوق للرد بطريقة معينة، وبهذه الطريقة إنشاء نمط تنبؤي مؤقت. ومع ذلك فإن عدد من أنماط محدودة جدا عند النظر فقط في تسلسل عدد قليل من الشموع المتجاورة. الخطوة التالية هي مقارنة الشموع التي ليست متاخمة، ولكن يتم اختيارها بشكل تعسفي خلال فترة زمنية أطول. وبهذه الطريقة يمكنك الحصول على عدد غير محدود تقريبا من الأنماط & # 8211؛ ولكن على حساب ترك أخيرا مجال العقلاني. من الصعب أن نتخيل كيف يمكن توقع حركة السعر من قبل بعض أنماط الشموع منذ أسابيع.


ومع ذلك، هناك الكثير من الجهد في ذلك. يدير زميل المدون، دانيال فرنانديز، موقع الاشتراك على الانترنت (أسيريكوي) المتخصصة في استخراج البيانات أنماط شمعة. انه صقل نمط التداول وصولا الى أصغر التفاصيل، وإذا كان أي شخص من أي وقت مضى تحقيق أي ربح بهذه الطريقة، سيكون له. ولكن لمشتركيه & # 8217؛ خيبة أمل، تداول أنماطه الحية (كوريكوانت) أنتج نتائج مختلفة جدا من له باكتيستس رائعة. إذا كانت أنظمة العمل السعر مربحة موجودة حقا، على ما يبدو لا أحد قد وجدت لهم حتى الآن.


3. الانحدار الخطي.


أساس بسيط من العديد من خوارزميات التعلم الآلي المعقدة: التنبؤ المتغير الهدف ذ من قبل مزيج خطي من التنبؤات × 1 .. س ن.


والمعاملات a هي النموذج. يتم حسابها لتقليل مجموع الاختلافات المربعة بين القيم الحقيقية y من عينات التدريب وتوقعها y من الصيغة أعلاه:


للعينات الموزعة العادية، والتقليل من الممكن مع بعض الحساب المصفوفة، لذلك لا حاجة التكرارات. في الحالة n = 1 & # 8211؛ مع متغير واحد فقط متغير x & # 8211؛ يتم تقليل صيغة الانحدار إلى.


وهو الانحدار الخطي البسيط، بدلا من الانحدار الخطي متعدد المتغيرات حيث n & غ؛ 1 - الانحدار الخطي البسيط متوفر في معظم منصات التداول، f. i. مع مؤشر لينريغ في تا-ليب. مع y = برايس و x = تايم & # 8217؛ s غالبا ما تستخدم كبديل للمتوسط ​​المتحرك. الانحدار الخطي متعدد المتغيرات متاح في منصة R من خلال الدالة (..) التي تأتي مع التثبيت القياسي. البديل هو الانحدار متعدد الحدود. مثل الانحدار البسيط فإنه يستخدم متغير واحد فقط متغير x، ولكن أيضا مربعه ودرجاته العليا، بحيث x n == x n:


مع n = 2 أو n = 3، غالبا ما يستخدم الانحدار متعدد الحدود للتنبؤ بالسعر المتوسط ​​التالي من الأسعار المسطحة للأشرطة الأخيرة. وظيفة بوليفيت من ماتلاب، R، زورو، والعديد من المنصات الأخرى يمكن أن تستخدم لانحدار متعدد الحدود.


4. بيرسيبترون.


غالبا ما يشار إليها باسم الشبكة العصبية مع واحد فقط من الخلايا العصبية. في الواقع بيرسيبترون هو وظيفة الانحدار مثل أعلاه، ولكن مع نتيجة ثنائية، مما يسمى الانحدار اللوجستي. انها & # 8217؛ s لا الانحدار الرغم من ذلك، انها & # 8217؛ s خوارزمية التصنيف. تولد الدالة زورو & # 8217 s (بيرسيبترون، & # 8230؛) شفرة C ترجع إما 100 أو -100، وتعتمد على ما إذا كانت النتيجة المتوقعة أعلى من عتبة أم لا:


يمكنك أن ترى أن صفيف سيغ يعادل الميزات x n في صيغة الانحدار، والعوامل الرقمية هي المعاملات n.


5. الشبكات الإلكترونية N.


الانحدار الخطي أو اللوجستي يمكن أن تحل المشاكل الخطية فقط. العديد من لا تقع في هذه الفئة & # 8211؛ مثال مشهور هو التنبؤ الناتج من وظيفة شور بسيطة. وعلى الأرجح أيضا التنبؤ الأسعار أو عائدات التجارة. يمكن للشبكة العصبية الاصطناعية (أن) معالجة المشاكل غير الخطية. انها مجموعة من بيرسيبترونس التي ترتبط معا في مجموعة من الطبقات. أي بيرسيبترون هو الخلايا العصبية من الشبكة. خرجها يذهب إلى مدخلات جميع الخلايا العصبية من الطبقة التالية، مثل هذا:


وكما هو الحال في المنظور، تتعلم الشبكة العصبية أيضا من خلال تحديد المعاملات التي تقلل من الخطأ بين التنبؤ بالعينة وهدف العينة. ولكن هذا يتطلب الآن عملية تقريب، وعادة مع باكبروباغاتينغ الخطأ من الإخراج إلى المدخلات، وتحسين الأوزان في طريقها. وتفرض هذه العملية قيادتين. أولا، يجب أن تكون مخرجات الخلايا العصبية الآن وظائف مختلفة بشكل مستمر بدلا من عتبة الإدراك الحسي البسيط. ثانيا، يجب ألا تكون الشبكة عميقة جدا & # 8211؛ يجب ألا يحتوي على عدد كبير جدا من & # 8216؛ الطبقات المخفية & # 8217؛ من الخلايا العصبية بين المدخلات والمخرجات. هذا التقييد الثاني يحد من تعقيد المشاكل التي يمكن أن تحلها الشبكة العصبية القياسية.


عند استخدام الشبكة العصبية للتنبؤ بالصفقات، لديك الكثير من المعلمات التي يمكنك اللعب حولها، وإذا كنت & # 8217؛ لا حذرا، تنتج الكثير من التحيز الاختيار:


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


وظيفة التنشيط يحاكي عتبة بيرسيبترون. ل باكبروباغاتيون تحتاج إلى وظيفة التفريق بشكل مستمر أن يولد & # 8216؛ لينة & # 8217؛ خطوة على قيمة x معينة. عادة يتم استخدام وظيفة السيني، تانه، أو سوفتماكس. في بعض الأحيان انها أيضا وظيفة خطية التي ترجع فقط المبلغ المرجح لجميع المدخلات. في هذه الحالة يمكن استخدام الشبكة للانحدار، للتنبؤ بقيمة رقمية بدلا من نتيجة ثنائية.


الشبكات العصبية متوفرة في تركيب R القياسية (نيت، شبكة طبقة مخفية واحدة) وفي العديد من الحزم، على سبيل المثال رسنس و FCNN4R.


6. التعلم العميق.


تستخدم طرق التعلم العميق الشبكات العصبية مع العديد من الطبقات الخفية والآلاف من الخلايا العصبية، والتي لا يمكن تدريبها بشكل فعال بعد الآن من قبل باكبروباغاتيون التقليدية. أصبحت عدة طرق شعبية في السنوات الأخيرة لتدريب مثل هذه الشبكات الضخمة. وهم عادة ما قبل تدريب طبقات الخلايا العصبية الخفية لتحقيق عملية التعلم أكثر فعالية. A بولتزمان مقيدة آلة (ربم) هو خوارزمية تصنيف غير خاضعة للرقابة مع بنية شبكة خاصة لا يوجد لديه اتصالات بين الخلايا العصبية الخفية. يستخدم جهاز الاشتعال المتفرق (ساي) بنية الشبكة التقليدية، ولكن قبل القطارات الطبقات المخفية بطريقة ذكية من خلال إعادة إنتاج إشارات الإدخال على مخرجات الطبقة مع عدد قليل من الاتصالات النشطة ممكن. وتتيح هذه الأساليب لشبكات معقدة جدا لمعالجة مهام التعلم المعقدة للغاية. مثل الضرب العالم & # 8217؛ لاعب أفضل الإنسان الذهاب.


شبكات التعلم العميق متوفرة في حزم ديبنيت و دارتش R. يوفر ديبنيت أوتوينكودر، دارتش آلة بولتزمان مقيدة. أنا لم تجرب حتى الآن مع دارتش، ولكن هنا & # 8217؛ s مثال النصي R باستخدام ديبنيت أوتوينكودر مع 3 طبقات مخفية لإشارات التجارة من خلال زورو & # 8217؛ s العصبية () وظيفة:


7. دعم ناقلات الآلات.


مثل شبكة العصبية، آلة ناقلات الدعم (سفم) هو امتداد آخر للانحدار الخطي. عندما ننظر إلى صيغة الانحدار مرة أخرى،


يمكننا تفسير ملامح x ن كإحداثيات مساحة ميزة n - dimensional. تحديد المتغير الهدف y إلى قيمة ثابتة يحدد مستوي في تلك المساحة، يسمى هبربلان لأنه يحتوي على أكثر من اثنين (في الواقع، ن -1) أبعاد. تفصل اللوحة المفرطة العينات مع y & غ؛ o من العينات مع y & لوت؛ 0. ويمكن حساب المعاملات n بطريقة تجعل مسافات الطائرة أقرب العينات & # 8211؛ والتي تسمى & # 8216؛ ناقلات الدعم & # 8217؛ من الطائرة، وبالتالي اسم الخوارزمية & # 8211؛ هو الحد الأقصى. بهذه الطريقة لدينا المصنف ثنائي مع الفصل الأمثل من العينات الفائزة والخاسرة.


المشكلة: عادة لا تكون هذه العينات قابلة للفصل خطيا & # 8211؛ فهي متناثرة حول بشكل غير منتظم في الفضاء ميزة. لا يمكن أن تقلص طائرة مسطحة بين الفائزين والخاسرين. إذا كان يمكن، كان لدينا أساليب أبسط لحساب تلك الطائرة، f. i. التحليل التمييزي الخطي. ولكن بالنسبة للحالة المشتركة نحن بحاجة إلى خدعة سفم: إضافة المزيد من الأبعاد لمساحة الميزة. لهذا الخوارزمية سفم تنتج المزيد من الميزات مع وظيفة النواة التي تجمع بين أي اثنين من التنبؤات الحالية إلى ميزة جديدة. وهذا يشبه الخطوة أعلاه من الانحدار البسيط إلى الانحدار متعدد الحدود، حيث تضيف أيضا المزيد من الميزات عن طريق أخذ المتنبأ الوحيد بالسلطة n. والمزيد من الأبعاد التي تضيفها، وأسهل هو لفصل العينات مع لوحة مسطحة مسطحة. ثم يتم تحويل هذه الطائرة مرة أخرى إلى الفضاء N - الأبعاد الأصلي، والحصول على التجاعيد وتكتل على الطريق. بواسطة ذكي اختيار وظيفة النواة، ويمكن تنفيذ العملية دون حساب الواقع التحول.


مثل الشبكات العصبية، سفمز يمكن استخدامها ليس فقط للتصنيف، ولكن أيضا للانحدار. كما أنها توفر بعض المعلمات لتحسين عملية التنبؤ وربما تحسينها:


وظيفة النواة. كنت عادة استخدام نواة ربف (وظيفة أساس شعاعي، نواة متماثلة)، ولكن لديك أيضا اختيار حبات أخرى، مثل السيني، متعدد الحدود، والخطي. غاما، وعرض نواة ربف معلمة التكلفة C، و & # 8216؛ ركلة جزاء & # 8217؛ للتصنيفات الخاطئة في عينات التدريب.


سفم المستخدمة في كثير من الأحيان هي مكتبة ليبسفم. كما أنها متوفرة في R في حزمة e1071. في الجزء التالي والأخير من هذه السلسلة أخطط لوصف استراتيجية التداول باستخدام هذا سفم.


8. K - أقرب الجيران.


مقارنة مع أن آن الثقيلة و سفم الاشياء، أن & # 8217؛ ق خوارزمية بسيطة لطيفة مع خاصية فريدة من نوعها: فإنه لا يحتاج إلى التدريب. وبالتالي فإن العينات هي النموذج. هل يمكن استخدام هذه الخوارزمية لنظام التداول الذي يتعلم بشكل دائم عن طريق إضافة المزيد والمزيد من العينات ببساطة. وتحسب خوارزمية الجوار الأقرب المسافات في حيز الميزة من قيم الخصائص الحالية إلى العينات الأقرب k. وتحسب المسافة في الفضاء n الأبعاد من مجموعتين من السمات (x 1 .. x n) و (y 1 .. y n) كما هو الحال في بعدين:


وتتوقع الخوارزمية ببساطة الهدف من متوسط ​​المتغيرات المستهدفة k لأقرب العينات، المرجحة بمسافاتها العكسية. ويمكن استخدامه للتصنيف وكذلك الانحدار. يمكن للحيل البرمجيات اقترضت من الرسومات الكمبيوتر، مثل شجرة ثنائية التكيف (عبت)، جعل أقرب جار البحث بسرعة كبيرة. في حياتي الماضية كما مبرمج لعبة الكمبيوتر، استخدمنا هذه الأساليب في ألعاب لمهام مثل التعلم الذاتي الذكاء العدو. يمكنك استدعاء وظيفة كن في R للتنبؤ أقرب الجار & # 8211؛ أو كتابة وظيفة بسيطة في C لهذا الغرض.


هذه خوارزمية تقريبية للتصنيف غير الخاضع للرقابة. لديها بعض التشابه، وليس فقط اسمها، إلى k - أقرب الجار. لتصنيف العينات، تضع الخوارزمية أولا نقاط عشوائية k في مساحة العنصر. ثم يعين إلى أي من تلك النقاط جميع العينات مع أصغر مسافات إليها. ثم يتم نقل النقطة إلى متوسط ​​هذه العينات الأقرب. وهذا سيولد تخصيص عينات جديدة، لأن بعض العينات هي الآن أقرب إلى نقطة أخرى. وتكرر العملية إلى أن لا يتغير التخصيص بعد الآن بتحريك النقاط، أي أن كل نقطة تكمن بالضبط في متوسط ​​عيناتها الأقرب. لدينا الآن K فئات من العينات، كل في حي واحد من النقاط k.


هذه الخوارزمية بسيطة يمكن أن تنتج نتائج جيدة بشكل مدهش. في R، وظيفة كمينز لا خدعة. مثال على خوارزمية k-مينز لتصنيف أنماط الشموع يمكن العثور عليها هنا: تصنيف الشموع غير الخاضعة للمراقبة من أجل المتعة والربح.


10. نايف بايس.


تستخدم هذه الخوارزمية بايز & # 8217؛ نظرية لتصنيف عينات من الميزات غير الرقمية (أي الأحداث)، مثل أنماط شمعة المذكورة أعلاه. لنفرض أن الحدث X (على سبيل المثال، أن فتح الشريط السابق أقل من فتح الشريط الحالي) يظهر في 80٪ من جميع العينات الفائزة. ما هو احتمالية فوز العينة عندما تحتوي على الحدث X؟ إنه ليس 0.8 كما قد تعتقد. يمكن حساب الاحتمال مع بايز & # 8217؛ نظرية:


P (Y | X) هو احتمال حدوث الحدث Y (f. i الفوز) في جميع العينات التي تحتوي على الحدث X (في مثالنا، أوبين (1) & لوت؛ أوبين (0)). According to the formula, it is equal to the probability of X occurring in all winning samples (here, 0.8), multiplied by the probability of Y in all samples (around 0.5 when you were following my above advice of balanced samples) and divided by the probability of X in all samples.


If we are naive and assume that all events X are independent of each other, we can calculate the overall probability that a sample is winning by simply multiplying the probabilities P (X|winning) for every event X . This way we end up with this formula:


with a scaling factor s . For the formula to work, the features should be selected in a way that they are as independent as possible, which imposes an obstacle for using Naive Bayes in trading. For instance, the two events Close(1) < Close(0) and Open(1) < Open(0) are most likely not independent of each other. Numerical predictors can be converted to events by dividing the number into separate ranges.


The Naive Bayes algorithm is available in the ubiquitous e1071 R package.


11. Decision and regression trees.


Those trees predict an outcome or a numeric value based on a series of yes/no decisions, in a structure like the branches of a tree. Any decision is either the presence of an event or not (in case of non-numerical features) or a comparison of a feature value with a fixed threshold. A typical tree function, generated by Zorro’s tree builder, looks like this:


How is such a tree produced from a set of samples? There are several methods; Zorro uses the Shannon i nformation entropy , which already had an appearance on this blog in the Scalping article. At first it checks one of the features, let’s say x 1 . It places a hyperplane with the plane formula x 1 = t into the feature space. This hyperplane separates the samples with x 1 > t from the samples with x 1 < t . The dividing threshold t is selected so that the information gain – the difference of information entropy of the whole space, to the sum of information entropies of the two divided sub-spaces – is maximum. This is the case when the samples in the subspaces are more similar to each other than the samples in the whole space.


This process is then repeated with the next feature x 2 and two hyperplanes splitting the two subspaces. Each split is equivalent to a comparison of a feature with a threshold. By repeated splitting, we soon get a huge tree with thousands of threshold comparisons. Then the process is run backwards by pruning the tree and removing all decisions that do not lead to substantial information gain. Finally we end up with a relatively small tree as in the code above.


Decision trees have a wide range of applications. They can produce excellent predictions superior to those of neural networks or support vector machines. But they are not a one-fits-all solution, since their splitting planes are always parallel to the axes of the feature space. This somewhat limits their predictions. They can be used not only for classification, but also for regression, for instance by returning the percentage of samples contributing to a certain branch of the tree. Zorro’s tree is a regression tree. The best known classification tree algorithm is C5.0 , available in the C50 package for R.


For improving the prediction even further or overcoming the parallel-axis-limitation, an ensemble of trees can be used, called a random forest . The prediction is then generated by averaging or voting the predictions from the single trees. Random forests are available in R packages randomForest , ranger and Rborist .


استنتاج.


There are many different data mining and machine learning methods at your disposal. The critical question: what is better, a model-based or a machine learning strategy? There is no doubt that machine learning has a lot of advantages. You don’t need to care about market microstructure, economy, trader psychology, or similar soft stuff. You can concentrate on pure mathematics. Machine learning is a much more elegant, more attractive way to generate trade systems. It has all advantages on its side but one. Despite all the enthusiastic threads on trader forums, it tends to mysteriously fail in live trading.


Every second week a new paper about trading with machine learning methods is published (a few can be found below). Please take all those publications with a grain of salt. According to some papers, phantastic win rates in the range of 70%, 80%, or even 85% have been achieved. Although win rate is not the only relevant criterion – you can lose even with a high win rate – 85% accuracy in predicting trades is normally equivalent to a profit factor above 5. With such a system the involved scientists should be billionaires meanwhile. Unfortunately I never managed to reproduce those win rates with the described method, and didn’t even come close. So maybe a lot of selection bias went into the results. Or maybe I’m just too stupid.


Compared with model based strategies, I’ve seen not many successful machine learning systems so far. And from what one hears about the algorithmic methods by successful hedge funds, machine learning seems still rarely to be used. But maybe this will change in the future with the availability of more processing power and the upcoming of new algorithms for deep learning.


Classification using deep neural networks: Dixon. et. al.2018 Predicting price direction using ANN & SVM: Kara. et. al.2018 Empirical comparison of learning algorithms: Caruana. et. al.2006 Mining stock market tendency using GA & SVM: Yu. Wang. Lai.2005.


The next part of this series will deal with the practical development of a machine learning strategy.


30 thoughts on “Build Better Strategies! Part 4: Machine Learning”


مشاركة لطيفة. There is a lot of potential in these approach towards the market.


Btw are you using the code editor which comes with zorro? how is it possible to get such a colour configuration?


The colorful script is produced by WordPress. You can’t change the colors in the Zorro editor, but you can replace it with other editors that support individual colors, for instance Notepad++.


Is it then possible that notepad detects the zorro variables in the scripts? I mean that BarPeriod is remarked as it is with the zorro editor?


Theoretically yes, but for this you had to configure the syntax highlighting of Notepad++, and enter all variables in the list. As far as I know Notepad++ can also not be configured to display the function description in a window, as the Zorro editor does. There’s no perfect tool…


Concur with the final paragraph. I have tried many machine learning techniques after reading various ‘peer reviewed’ papers. But reproducing their results remains elusive. When I live test with ML I can’t seem to outperform random entry.


ML fails in live? Maybe the training of the ML has to be done with price data that include as well historical spread, roll, tick and so on?


I think reason #1 for live failure is data mining bias, caused by biased selection of inputs and parameters to the algo.


Thanks to the author for the great series of articles.


However, it should be noted that we don’t need to narrow our view with predicting only the next price move. It may happen that the next move goes against our trade in 70% of cases but it still worth making a trade. This happens when the price finally does go to the right direction but before that it may make some steps against us. If we delay the trade by one price step we will not enter the mentioned 30% of trades but for that we will increase the result of the remained 70% by one price step. So the criteria is which value is higher: N*average_result or 0.7*N*(avergae_result + price_step).


مشاركة لطيفة. If you just want to play around with some machine learning, I implemented a very simple ML tool in python and added a GUI. It’s implemented to predict time series.


Thanks JCL I found very interesting your article. I would like to ask you, from your expertise in trading, where can we download reliable historical forex data? I consider it very important due to the fact that Forex market is decentralized.


شكرا مقدما!


There is no really reliable Forex data, since every Forex broker creates their own data. They all differ slightly dependent on which liquidity providers they use. FXCM has relatively good M1 and tick data with few gaps. You can download it with Zorro.


Thanks for writing such a great article series JCL… a thoroughly enjoyable read!


I have to say though that I don’t view model-based and machine learning strategies as being mutually exclusive; I have had some OOS success by using a combination of the elements you describe.


To be more exact, I begin the system generation process by developing a ‘traditional’ mathematical model, but then use a set of online machine learning algorithms to predict the next terms of the various different time series (not the price itself) that are used within the model. The actual trading rules are then derived from the interactions between these time series. So in essence I am not just blindly throwing recent market data into an ML model in an effort to predict price action direction, but instead develop a framework based upon sound investment principles in order to point the models in the right direction. I then data mine the parameters and measure the level of data-mining bias as you’ve described also.


It’s worth mentioning however that I’ve never had much success with Forex.


Anyway, best of luck with your trading and keep up the great articles!


Thanks for posting this great mini series JCL.


I recently studied a few latest papers about ML trading, deep learning especially. Yet I found that most of them valuated the results without risk-adjusted index, i. e., they usually used ROC curve, PNL to support their experiment instead of Sharpe Ratio, for example.


Also, they seldom mentioned about the trading frequency in their experiment results, making it hard to valuate the potential profitability of those methods. لماذا هذا؟ Do you have any good suggestions to deal with those issues?


ML papers normally aim for high accuracy. Equity curve variance is of no interest. This is sort of justified because the ML prediction quality determines accuracy, not variance.


Of course, if you want to really trade such a system, variance and drawdown are important factors. A system with lower accuracy and worse prediction can in fact be preferable when it’s less dependent on market condictions.


“In fact the most popular – and surprisingly profitable – data mining method works without any fancy neural networks or support vector machines.”


Would you please name those most popular & surprisingly profitable ones. So I could directly use them.


I was referring to the Indicator Soup strategies. For obvious reasons I can’t disclose details of such a strategy, and have never developed such systems myself. We’re merely coding them. But I can tell that coming up with a profitable Indicator Soup requires a lot of work and time.


Well, i am just starting a project which use simple EMAs to predict price, it just select the correct EMAs based on past performance and algorithm selection that make some rustic degree of intelligence.


Jonathan. orrego@gmail offers services as MT4 EA programmer.


شكرا على writeup جيد. It in reality used to be a leisure account it.


Look complicated to more delivered agreeable from you!


By the way, how could we be in contact?


There are following issues with ML and with trading systems in general which are based on historical data analysis:


1) Historical data doesn’t encode information about future price movements.


Future price movement is independent and not related to the price history. There is absolutely no reliable pattern which can be used to systematically extract profits from the market. Applying ML methods in this domain is simply pointless and doomed to failure and is not going to work if you search for a profitable system. Of course you can curve fit any past period and come up with a profitable system for it.


The only thing which determines price movement is demand and supply and these are often the result of external factors which cannot be predicted. For example: a war breaks out somewhere or other major disaster strikes or someone just needs to buy a large amount of a foreign currency for some business/investment purpose. These sort of events will cause significant shifts in the demand supply structure of the FX market . As a consequence, prices begin to move but nobody really cares about price history just about the execution of the incoming orders. An automated trading system can only be profitable if it monitors a significant portion of the market and takes the supply and demand into account for making a trading decision. But this is not the case with any of the systems being discussed here.


2) Race to the bottom.


Even if (1) wouldn’t be true and there would be valuable information encoded in historical price data, you would still face following problem: there are thousands of gold diggers out there, all of them using similar methods and even the same tools to search for profitable systems and analyze the same historical price data. As a result, many of them will discover the same or very similar “profitable” trading systems and when they begin actually trading those systems, they will become less and less profitable due to the nature of the market.


The only sure winners in this scenario will be the technology and tool vendors.


I will be still keeping an eye on your posts as I like your approach and the scientific vigor you apply. Your blog is the best of its kind – keep the good work!


One hint: there are profitable automated systems, but they are not based on historical price data but on proprietary knowledge about the market structure and operations of the major institutions which control these markets. Let’s say there are many inefficiencies in the current system but you absolutely have no chance to find the information about those by analyzing historical price data. Instead you have to know when and how the institutions will execute market moving orders and front run them.


Thanks for the extensive comment. I often hear these arguments and they sound indeed intuitive, only problem is that they are easily proven wrong. The scientific way is experiment, not intuition. Simple tests show that past and future prices are often correlated – otherwise every second experiment on this blog had a very different outcome. Many successful funds, for instance Jim Simon’s Renaissance fund, are mainly based on algorithmic prediction.


One more thing: in my comment I have been implicitly referring to the buy side (hedge funds, traders etc) not to the sell side (market makers, banks). The second one has always the edge because they sell at the ask and buy at the bid, pocketing the spread as an additional profit to any strategy they might be running. Regarding Jim Simon’s Renaissance: I am not so sure if they have not transitioned over the time to the sell side in order to stay profitable. There is absolutely no information available about the nature of their business besides the vague statement that they are using solely quantitative algorithmic trading models…


Thanks for the informative post!


Regarding the use of some of these algorithms, a common complaint which is cited is that financial data is non-stationary…Do you find this to be a problem? Couldn’t one just use returns data instead which is (I think) stationary?


Yes, this is a problem for sure. If financial data were stationary, we’d all be rich. I’m afraid we have to live with what it is. Returns are not any more stationary than other financial data.


Hello sir, I developed some set of rules for my trading which identifies supply demand zones than volume and all other criteria. Can you help me to make it into automated system ?? If i am gonna do that myself then it can take too much time. Please contact me at svadukia@gmail if you are interested.


Sure, please contact my employer at info@opgroup. de. They’ll help.


I have noticed you don’t monetize your page, don’t waste your traffic,


you can earn extra bucks every month because you’ve got high quality content.


If you want to know how to make extra $$$, search for: Mrdalekjd methods for $$$


Technical analysis has always been rejected and looked down upon by quants, academics, or anyone who has been trained by traditional finance theories. I have worked for proprietary trading desk of a first tier bank for a good part of my career, and surrounded by those ivy-league elites with background in finance, math, or financial engineering. I must admit none of those guys knew how to trade directions. They were good at market making, product structures, index arb, but almost none can making money trading directions. لماذا ا؟ Because none of these guys believed in technical analysis. Then again, if you are already making your millions why bother taking the risk of trading direction with your own money. For me luckily my years of training in technical analysis allowed me to really retire after laying off from the great recession. I look only at EMA, slow stochastics, and MACD; and I have made money every year since started in 2009. Technical analysis works, you just have to know how to use it!!


QuantStart.


What is Machine Learning?


And why is it useful for quant finance?


Machine learning makes use of algorithms that learn how to perform tasks such as prediction or classification without explicitly being programmed to do so. In essence, the algorithms learn from data rather than being prespecified.


Such algorithms are incredibly diverse and range from more traditional statistical models that emphasise inference through to highly complex hierarchical "deep" neural network architectures that excel at prediction and classification tasks.


Over the last ten years or so machine learning has been making steady gains in the quantitative finance sector and has aroused the interest of large quant funds including Man AHL, DE Shaw, Winton, Citadel and Two Sigma to name a few.


Machine learning algorithms can be applied in incredibly diverse ways for quantitative finance. Particular examples include:


Prediction of future asset price movements Prediction of liquidity movements due to redemption of capital in large funds Determination of mis-priced assets in niche markets Natural language processing of equity analyst sentiment and forecasts Image classification/recognition for use in commodity supply/demand signals.


Unfortunately much of the work on applying machine learning algorithms to trading strategies in quant finance is proprietary and thus difficult to obtain. However, with practice it can be seen how to take certain datasets and find consistent alpha.


Machine learning is a broad area and is not a field that can be mastered quickly. The following resources will teach the basics, allowing you to dive deeper into specific areas:


Machine Learning Domains.


What are the differing areas of study in machine learning?


Machine learning tasks are generally categorised into three main areas, which often depends on the type of data that is being analysed: Supervised learning, unsupervised learning and reinforcement learning.


The methods all differ in how the machine learning algorithm is "rewarded" for being correct in its predictions or classifications.


Supervised Learning - Supervised learning algorithms involve labelled data . That is, data that has been labelled, often manually, with categories (as in supervised classification ) or with numerical responses (as in supervised regression ). Such algorithms are trained on the data and learn which predictors correspond to which responses. When applied to unseen data they attempt to make predictions based on their prior training experience. An example from quantitative finance would be using supervised regression to predict tomorrow's stock price from the previous month's worth of price data.


Unsupervised Learning - Unsupervised learning algorithms do not make use of labelled data. Instead they utilise the underlying structure of the data to identify patterns. The canonical method is unsupervised clustering , which attempts to partition datasets into sub-clusters that are associated in some manner. An example from quantitative finance would be to cluster certain assets into classes that behave similarly to adjust portfolio allocations. Read more about Unsupervised Learning here.


Reinforcement Learning - Reinforcement learning algorithms attempt to perform a task within a certain dynamic environment, by taking actions inside the environment in order to maximise a reward mechanism. These algorithms differ from supervised learning in that there is no direct set of input/output pairs of data. Such algorithms have become famous recently as they have been used by Google DeepMind to exceed human performance in Atari games and the ancient game of Go. Such algorithms have been applied in quant finance to optimise investment portfolios.


Machine Learning Algorithms.


What are the different algorithms?


Due to its interdisciplinary nature there are a large number of differing machine learning algorithms. Most have arisen from the computer science, engineering and statistics communities.


The list of machine learning algorithms is almost endless, as they include crossover techniques and ensembles of many other algorithms. However, the algorithms frequently used within quantitative finance are listed below:


Linear Regression - An elementary supervised technique from classical statistics that finds an optimal linear response surface from a set of labelled predictor-response pairs. Linear Classification - These supervised techniques classify data into groups, rather than predict numerical responses. Common techniques include Logistic Regression, Linear Discriminant Analysis and Naive Bayes Classification. Tree-Based Methods - Decision trees are a supervised technique that partition the predictor/feature space into hypercubic subsets. Ensembles of decision trees include Random Forests. Support Vector Machines - SVMs are a supervised technique that attempts to create a linear separation boundary in higher-dimensional space than the original problem in order to deal with non-linear separation. Artificial Neural Networks/Deep Learning - Neural networks are a supervised technique that create hierarchies of activation "neurons" that can approximate high-dimensional non-linear functions. "Deep" networks make use of many hidden layers of neurons to form hierarchical representations for state-of-the-art classification performance. Bayesian Networks - Bayesian Networks or "Bayes Nets" are a type of probabilistic graphical model that represent probabilistic relationships between variables. They are utilised both for inference and learning applications. Clustering - Clustering is an unsupervised technique that attempts to partition data into subsets according to some similarity criteria. A common technique is K-Means Clustering. Dimensionality Reduction - Dimensionality reduction algorithms are unsupervised techniques that attempt to transform the space of predictors/factors into another set that explain the "variation" in the responses with fewer dimensions. Principal Components Analysis is the canonical technique here.


Determining the "best tool for the job" is one of the trickiest aspects of machine learning as applied to quant finance. Many articles on QuantStart discuss this particular point and will guide you to applying the correct technique where appropriate.


مجرد بدء مع التداول الكمي؟


3 أسباب الاشتراك في قائمة البريد الإلكتروني كوانتستارت:


1. دروس التداول الكمي.


سوف تحصل على إمكانية الوصول الفوري إلى دورة مجانية 10-البريد الإلكتروني معبأة مع تلميحات ونصائح لمساعدتك على البدء في التداول الكمي!


2. جميع أحدث المحتوى.


كل أسبوع سوف نرسل لك التفاف جميع الأنشطة على كوانتستارت لذلك عليك أن لا يفوتون وظيفة مرة أخرى.


ريال مدريد، وقابلة للتنفيذ نصائح التداول الكمي مع أي هراء.


Better Strategies 5: A Short-Term Machine Learning System.


It’s time for the 5th and final part of the Build Better Strategies series. In part 3 we’ve discussed the development process of a model-based system, and consequently we’ll conclude the series with developing a data-mining system. The principles of data mining and machine learning have been the topic of part 4. For our short-term trading example we’ll use a deep learning algorithm , a stacked autoencoder, but it will work in the same way with many other machine learning algorithms. With today’s software tools, only about 20 lines of code are needed for a machine learning strategy. I’ll try to explain all steps in detail.


Our example will be a research project – a machine learning experiment for answering two questions. Does a more complex algorithm – such as, more neurons and deeper learning – produce a better prediction? And are short-term price moves predictable by short-term price history? The last question came up due to my scepticism about price action trading in the previous part of this series. I got several emails asking about the “trading system generators” or similar price action tools that are praised on some websites. There is no hard evidence that such tools ever produced any profit (except for their vendors) – but does this mean that they all are garbage? سنرى & # 8217.


Our experiment is simple: We collect information from the last candles of a price curve, feed it in a deep learning neural net, and use it to predict the next candles. My hypothesis is that a few candles don’t contain any useful predictive information. Of course, a nonpredictive outcome of the experiment won’t mean that I’m right, since I could have used wrong parameters or prepared the data badly. But a predictive outcome would be a hint that I’m wrong and price action trading can indeed be profitable.


Machine learning strategy development.


Step 1: The target variable.


To recap the previous part: a supervised learning algorithm is trained with a set of features in order to predict a target variable . So the first thing to determine is what this target variable shall be. A popular target, used in most papers, is the sign of the price return at the next bar. Better suited for prediction, since less susceptible to randomness, is the price difference to a more distant prediction horizon , like 3 bars from now, or same day next week. Like almost anything in trading systems, the prediction horizon is a compromise between the effects of randomness (less bars are worse) and predictability (less bars are better).


Sometimes you’re not interested in directly predicting price, but in predicting some other parameter – such as the current leg of a Zigzag indicator – that could otherwise only be determined in hindsight. Or you want to know if a certain market inefficiency will be present in the next time, especially when you’re using machine learning not directly for trading, but for filtering trades in a model-based system. Or you want to predict something entirely different, for instance the probability of a market crash tomorrow. All this is often easier to predict than the popular tomorrow’s return.


In our price action experiment we’ll use the return of a short-term price action trade as target variable. Once the target is determined, next step is selecting the features.


Step 2: The features.


A price curve is the worst case for any machine learning algorithm. Not only does it carry little signal and mostly noise , it is also nonstationary and the signal/noise ratio changes all the time. The exact ratio of signal and noise depends on what is meant with “signal”, but it is normally too low for any known machine learning algorithm to produce anything useful. So we must derive features from the price curve that contain more signal and less noise. Signal, in that context, is any information that can be used to predict the target, whatever it is. All the rest is noise.


Thus, selecting the features is critical for success – much more critical than deciding which machine learning algorithm you’re going to use. There are two approaches for selecting features. The first and most common is extracting as much information from the price curve as possible. Since you do not know where the information is hidden, you just generate a wild collection of indicators with a wide range of parameters, and hope that at least a few of them will contain the information that the algorithm needs. This is the approach that you normally find in the literature. The problem of this method: Any machine learning algorithm is easily confused by nonpredictive predictors. So it won’t do to just throw 150 indicators at it. You need some preselection algorithm that determines which of them carry useful information and which can be omitted. Without reducing the features this way to maybe eight or ten, even the deepest learning algorithm won’t produce anything useful.


The other approach, normally for experiments and research, is using only limited information from the price curve. This is the case here: Since we want to examine price action trading, we only use the last few prices as inputs, and must discard all the rest of the curve. This has the advantage that we don’t need any preselection algorithm since the number of features is limited anyway. Here are the two simple predictor functions that we use in our experiment (in C):


The two functions are supposed to carry the necessary information for price action: per-bar movement and volatility. The change function is the difference of the current price to the price of n bars before, divided by the current price. The range function is the total high-low distance of the last n candles, also in divided by the current price. And the scale function centers and compresses the values to the +/-100 range, so we divide them by 100 for getting them normalized to +/-1 . We remember that normalizing is needed for machine learning algorithms.


Step 3: Preselecting/preprocessing predictors.


When you have selected a large number of indicators or other signals as features for your algorithm, you must determine which of them is useful and which not. There are many methods for reducing the number of features, for instance:


Determine the correlations between the signals. Remove those with a strong correlation to other signals, since they do not contribute to the information. Compare the information content of signals directly, with algorithms like information entropy or decision trees. Determine the information content indirectly by comparing the signals with randomized signals; there are some software libraries for this, such as the R Boruta package. Use an algorithm like Principal Components Analysis (PCA) for generating a new signal set with reduced dimensionality. Use genetic optimization for determining the most important signals just by the most profitable results from the prediction process. Great for curve fitting if you want to publish impressive results in a research paper.


For our experiment we do not need to preselect or preprocess the features, but you can find useful information about this in articles (1), (2), and (3) listed at the end of the page.


Step 4: Select the machine learning algorithm.


R offers many different ML packages, and any of them offers many different algorithms with many different parameters. Even if you already decided about the method – here, deep learning – you have still the choice among different approaches and different R packages. Most are quite new, and you can find not many empirical information that helps your decision. You have to try them all and gain experience with different methods. For our experiment we’ve choosen the Deepnet package, which is probably the simplest and easiest to use deep learning library. This keeps our code short. We’re using its Stacked Autoencoder ( SAE ) algorithm for pre-training the network. Deepnet also offers a Restricted Boltzmann Machine ( RBM ) for pre-training, but I could not get good results from it. There are other and more complex deep learning packages for R, so you can spend a lot of time checking out all of them.


How pre-training works is easily explained, but why it works is a different matter. As to my knowledge, no one has yet come up with a solid mathematical proof that it works at all. Anyway, imagine a large neural net with many hidden layers:


Training the net means setting up the connection weights between the neurons. The usual method is error backpropagation. But it turns out that the more hidden layers you have, the worse it works. The backpropagated error terms get smaller and smaller from layer to layer, causing the first layers of the net to learn almost nothing. Which means that the predicted result becomes more and more dependent of the random initial state of the weights. This severely limited the complexity of layer-based neural nets and therefore the tasks that they can solve. At least until 10 years ago.


In 2006 scientists in Toronto first published the idea to pre-train the weights with an unsupervised learning algorithm, a restricted Boltzmann machine. This turned out a revolutionary concept. It boosted the development of artificial intelligence and allowed all sorts of new applications from Go-playing machines to self-driving cars. In the case of a stacked autoencoder, it works this way:


Select the hidden layer to train; begin with the first hidden layer. Connect its outputs to a temporary output layer that has the same structure as the network’s input layer. Feed the network with the training samples, but without the targets. Train it so that the first hidden layer reproduces the input signal – the features – at its outputs as exactly as possible. The rest of the network is ignored. During training, apply a ‘weight penalty term’ so that as few connection weights as possible are used for reproducing the signal. Now feed the outputs of the trained hidden layer to the inputs of the next untrained hidden layer, and repeat the training process so that the input signal is now reproduced at the outputs of the next layer. Repeat this process until all hidden layers are trained. We have now a ‘sparse network’ with very few layer connections that can reproduce the input signals. Now train the network with backpropagation for learning the target variable, using the pre-trained weights of the hidden layers as a starting point.


The hope is that the unsupervised pre-training process produces an internal noise-reduced abstraction of the input signals that can then be used for easier learning the target. And this indeed appears to work. No one really knows why, but several theories – see paper (4) below – try to explain that phenomenon.


Step 5: Generate a test data set.


We first need to produce a data set with features and targets so that we can test our prediction process and try out parameters. The features must be based on the same price data as in live trading, and for the target we must simulate a short-term trade. So it makes sense to generate the data not with R, but with our trading platform, which is anyway a lot faster. Here’s a small Zorro script for this, DeepSignals. c :


We’re generating 2 years of data with features calculated by our above defined change and range functions. Our target is the result of a trade with 3 bars life time. Trading costs are set to zero, so in this case the result is equivalent to the sign of the price difference at 3 bars in the future. The adviseLong function is described in the Zorro manual; it is a mighty function that automatically handles training and predicting and allows to use any R-based machine learning algorithm just as if it were a simple indicator.


In our code, the function uses the next trade return as target, and the price changes and ranges of the last 4 bars as features. The SIGNALS flag tells it not to train the data, but to export it to a. csv file. The BALANCED flag makes sure that we get as many positive as negative returns; this is important for most machine learning algorithms. Run the script in [Train] mode with our usual test asset EUR/USD selected. It generates a spreadsheet file named DeepSignalsEURUSD_L. csv that contains the features in the first 8 columns, and the trade return in the last column.


Step 6: Calibrate the algorithm.


Complex machine learning algorithms have many parameters to adjust. Some of them offer great opportunities to curve-fit the algorithm for publications. Still, we must calibrate parameters since the algorithm rarely works well with its default settings. For this, here’s an R script that reads the previously created data set and processes it with the deep learning algorithm ( DeepSignal. r ):


We’ve defined three functions neural. train , neural. predict , and neural. init for training, predicting, and initializing the neural net. The function names are not arbitrary, but follow the convention used by Zorro’s advise(NEURAL. ) function. It doesn’t matter now, but will matter later when we use the same R script for training and trading the deep learning strategy. A fourth function, TestOOS , is used for out-of-sample testing our setup.


The function neural. init seeds the R random generator with a fixed value (365 is my personal lucky number). Otherwise we would get a slightly different result any time, since the neural net is initialized with random weights. It also creates a global R list named “Models”. Most R variable types don’t need to be created beforehand, some do (don’t ask me why). The ‘<<-‘ operator is for accessing a global variable from within a function.


The function neural. train takes as input a model number and the data set to be trained. The model number identifies the trained model in the “ Models ” قائمة. A list is not really needed for this test, but we’ll need it for more complex strategies that train more than one model. The matrix containing the features and target is passed to the function as second parameter. If the XY data is not a proper matrix, which frequently happens in R depending on how you generated it, it is converted to one. Then it is split into the features ( X ) and the target ( Y ), and finally the target is converted to 1 for a positive trade outcome and 0 for a negative outcome.


The network parameters are then set up. Some are obvious, others are free to play around with:


The network structure is given by the hidden vector: c(50,100,50) defines 3 hidden layers, the first with 50, second with 100, and third with 50 neurons. That’s the parameter that we’ll later modify for determining whether deeper is better. The activation function converts the sum of neuron input values to the neuron output; most often used are sigmoid that saturates to 0 or 1, or tanh that saturates to -1 or +1.


We use tanh here since our signals are also in the +/-1 range. The output of the network is a sigmoid function since we want a prediction in the 0..1 range. But the SAE output must be “linear” so that the Stacked Autoencoder can reproduce the analog input signals on the outputs.


The learning rate controls the step size for the gradient descent in training; a lower rate means finer steps and possibly more precise prediction, but longer training time. Momentum adds a fraction of the previous step to the current one. It prevents the gradient descent from getting stuck at a tiny local minimum or saddle point. The learning rate scale is a multiplication factor for changing the learning rate after each iteration (I am not sure for what this is good, but there may be tasks where a lower learning rate on higher epochs improves the training). An epoch is a training iteration over the entire data set. Training will stop once the number of epochs is reached. More epochs mean better prediction, but longer training. The batch size is a number of random samples – a mini batch – taken out of the data set for a single training run. Splitting the data into mini batches speeds up training since the weight gradient is then calculated from fewer samples. The higher the batch size, the better is the training, but the more time it will take. The dropout is a number of randomly selected neurons that are disabled during a mini batch. This way the net learns only with a part of its neurons. This seems a strange idea, but can effectively reduce overfitting.


All these parameters are common for neural networks. Play around with them and check their effect on the result and the training time. Properly calibrating a neural net is not trivial and might be the topic of another article. The parameters are stored in the model together with the matrix of trained connection weights. So they need not to be given again in the prediction function, neural. predict . It takes the model and a vector X of features, runs it through the layers, and returns the network output, the predicted target Y . Compared with training, prediction is pretty fast since it only needs a couple thousand multiplications. If X was a row vector, it is transposed and this way converted to a column vector, otherwise the nn. predict function won’t accept it.


Use RStudio or some similar environment for conveniently working with R. Edit the path to the. csv data in the file above, source it, install the required R packages (deepnet, e1071, and caret), then call the TestOOS function from the command line. If everything works, it should print something like that:


TestOOS reads first our data set from Zorro’s Data folder. It splits the data in 80% for training ( XY. tr ) and 20% for out-of-sample testing ( XY. ts ). The training set is trained and the result stored in the Models list at index 1. The test set is further split in features ( X ) and targets ( Y ). Y is converted to binary 0 or 1 and stored in Y. ob , our vector of observed targets. We then predict the targets from the test set, convert them again to binary 0 or 1 and store them in Y. pr . For comparing the observation with the prediction, we use the confusionMatrix function from the caret package.


A confusion matrix of a binary classifier is simply a 2×2 matrix that tells how many 0’s and how many 1’s had been predicted wrongly and correctly. A lot of metrics are derived from the matrix and printed in the lines above. The most important at the moment is the 62% prediction accuracy . This may hint that I bashed price action trading a little prematurely. But of course the 62% might have been just luck. We’ll see that later when we run a WFO test.


A final advice: R packages are occasionally updated, with the possible consequence that previous R code suddenly might work differently, or not at all. This really happens, so test carefully after any update.


Step 7: The strategy.


Now that we’ve tested our algorithm and got some prediction accuracy above 50% with a test data set, we can finally code our machine learning strategy. In fact we’ve already coded most of it, we just must add a few lines to the above Zorro script that exported the data set. This is the final script for training, testing, and (theoretically) trading the system ( DeepLearn. c ):


We’re using a WFO cycle of one year, split in a 90% training and a 10% out-of-sample test period. You might ask why I have earlier used two year’s data and a different split, 80/20, for calibrating the network in step 5. This is for using differently composed data for calibrating and for walk forward testing. If we used exactly the same data, the calibration might overfit it and compromise the test.


The selected WFO parameters mean that the system is trained with about 225 days data, followed by a 25 days test or trade period. Thus, in live trading the system would retrain every 25 days, using the prices from the previous 225 days. In the literature you’ll sometimes find the recommendation to retrain a machine learning system after any trade, or at least any day. But this does not make much sense to me. When you used almost 1 year’s data for training a system, it can obviously not deteriorate after a single day. Or if it did, and only produced positive test results with daily retraining, I would strongly suspect that the results are artifacts by some coding mistake.


Training a deep network takes really a long time, in our case about 10 minutes for a network with 3 hidden layers and 200 neurons. In live trading this would be done by a second Zorro process that is automatically started by the trading Zorro. In the backtest, the system trains at any WFO cycle. Therefore using multiple cores is recommended for training many cycles in parallel. The NumCores variable at -1 activates all CPU cores but one. Multiple cores are only available in Zorro S, so a complete walk forward test with all WFO cycles can take several hours with the free version.


In the script we now train both long and short trades. For this we have to allow hedging in Training mode, since long and short positions are open at the same time. Entering a position is now dependent on the return value from the advise function, which in turn calls either the neural. train or the neural. predict function from the R script. So we’re here entering positions when the neural net predicts a result above 0.5.


The R script is now controlled by the Zorro script (for this it must have the same name, NeuralLearn. r , only with different extension). It is identical to our R script above since we’re using the same network parameters. Only one additional function is needed for supporting a WFO test:


The neural. save function stores the Models list – it now contains 2 models for long and for short trades – after every training run in Zorro’s Data folder. Since the models are stored for later use, we do not need to train them again for repeated test runs.


This is the WFO equity curve generated with the script above (EUR/USD, without trading costs):


EUR/USD equity curve with 50-100-50 network structure.


Although not all WFO cycles get a positive result, it seems that there is some predictive effect. The curve is equivalent to an annual return of 89%, achieved with a 50-100-50 hidden layer structure. We’ll check in the next step how different network structures affect the result.


Since the neural. init , neural. train , neural. predict , and neural. save functions are automatically called by Zorro’s adviseLong/adviseShort functions, there are no R functions directly called in the Zorro script. Thus the script can remain unchanged when using a different machine learning method. Only the DeepLearn. r script must be modified and the neural net, for instance, replaced by a support vector machine. For trading such a machine learning system live on a VPS, make sure that R is also installed on the VPS, the needed R packages are installed, and the path to the R terminal set up in Zorro’s ini file. Otherwise you’ll get an error message when starting the strategy.


Step 8: The experiment.


If our goal had been developing a strategy, the next steps would be the reality check, risk and money management, and preparing for live trading just as described under model-based strategy development. But for our experiment we’ll now run a series of tests, with the number of neurons per layer increased from 10 to 100 in 3 steps, and 1, 2, or 3 hidden layers (deepnet does not support more than 3). So we’re looking into the following 9 network structures: c(10), c(10,10), c(10,10,10), c(30), c(30,30), c(30,30,30), c(100), c(100,100), c(100,100,100). For this experiment you need an afternoon even with a fast PC and in multiple core mode. Here are the results (SR = Sharpe ratio, R2 = slope linearity):


We see that a simple net with only 10 neurons in a single hidden layer won’t work well for short-term prediction. Network complexity clearly improves the performance, however only up to a certain point. A good result for our system is already achieved with 3 layers x 30 neurons. Even more neurons won’t help much and sometimes even produce a worse result. This is no real surprise, since for processing only 8 inputs, 300 neurons can likely not do a better job than 100.


استنتاج.


Our goal was determining if a few candles can have predictive power and how the results are affected by the complexity of the algorithm. The results seem to suggest that short-term price movements can indeed be predicted sometimes by analyzing the changes and ranges of the last 4 candles. The prediction is not very accurate – it’s in the 58%..60% range, and most systems of the test series become unprofitable when trading costs are included. Still, I have to reconsider my opinion about price action trading. The fact that the prediction improves with network complexity is an especially convincing argument for short-term price predictability.


It would be interesting to look into the long-term stability of predictive price patterns. For this we had to run another series of experiments and modify the training period ( WFOPeriod in the script above) and the 90% IS/OOS split. This takes longer time since we must use more historical data. I have done a few tests and found so far that a year seems to be indeed a good training period. The system deteriorates with periods longer than a few years. Predictive price patterns, at least of EUR/USD, have a limited lifetime.


Where can we go from here? There’s a plethora of possibilities, for instance:


Use inputs from more candles and process them with far bigger networks with thousands of neurons. Use oversampling for expanding the training data. Prediction always improves with more training samples. Compress time series f. i. with spectal analysis and analyze not the candles, but their frequency representation with machine learning methods. Use inputs from many candles – such as, 100 – and pre-process adjacent candles with one-dimensional convolutional network layers. Use recurrent networks. Especially LSTM could be very interesting for analyzing time series – and as to my knowledge, they have been rarely used for financial prediction so far. Use an ensemble of neural networks for prediction, such as Aronson’s “oracles” and “comitees”.


Papers / Articles.


(3) V. Perervenko, Selection of Variables for Machine Learning.


I’ve added the C and R scripts to the 2018 script repository. You need both in Zorro’s Strategy folder. Zorro version 1.474, and R version 3.2.5 (64 bit) was used for the experiment, but it should also work with other versions.


65 thoughts on “Better Strategies 5: A Short-Term Machine Learning System”


I’ve tested your strategy using 30min AAPL data but “sae. dnn. train” returns all NaN in training.


(It works just decreasing neurons to less than (5,10,5)… but accuracy is 49%)


Can you help me to understand why?


شكرا مقدما.


If you have not changed any SAE parameters, look into the. csv data. It is then the only difference to the EUR/USD test. Maybe something is wrong with it.


Another fantastic article, jcl. Zorro is a remarkable environment for these experiments. Thanks for sharing your code and your approach – this really opens up an incredible number of possibilities to anyone willing to invest the time to learn how to use Zorro.


The problem with AAPL 30min data was related to the normalizing method I used (X-mean/SD).


The features range was not between -1:1 and I assume that sae. dnn need it to work…


Anyway performances are not comparable to yours 🙂


I have one question:


why do you use Zorro for creating the features in the csv file and then opening it in R?


why not create the file with all the features in R in a few lines and do the training on the file when you are already in R? instead of getting inside Zorro and then to R.


When you want R to create the features, you must still transmit the price data and the targets from Zorro to R. So you are not gaining much. Creating the features in Zorro results usually in shorter code and faster training. Features in R make only sense when you need some R package for calculating them.


Really helpful and interesting article! I would like to know if there are any English version of the book:


“Das Börsenhackerbuch: Finanziell unabhängig durch algorithmische Handelssysteme”


I am really interested on it,


Not yet, but an English version is planned.


Thanks JCL! Please let me now when the English version is ready, because I am really interested on it.


Works superbly (as always). تشكرات. One small note, if you have the package “dlm” loaded in R, TestOOS will fail with error: “Error in TestOOS() : cannot change value of locked binding for ‘X'”. This is due to there being a function X in the dlm package, so the name is locked when the package is loaded. Easily fixed by either renaming occurrences of the variable X to something else, or temporarily detaching the dlm package with: detach(“package:dlm”, unload=TRUE)


Thanks for the info with the dlm package. I admit that ‘X’ is not a particular good name for a variable, but a function named ‘X’ in a distributed package is even a bit worse.


Results below were generated by revised version of DeepSignals. r – only change was use of LSTM net from the rnn package on CRAN. The authors of the package regard their LSTM implementation as “experimental” and do not feel it is as yet learning properly, so hopefully more improvement to come there. (Spent ages trying to accomplish the LSTM element using the mxnet package but gave up as couldn’t figure out the correct input format when using multiple training features.)


Will post results of full WFO when I have finished LSTM version of DeepLearn. r.


Confusion Matrix and Statistics.


95% CI : (0.5699, 0.5956)


No Information Rate : 0.5002.


P-Value [Acc > NIR] : <2e-16.


Mcnemar's Test P-Value : 0.2438.


Pos Pred Value : 0.5844.


Neg Pred Value : 0.5813.


Detection Rate : 0.2862.


Detection Prevalence : 0.4897.


Balanced Accuracy : 0.5828.


Results of WFO test below. Again, only change to original files was the use of LSTM in R, rather than DNN+SAE.


Walk-Forward Test DeepLearnLSTMV4 EUR/USD.


Simulated account AssetsFix.


Bar period 1 hour (avg 87 min)


Simulation period 15.05.2017-07.06.2018 (12486 bars)


Test period 04.05.2018-07.06.2018 (6649 bars)


Lookback period 100 bars (4 days)


WFO test cycles 11 x 604 bars (5 weeks)


Training cycles 12 x 5439 bars (46 weeks)


Monte Carlo cycles 200.


Assumed slippage 0.0 sec.


Spread 0.0 pips (roll 0.00/0.00)


Contracts per lot 1000.0.


Gross win/loss 3628$ / -3235$ (+5199p)


Average profit 360$/year, 30$/month, 1.38$/day.


Max drawdown -134$ 34% (MAE -134$ 34%)


Total down time 95% (TAE 95%)


Max down time 5 weeks from Aug 2018.


Max open margin 40$


Max open risk 35$


Trade volume 5710964$ (5212652$/year)


Transaction costs 0.00$ spr, 0.00$ slp, 0.00$ rol.


Capital required 262$


Number of trades 6787 (6195/year, 120/week, 25/day)


Percent winning 57.6%


Max win/loss 16$ / -14$


Avg trade profit 0.06$ 0.8p (+12.3p / -14.8p)


Avg trade slippage 0.00$ 0.0p (+0.0p / -0.0p)


Avg trade bars 1 (+1 / -2)


Max trade bars 3 (3 hours)


Time in market 177%


Max open trades 3.


Max loss streak 17 (uncorrelated 11)


Annual return 137%


Profit factor 1.12 (PRR 1.08)


Sharpe ratio 1.79.


Kelly criterion 2.34.


R2 coefficient 0.435.


Ulcer index 13.3%


Prediction error 152%


Confidence level AR DDMax Capital.


Portfolio analysis OptF ProF Win/Loss Wgt% Cycles.


EUR/USD .219 1.12 3907/2880 100.0 XX/\//\X///


EUR/USD:L .302 1.17 1830/1658 65.0 /\/\//\////


EUR/USD:S .145 1.08 2077/1222 35.0 \//\//\\///


مثير للإعجاب! For a still experimental LSTM implementation that result looks not bad.


Sorry for being completely off topic but could you please point me to the best place where i can learn to code trend lines?? I’m a complete beginner, but from trading experience i see them as an important part of what i would like to build…


Robot Wealth has an algorithmic trading course for that – you can find details on his blog robotwealth/.


I think you misunderstand the meaning pretrening. See my articles mql5/ru/articles/1103.


I think there is more fully described this stage.


I don’t think I misunderstood pretraining, at least not more than everyone else, but thanks for the links!


You can paste your LTSM r code please ?


Could you help me answering some questions?


I have few question below:


1.I want to test Commission mode.


If I use interactive broker, I should set Commission = ? in normal case.


2.If I press the “trade” button, I see the log the script will use DeepLearn_EURUSD. ml.


So real trade it will use DeepLearn_EURUSD. ml to get the model to trade?


And use neural. predict function to trade?


3.If I use the slow computer to train the data ,


I should move DeepLearn_EURUSD. ml to the trade computer?


I test the real trade on my interactive brokers and press the result button.


Can I use Commission=0.60 to train the neural and get the real result?


Result button will show the message below:


Trade Trend EUR/USD.


Bar period 2 min (avg 2 min)


Trade period 02.11.2018-02.11.2018.


Spread 0.5 pips (roll -0.02/0.01)


Contracts per lot 1000.0.


Commission should be normally not set up in the script, but entered in the broker specific asset list. Otherwise you had to change the script every time when you want to test it with a different broker or account. IB has different lot sizes and commissions, so you need to add the command.


to the script when you want to test it for an IB account.


Yes, DeepLearn_EURUSD. ml is the model for live trading, and you need to copy it to the trade computer.


Do I write assetList(“AssetsIB. csv”) in the right place?


So below code’s result includes Commission ?


I test the result with Commission that seems pretty good.


Annual +93% +3177p.


BarPeriod = 60; // 1 hour.


WFOPeriod = 252*24; // 1 year.


NumCores = -1; // use all CPU cores but one.


Spread = RollLong = RollShort = Commission = Slippage = 0;


if(Train) Hedge = 2;


I run the DeepLearn. c in the IB paper trade.


The code “LifeTime = 3; // prediction horizon” seems to close the position that you open after 3 bars(3 hours).


But I can’t see it close the position on third bar close.


I see the logs below:


Closing prohibited – check NFA flag!


[EUR/USD::L4202] Can’t close 1@1.10995 at 09:10:51.


In my IB paper trade, it the default order size is 1k on EUR/USD.


How to change the order size in paper trade?


شكرا جزيلا.


IB is an NFA compliant broker. You can not close trades on NFA accounts. You must set the NFA flag for opening a reverse position instead. And you must enable trading costs, otherwise including the commission has no effect. I don’t think that you get a positive result with trading costs.


Those account issues are not related to machine learning, and are better asked on the Zorro forum. Or even better, read the Zorro manual where all this is explained. Just search for “NFA”.


I do some experiment to change the neural’s parameter with commission.


The code is below:


BarPeriod = 60; // 1 hour.


WFOPeriod = 252*24; // 1 year.


NumCores = -1; // use all CPU cores but one.


Spread = RollLong = RollShort = Slippage = 0;


if(Train) Hedge = 2;


I get the result with commission that Annual Return is about +23%.


But I don’t complete understand the zorro’s setting and zorro’s report.


Walk-Forward Test DeepLearn EUR/USD.


Simulated account AssetsIB. csv.


Bar period 1 hour (avg 86 min)


Simulation period 15.05.2017-09.09.2018 (14075 bars)


Test period 23.04.2018-09.09.2018 (8404 bars)


Lookback period 100 bars (4 days)


WFO test cycles 14 x 600 bars (5 weeks)


Training cycles 15 x 5401 bars (46 weeks)


Monte Carlo cycles 200.


Simulation mode Realistic (slippage 0.0 sec)


Spread 0.0 pips (roll 0.00/0.00)


Contracts per lot 20000.0.


Gross win/loss 24331$ / -22685$ (+914p)


Average profit 1190$/year, 99$/month, 4.58$/day.


Max drawdown -1871$ 114% (MAE -1912$ 116%)


Total down time 92% (TAE 41%)


Max down time 18 weeks from Dec 2018.


Max open margin 2483$


Max open risk 836$


Trade volume 26162350$ (18916130$/year)


Transaction costs 0.00$ spr, 0.00$ slp, 0.00$ rol, -1306$ com.


Capital required 5239$


Number of trades 1306 (945/year, 19/week, 4/day)


Percent winning 52.5%


Max win/loss 375$ / -535$


Avg trade profit 1.26$ 0.7p (+19.7p / -20.3p)


Avg trade slippage 0.00$ 0.0p (+0.0p / -0.0p)


Avg trade bars 2 (+2 / -3)


Max trade bars 3 (3 hours)


Time in market 46%


Max open trades 3.


Max loss streak 19 (uncorrelated 10)


Annual return 23%


Profit factor 1.07 (PRR 0.99)


Sharpe ratio 0.56.


Kelly criterion 1.39.


R2 coefficient 0.000.


Ulcer index 20.8%


Confidence level AR DDMax Capital.


10% 29% 1134$ 4153$


20% 27% 1320$ 4427$


30% 26% 1476$ 4656$


40% 24% 1649$ 4911$


50% 23% 1767$ 5085$


60% 22% 1914$ 5301$


70% 21% 2245$ 5789$


80% 19% 2535$ 6216$


90% 16% 3341$ 7403$


95% 15% 3690$ 7917$


100% 12% 4850$ 9625$


Portfolio analysis OptF ProF Win/Loss Wgt% Cycles.


EUR/USD .256 1.07 685/621 100.0 /X/XXXXXXXXXXX.


The manual is your friend:


Great read…I built this framework to use XGB to analyze live ETF price movements. Let me know what you think:


Hi, deep learning researcher and programmer here. 🙂


Great blog and great article, congratulations! I have some comments:


& # 8211؛ if you use ReLUs as activation functions, pretraining is not necessary.


& # 8211؛ AE is genarraly referred to as networks with same input and output, I would call the proposed network rather a MLP (multi-layer perceptron).


Do you think it is possible to use Python (like TensorFlow) or LUA (like Torch7) based deep learing libraries with Zorro?


I have also heard that ReLUs make a network so fast that you can brute force train it in some cases, with no pretraining. But I have not yet experimented with that. The described network is commonly called ‘SAE’ since it uses autoencoders, with indeed the same number of inputs and outputs, for the pre-training process. & # 8211؛ I am not familiar with Torch7, but you can theoretically use Tensorflow with Zorro with a DLL based interface. The network structure must still be defined in Python, but Zorro can use the network for training and prediction.


Would you do YouTube Tutorials to your work, this series of articles. And where can I subscribe this kinda of algorithmic trading tutorials. Thanks for your contribution.


I would do YouTube tutorials if someone payed me very well for them. Until then, you can subscribe this blog with the link on the right above.


Why not feed economic data from a calendar like forexfactory into the net as well? I suggested that several times before. This data is what makes me a profitable manual trader (rookie though), if there is any intelligence in these neuronal networks it should improve performance greatly. input must be name (non farm payrolls for example or some unique identifier) , time left to release, predicted value (like 3-5 days before) last value and revision. Some human institutional traders claim its possible to trade profitably without a chart from this data alone. Detecting static support and resistance areas (horizontal lines) should be superior to any simple candle patterns. It can be mathematically modeled, as the Support and Resistance indicator from Point Zero Trading proves. Unfortunately i dont have a clue how Arturo the programmer did it. I imagine an artificial intelligence actually “seeing” what the market is focussed on (like speculation on a better than expected NFP report based on other positive Data in the days before, driving the dollar up into the report). “seeing” significant support and resistance levels should allow for trading risk, making reasonable decisions on where to place SL and TP.


We also made the experience that well chosen external data, not derived from the price curve, can improve the prediction. There is even a trading system based on Trump’s twitter outpourings. I can’t comment on support and resistance since I know no successful systems that use them, and am not sure that they exist at all.


thank you very much for everything that you did so far.


I read the book (German here, too) and am working through your blog articles right now.


I already learnt a lot and still am learning more and more about the really important stuff (other than: Your mindset must be perfect and you need to have well-defined goals. I never was a fan of such things and finally I found someone that is on the same opinion and actually teaches people how to correctly do it).


So, thank you very much and thanks in advance for all upcoming articles that I will read and you will post.


As a thank you I was thinking about sending you a corrected version of your book (there are some typos and wrong articles here and there…). Would you be interested in that?


Again thank you for everything and please keep up the good work.


شكر! And I’m certainly interested in a list of all my mistakes.


Thank you for this interesting post. I ran it on my pc and obtained similar results as yours. Then I wanted to see if it could perform as well when commission and rollover and slippage were included during test. I used the same figures as the ones used in the workshops and included in the AssetFix. csv file. The modifications I did in your DeepLearn. c file are as follows:


Spread = RollLong = RollShort = Commission = Slippage = 0;


The results then were not as optimistic as without commission:


Walk-Forward Test DeepLearn_realistic EUR/USD.


Simulated account AssetsFix.


Bar period 1 hour (avg 86 min)


Simulation period 09.05.2017-27.01.2017 (16460 bars)


Test period 22.04.2018-27.01.2017 (10736 bars)


Lookback period 100 bars (4 days)


WFO test cycles 18 x 596 bars (5 weeks)


Training cycles 19 x 5367 bars (46 weeks)


Monte Carlo cycles 200.


Simulation mode Realistic (slippage 5.0 sec)


Spread 0.5 pips (roll -0.02/0.01)


Contracts per lot 1000.0.


Gross win/loss 5608$ / -6161$ (-6347p)


Average profit -312$/year, -26$/month, -1.20$/day.


Max drawdown -635$ -115% (MAE -636$ -115%)


Total down time 99% (TAE 99%)


Max down time 85 weeks from Jun 2018.


Max open margin 40$


Max open risk 41$


Trade volume 10202591$ (5760396$/year)


Transaction costs -462$ spr, 46$ slp, -0.16$ rol, -636$ com.


Capital required 867$


Number of trades 10606 (5989/year, 116/week, 24/day)


Percent winning 54.9%


Max win/loss 18$ / -26$


Avg trade profit -0.05$ -0.6p (+11.1p / -14.8p)


Avg trade slippage 0.00$ 0.0p (+1.5p / -1.7p)


Avg trade bars 1 (+1 / -2)


Max trade bars 3 (3 hours)


Time in market 188%


Max open trades 3.


Max loss streak 19 (uncorrelated 12)


Annual return -36%


Profit factor 0.91 (PRR 0.89)


Sharpe ratio -1.39.


Kelly criterion -5.39.


R2 coefficient 0.737.


Ulcer index 100.0%


Confidence level AR DDMax Capital.


Portfolio analysis OptF ProF Win/Loss Wgt% Cycles.


EUR/USD .000 0.91 5820/4786 100.0 XX/\XX\X\X/X/\\X\\


I am a very beginner with Zorro, maybe I did a mistake ? ما رأيك ؟


No, your results look absolutely ok. The predictive power of 4 candles is very weak. This is just an experiment for finding out if price action has any predictive power at all.


Although it apparently has, I have not yet seen a really profitable system with this method. From the machine learning systems that we’ve programmed so far, all that turned out profitable used data from a longer price history.


Thank you for the great article, it’s exactly what I needed in order to start experimenting with ML in Zorro.


I’ve noticed that the results are slightly different each time despite using the random seed. Here it doesn’t matter thanks to the large number of trades but for example with daily bars the performance metrics fluctuate much more. My question is: do you happen to know from where does the randomness come? Is it still the training process in R despite the seed?


It is indeed so. Deepnet apparently uses also an internal function, not only the R random function, for randomizing some initial value.


any idea about how to use machine learning like in this example with indicators? you could do as better strategy 6.


would be very interesting.


Is it grid search inside the neural. train function allowed? I get error when I try it.


Besides Andy, how did you end up definining the LSTM structure using rnn? Is it not clear for me after reading inside the package.


where is the full code?(or where is the repository?)


You said” Use genetic optimization for determining the most important signals just by the most profitable results from the prediction process. Great for curve fitting” How about after using genetic optimization process for determining the most profitable signals , match and measure the most profitable signals with distance metrics/similarity analysis(mutual information, DTW, frechet distance algorithm etc…) then use the distance metrics/similarity analysis as function for neural network prediction? Does that make sense ?


Distance to what? To each other?


Yes find similar profitable signal-patterns in history and find distance between patterns/profitable signals then predict the behavior of the profitable signal in the future from past patterns.


Was wondering about this point you made in Step 5:


“Our target is the return of a trade with 3 bars life time.”


But in the code, doesn’t.


mean that we are actually predicting the SIGN of the return, rather than the return itself?


نعم فعلا. Only the binary win/loss result, but not the magnitude of the win or loss is used for the prediction.


“When you used almost 1 year’s data for training a system, it can obviously not deteriorate after a single day. Or if it did, and only produced positive test results with daily retraining, I would strongly suspect that the results are artifacts by some coding mistake.”


There is an additional trap to be aware of related to jcl’s comment above that applies to supervised machine learning techniques (where you train a model against actual outcomes). Assume you are trying to predict the return three bars ahead (as in the example above – LifeTime = 3;). In real time you obviously don’t have access to the outcomes for one, two and three bars ahead with which to retrain your model, but when using historical data you do. With frequently retrained models (especially if using relatively short blocks of training data) it is easy to train a model offline (and get impressive results) with data you will not have available for training in real time. Then reality kicks in. Therefore truncating your offline training set by N bars (where N is the number of bars ahead you are trying to predict) may well be advisable…


Amazing work, could you please share the WFO code as well. I was able to run the code till neural. save but unable to generate the WFO results.


شكرا جزيلا.


The code above does use WFO.


Dear jcl, in the text you mentioned that you could predict the current leg of zig-zag indicator, could you please elaborate on how to do that? what features and responses would you reccomend?


I would never claim that I could predict the current leg of zigzag indicator. But we have indeed coded a few systems that attempted that. For this, simply use not the current price movement, but the current zigzag slope as a training target. Which parameters you use for the features is completely up to you.


عمل جيد. I was wondering if you ever tried using something like a net long-short ratio of the asset (I. e. the FXCM SSI index – real time live data) as a feature to improve prediction?


Not with the FXCM SSI index, since it is not available as historical data as far as I know. But similar data of other markets, such as order book content, COT report or the like, have been used as features to a machine learning system.


I see, thanks, and whats’s the experience on those? do they have any predictive power? if you know any materials on this, I would be very interested to read it. (fyi, the SSI index can be exported from FXCM Trading Station (daily data from 2003 for most currency pairs)


Thanks for the info with the SSI. Yes, additional market data can have predictive power, especially from the order book. But since we gathered this experience with contract work for clients, I’m not at liberty to disclose details. However we plan an own study with ML evaluation of additional data, and that might result in an article on this blog.


Thanks jcl, looking forward to it! there is a way to record SSI ratios in a CSV file from a LUA Strategy script (FXCM’s scripting language) for live evaluation. happy to give you some details if you decide to evaluate this. (drop me an email) MyFxbook also has a similar indicator, but no historical data on that one unfortunately.


Does random forest algorithm have any advantage over deep net or neural networks for classification problems in financial data? I make it more clear ; I use number of moving averages and oscillators slope colour change for trading decision(buy - sell-hold).Sometimes one oscillator colour change is lagging other is faster etc..There is no problem at picking tops and bottoms but It is quite challenging to know when to hold. Since random forest doesnt’ need normalization, do they have any advantage over deep net or neural networks for classification? Thanks.


This depends on the system and the features, so there is no general answer. In the systems we did so far, a random forest or single decision tree was sometimes indeed better than a standard neural network, but a deep network beats anything, especially since you need not care as much about feature preselection. We meanwhile do most ML systems with deep networks.

No comments:

Post a Comment