Monday, 4 December 2017

الوقت على الانترنت ، سلسلة تجانس - خوارزمية الفوركس


ميتاتريدر 5 - المؤشرات التنبؤات الزمنية للمسلسلات باستخدام التماسك الأسي (مقدمة) أعطت المقالة تسلسل السلاسل الزمنية باستخدام التمهيد الأسي 1 موجزا مختصرا لنماذج تمهيد الأسية، وأوضحت واحدة من النهج الممكنة لتحسين معلمات النموذج، واقترحت في نهاية المطاف وضع مؤشر التنبؤ على أساس نموذج النمو الخطي مع التخميد. تمثل هذه المقالة محاولة لزيادة دقة مؤشر التوقعات هذا إلى حد ما. ومن المعقول التنبؤ بأسعار العملات أو الحصول على توقعات موثوقة إلى حد ما حتى لمدة ثلاث أو أربع خطوات إلى الأمام. ومع ذلك، كما هو الحال في المادة السابقة من هذه السلسلة، فإننا سوف تنتج 12 خطوة قبل التوقعات، يدرك بوضوح أنه سيكون من المستحيل الحصول على نتائج مرضية على هذا الأفق الطويل. ولذلك ينبغي إيلاء الاهتمام الأول للخطوات القليلة الأولى للتنبؤ بأقصر فترات الثقة. وتهدف التوقعات من 10 إلى 12 خطوة إلى الأمام أساسا لبيان الميزات السلوكية من نماذج مختلفة وطرق التنبؤ. وعلى أي حال، يمكن تقييم دقة التنبؤات التي تم الحصول عليها لأي أفق باستخدام حدود فاصل الثقة. وتهدف هذه المادة أساسا إلى إظهار بعض الأساليب التي يمكن أن تساعد على رفع مستوى المؤشر على النحو المبين في المادة 1. وقد تم التعامل مع خوارزمية لإيجاد الحد الأدنى من وظيفة لعدة متغيرات يتم تطبيقها في تطوير المؤشرات في السابق وبالتالي لن يتم وصفها مرارا وتكرارا هنا. لا لإثقال المادة، سيتم الاحتفاظ المدخلات النظرية إلى الحد الأدنى. 1. المؤشر المبدئي سيستخدم مؤشر INDATORES. mq5 (انظر المادة 1) كنقطة انطلاق. لتجميع المؤشر سوف نحتاج IndatorsES. mq5، CIndicatorES. mqh و PowellsMethod. mqh، وكلها تقع في نفس الدليل. يمكن العثور على الملفات في أرشيف files2.zip في نهاية المقالة. دعونا تحديث المعادلات التي تحدد نموذج تمهيد الأسي المستخدمة في تطوير هذا المؤشر - نموذج النمو الخطي مع التخميد. وتكون معلمة المدخلات الوحيدة للمؤشر هي القيمة التي تحدد طول الفاصل الزمني الذي يتم بموجبه تحسين معلمات النموذج والقيم الأولية (الفاصل الزمني للدراسة) المحدد. وبعد تحديد القيم المثلى لمعلمات النموذج في فترة زمنية معينة والحسابات المطلوبة، يتم إعداد التنبؤ وفترة الثقة والخط المقابل لتوقعات خطوة واحدة. في كل شريط جديد، يتم تحسين المعلمات ويتم التنبؤ. وبما أن المؤشر المعني سوف يتم ترقيته، سيتم تقييم تأثير التغييرات التي سنقوم بها باستخدام تسلسل الاختبار من أرشيف Files2.zip الموجود في نهاية المقال. يحتوي أرشيف الدليل Dataset2 على ملفات مع اليورو مقابل الدولار الأميركي، أوسشف، أوسجبي يقتبس ومؤشر الدولار الأمريكي دكسي. كل واحد منها يتم توفيره لثلاثة أطر زمنية، وهي M1، H1 و D1. توجد القيم المفتوحة المحفوظة في الملفات بحيث تكون أحدث قيمة في نهاية الملف. يحتوي كل ملف على 1200 عنصر. سيتم تقدير أخطاء التنبؤ بحساب معامل الخطأ النسبة المئوية المطلقة (ميب) دعونا نقسم كل من تسلسل الاختبار الاثني عشر إلى 50 مقطع متداخل يحتوي على 80 عنصرا لكل منها ويحسب قيمة ماب لكل واحد منها. وسيستخدم متوسط ​​التقديرات التي تم الحصول عليها على هذا النحو كمؤشر للخطأ المتعلق بالتنبؤ فيما يتعلق بالمؤشرات الموضوعة للمقارنة. سيتم حساب قيم ميب لخطأ التنبؤ المسبق من خطوتين وثلاث خطوات بنفس الطريقة. وستتم الإشارة إلى هذه التقديرات المتوسطة على النحو التالي: التقدير المتوسط ​​المتوسط ​​لخطأ التنبؤ خطوة واحدة إلى الأمام MAPE2 تقدير متوسط ​​الخطأ المتوقع في خطوتين MAPE3 تقدير متوسط ​​الخطأ المتوقع في الخطوات الثلاث MAPE1-3 المتوسط (MAPE1MAPE2MAPE3) 3. وعند حساب قيمة ميب، تكون قيمة خطأ التنبؤ المطلق في كل خطوة مقسومة على القيمة الحالية للتسلسل. من أجل تجنب الانقسام بمقدار صفر أو الحصول على قيم سلبية في القيام بذلك، مطلوب تسلسل المدخلات لاتخاذ القيم الإيجابية غير الصفرية فقط، كما هو الحال في حالتنا. يتم عرض القيم التقديرية لمؤشرنا المبدئي في الجدول 1. الجدول 1. تقديرات خطأ التنبؤ المبدئي للمؤشر يتم الحصول على البيانات المعروضة في الجدول 1 باستخدام البرنامج النصي ErrorsIndicatorES. mq5 (من أرشيف files2.zip الموجود في نهاية المقالة) . لتجميع وتشغيل البرنامج النصي، فمن الضروري أن CIndicatorES. mqh و PowellsMethod. mqh تقع في نفس الدليل كما ErrorsIndicatorES. mq5، وتسلسل الإدخال في الدليل FilesDataset2. وبعد الحصول على التقديرات الأولية لأخطاء التنبؤ، يمكننا الآن الشروع في رفع مستوى المؤشر قيد النظر. 2. معيار التحسين المعلمات النموذجية في المؤشر الأولي كما هو مبين في المقالة تم تحديد سلسلة الوقت التنبؤ باستخدام التماسك الأسي عن طريق التقليل من مجموع مربعات الخطأ التنبؤ خطوة واحدة إلى الأمام. ويبدو من المنطقي أن المعلمات النموذجية الأمثل لتوقعات خطوة واحدة إلى الأمام قد لا تسفر عن أخطاء دنيا لتوقعات أكثر خطوة. وسيكون من المستصوب، بطبيعة الحال، تقليل أخطاء التنبؤ من 10 إلى 12 خطوة إلى أدنى حد، ولكن الحصول على نتيجة مرضية للتنبؤ على المدى المحدد للتسلسل قيد النظر سيكون من المستحيل القيام به. كونها واقعية، عند تحسين المعلمات نموذج، وسوف نستخدم مجموع المربعات من واحد، واثنين من ثلاث خطوات قبل التنبؤ الأخطاء كما الترقية الأولى من مؤشرنا. ومن المتوقع أن ينخفض ​​متوسط ​​عدد الأخطاء إلى حد ما على مدى الخطوات الثلاث الأولى للتنبؤ. ومن الواضح أن هذا التحديث للمؤشر الأولي لا يتعلق بمبادئه الهيكلية الرئيسية ولكنه يغير معيار تحسين المعلمة فقط. لذلك لا يمكننا أن نتوقع دقة التنبؤ لزيادة عدة أضعاف على الرغم من أن عدد من اثنين وثالثة خطوة قبل التوقعات الأخطاء يجب أن تنخفض قليلا. من أجل مقارنة نتائج التنبؤ، أنشأنا فئة CMod1 مماثلة للطبقة سينديكاتوريس قدم في المادة السابقة مع وظيفة الهدف المعدلة فونك. الدالة فونك للطبقة سينديكاتوريس الأولية: بعد بعض التعديلات، تظهر الدالة فونك الآن على النحو التالي: عند حساب دالة الهدف، يستخدم مجموع مربعات أخطاء التنبؤ ذات الخط الواحد والثاني والخطوة الثلاث. وعلاوة على ذلك، استنادا إلى هذه الفئة تم تطوير البرنامج النصي ErrorsMod1.mq5 السماح لتقدير أخطاء التنبؤ، مثل المذكورة بالفعل ErrorsIndicatorES. mq5 النصي. توجد CMod1.mqh و ErrorsMod1.mq5 في أرشيف files2.zip في نهاية المقالة. ويعرض الجدول 2 تقديرات الأخطاء المتوقعة للنسخ الأولية والمحدثة. الجدول 2. مقارنة تقديرات الأخطاء المتوقعة كما يتبين من ذلك، فإن معاملي الخطأ MAPE2 و MAPE3 والقيمة المتوسطة MAPE1-3 قد اتضح أنهما أقل قليلا بالنسبة للتتابعات قيد النظر. لذلك دعونا حفظ هذا الإصدار والمضي قدما في مزيد من التعديل من مؤشرنا. 3. تعديل المعلمات في عملية تمهيد فكرة تغيير المعلمات تمهيد اعتمادا على القيم الحالية لتسلسل المدخلات ليست جديدة أو أصلية ويأتي من الرغبة في ضبط معاملات تمهيد بحيث تظل الأمثل نظرا لأي تغيير في طبيعة تسلسل المدخلات. بعض الطرق لضبط معاملات التمهيد موصوفة في الأدبيات 2، 3. لمزيد من ترقية المؤشر، سوف نستخدم النموذج مع تغيير ديناميكي معامل التمهيد المتوقع أن استخدام نموذج التكيف الأسي التكيفي سوف يسمح لنا لزيادة دقة التنبؤ من مؤشرنا. لسوء الحظ، عندما تستخدم في خوارزميات التنبؤ، فإن غالبية أساليب التكيف لا تسفر دائما عن النتائج المرجوة. قد يبدو اختيار طريقة التكيف كافية لتكون مرهقة جدا وتستغرق وقتا طويلا وبالتالي في حالتنا سوف نستفيد من النتائج الواردة في الأدب 4 ومحاولة لتوظيف الانتقال السلس التحول الأسي (ستيس) المنصوص عليها في المادة 5 ، وقد تم توضيح جوهر المقاربة بوضوح في المادة المحددة، لذلك سنتركها هنا وننتقل مباشرة إلى معادلات نموذجنا (انظر بداية المقال المحدد) مع الأخذ بعين الاعتبار استخدام معامل التجانس التكيفي. كما نستطيع الآن أن نرى، يتم حساب قيمة معامل تمهيد ألفا في كل خطوة من خوارزمية ويعتمد على خطأ التنبؤ التربيعي. وتحدد قيم المعاملات b و g تأثير الخطأ المتوقع على قيمة ألفا. وفي جميع الجوانب الأخرى، ظلت معادلات النموذج المستخدم دون تغيير. ويمكن الاطلاع على معلومات إضافية بشأن استخدام النهج ستيس في المادة 6. في حين أنه في الإصدارات السابقة، كان علينا أن نحدد القيمة المثلى لمعامل ألفا على تسلسل المدخلات معين، وهناك الآن اثنين من معاملات التكيف b و g التي هي تخضع للتحسين وسيتم تحديد قيمة ألفا بشكل حيوي في عملية تمهيد تسلسل المدخلات. يتم تنفيذ هذه الترقية في شكل فئة CMod2. التغييرات الرئيسية (كما في المرة السابقة) تتعلق في المقام الأول وظيفة فونك التي تظهر الآن على النحو التالي. عند تطوير هذه الوظيفة، تم تعديل المعادلة التي تحدد قيمة معامل ألفا بشكل طفيف. وقد تم ذلك لتعيين الحد الأقصى والقيمة الدنيا المسموح بها لهذا المعامل عند 0.05 و 0.95 على التوالي. لتقدير أخطاء التنبؤ، كما كان يفعل سابقا، تم كتابة البرنامج النصي ErrorsMod2.mq5 استنادا إلى فئة CMod2. توجد CMod2.mqh و ErrorsMod2.mq5 في أرشيف files2.zip في نهاية المقالة. وترد نتائج النصي في الجدول 3. الجدول 3. مقارنة تقديرات الأخطاء المتوقعة كما يوحي الجدول 3، فإن استخدام معامل التجانس التكيفي في المتوسط ​​يسمح بزيادة خفض طفيف في أخطاء التنبؤات بالنسبة إلى متواليات الاختبار. وهكذا، بعد اثنين من التحسينات، تمكنا من تقليل معامل الخطأ MAPE1-3 بنحو 2 في المئة. على الرغم من نتيجة الترقية متواضعة نوعا ما، ونحن سوف التمسك النسخة الناتجة وترك المزيد من التحسينات خارج نطاق هذه المادة. وكخطوة تالية، سيكون من المثير للاهتمام محاولة استخدام التحول بوكس-كوكس. ويستخدم هذا التحول في الغالب لتقريب التوزيع التتابعي الأولي للتوزيع الطبيعي. في حالتنا، يمكن أن تستخدم لتحويل تسلسل الأولي، حساب التوقعات و معكوس تحويل التوقعات. وينبغي انتقاء معامل التحويل المطبق في القيام بذلك بحيث يقلل خطأ التنبؤ الناتج. ويمكن الاطلاع على مثال على استخدام التحول بوكس-كوكس في تسلسل التنبؤات في المادة 7. 4. توقعات فترة الثقة تم حساب فترة الثقة المتوقعة في مؤشر INDATORES. mq5 الأولي (المنصوص عليها في المادة السابقة) وفقا للتحليل التعبيرات المستمدة من نموذج التمهيد الأسي المختار 8 - أدت التغييرات التي أجريت في حالتنا إلى تغييرات في النموذج قيد النظر. معامل التمهيد المتغير يجعل من غير المناسب استخدام التعبيرات التحليلية المذكورة أعلاه لتقدير فترة الثقة. وحقيقة أن التعابير التحليلية المستخدمة سابقا مستمدة استنادا إلى افتراض أن توزيع الأخطاء المتوقعة متماثل وطبيعي قد يشكل سببا إضافيا لتغيير طريقة تقدير فترة الثقة. ولا تستوفى هذه المتطلبات لفئتنا من التتابعات وقد لا يكون توزيع الأخطاء المتوقعة طبيعيا ولا متماثلا. وعند تقدير فاصل الثقة في المؤشر الأولي، تم حساب التباين المتوقع في خطأ التنبؤ من خطوة واحدة في المقام الأول من تتابع المدخلات، يليه حساب التباين في مرحلتين أو ثلاث أو أكثر على أساس قيمة التباين في أخطاء التنبؤ التي تم الحصول عليها من خطوة واحدة إلى الأمام باستخدام التعبيرات التحليلية. من أجل تجنب استخدام التعبيرات التحليلية، هناك طريقة بسيطة للخروج حيث يتم حساب التباين لتوقعات اثنين، ثلاثة و أكثر من الأمام قبل مباشرة من تسلسل المدخلات وكذلك التباين خطوة واحدة توقعات - ahead. ومع ذلك، فإن هذا النهج له عيب كبير: ففي تسلسل المدخلات القصيرة، ستكون تقديرات الفاصل الزمني للثقة متناثرة على نطاق واسع، ولن يسمح حساب التباين ومتوسط ​​الخطأ المربعة بتخفيف القيود على الحالة الطبيعية المتوقعة للأخطاء. ويمكن العثور على حل في هذه الحالة في استخدام التمهيد غير اللامتري (إعادة اختزال) 9. وأعرب العمود الفقري للفكرة ببساطة: عندما أخذ العينات بطريقة عشوائية (توزيع موحد) مع استبدال من تسلسل الأولي، وتوزيع توليد ذلك سيكون تسلسل الاصطناعي هو نفسه كما في الأولي. نفترض، لدينا تسلسل مدخلات من أعضاء N من خلال توليد تسلسل شبه عشوائي موزعة بشكل موحد على نطاق 0، N-1 واستخدام هذه القيم كمؤشرات عند أخذ العينات من الصفيف الأولي، يمكننا توليد تسلسل اصطناعي من حد كبير أكبر من الطول الأولي. على الرغم من ذلك، فإن توزيع تسلسل ولدت تكون هي نفسها (تقريبا نفس) من تلك الأولى. ويمكن أن يكون إجراء التمهيد لتقدير فترات الثقة كما يلي: تحديد القيم الأولية المثلى لمعلمات النموذج ومعاملاته ومعاملاته التكيفية من تتابع المدخلات لنموذج التمهيد الأسي المتحصل عليه نتيجة للتعديل. وتحدد المعلمات المثلى، كما كان من قبل، باستخدام الخوارزمية التي توظف طريقة البحث في باول باستخدام معلمات النموذج الأمثل المحددة، تمر بالتتابع الأولي وتشكل مصفوفة من أخطاء التنبؤ بخطوة واحدة. ويكون عدد عناصر الصفيف مساويا لطول تتابع الدخل N محاذاة الأخطاء بطرح القيمة من متوسط ​​كل عنصر من عناصر الخطأ باستخدام مولد التتابع شبه العشوائي، وتوليد مؤشرات في حدود 0، و N-1 واستخدامها لتشكيل تسلسل اصطناعي من الأخطاء 9999 عناصر طويلة (إعادة تشكيل) تشكيل مصفوفة تحتوي على 9999 قيم تسلسل الإدخال شبه عن طريق إدراج القيم من مصفوفة خطأ ولدت اصطناعيا في المعادلات التي تحدد النموذج المستخدم حاليا. وبعبارة أخرى، في حين كان علينا في السابق لإدراج قيم تسلسل المدخلات في المعادلات النموذجية وبالتالي حساب خطأ التنبؤ، والآن يتم إجراء الحسابات العكسية. لكل عنصر من الصفيف، يتم إدراج قيمة الخطأ لحساب قيمة الإدخال. ونتيجة لذلك، نحصل على صفيف من العناصر 9999 التي تحتوي على تسلسل مع نفس التوزيع مثل تسلسل المدخلات في حين يجري من طول كاف لتقدير مباشرة فترات الثقة التنبؤ. ثم تقدير فترات الثقة باستخدام تسلسل ولدت من طول مناسب. لهذا الغرض، سوف نستغل حقيقة أنه إذا تم تصنيف مجموعة خطأ التنبؤ ولدت بترتيب تصاعدي، فإن خلايا الصفيف مع المؤشرات 249 و 9749 للمصفوفة التي تحتوي على 9999 قيم سيكون لها القيم المقابلة للحدود 95 فترة الثقة 10 ومن أجل الحصول على تقدير أكثر دقة لفترات التنبؤ، يكون طول الصفيف غريبا. في حالتنا، يتم تقدير حدود فترات الثقة المتوقعة على النحو التالي: استخدام معلمات النموذج الأمثل كما هو محدد سابقا، انتقل من خلال تسلسل ولدت وتشكيل مصفوفة من 9999 أخطاء خطوة واحدة قبل التوقعات فرز الصفيف الناتج من فرز ، حدد القيم باستخدام الرقمين 249 و 9749 اللذين يمثلان حدود فاصل الثقة 95 كرر الخطوات 1 و 2 و 3 لأخطاء التنبؤ مرتين أو ثلاث أو أكثر. هذا النهج لتقدير فترات الثقة له مزاياه وعيوبه. ومن مزاياه غياب الافتراضات المتعلقة بطبيعة توزيع أخطاء التنبؤ. ولا يلزم توزيعها بشكل طبيعي أو بشكل متناظر. وبالإضافة إلى ذلك، قد يكون هذا النهج مفيدا حيث يستحيل استخلاص أشكال تحليلية للنموذج المستخدم. ويمكن اعتبار الزيادة الهائلة في النطاق المطلوب من الحسابات واعتماد التقديرات على نوعية مولد التتابع شبه العشوائي مساوئه. إن النهج المقترح لتقدير فترات الثقة باستخدام إعادة الخلط والكميات بدائي نوعا ما ويجب أن يكون هناك طرق لتحسينه. ولكن بما أن فترات الثقة في حالتنا مخصصة فقط للتقييم البصري، فإن الدقة التي يوفرها النهج أعلاه قد تبدو كافية تماما. 5. نسخة معدلة من المؤشر مع الأخذ بعين الاعتبار التحسينات التي أدخلت في هذه المادة، تم تطوير مؤشر ForecastES. mq5. ولإعادة التشكيل، استخدمنا مولد التتابع شبه العشوائي المقترح في وقت سابق في المادة 11. وقد أدى مولد ماثراند القياسي () إلى نتائج أقل فقرا، ربما يرجع ذلك إلى حقيقة أن مجموعة القيم التي ولدها 0،32767 لم تكن واسعة بما فيه الكفاية. عند تجميع مؤشر ForecastES. mq5، PAellsMethod. mqh، CForees. mqh و RNDXor128.mqh يجب أن يكون موجودا في نفس الدليل معها. كل هذه الملفات يمكن العثور عليها في الأرشيف fore. zip. أدناه هو شفرة المصدر من مؤشر ForecastES. mq5. ولأغراض إيضاحية أفضل، تم تنفيذ المؤشر، قدر الإمكان، كقاعدة خط مستقيم. لم يكن المقصود من التحسين أثناء ترميزه. ويبين الشكلان 1 و 2 نتائج تشغيل المؤشر لحالتين مختلفتين. الشكل 1. مثال العملية الأولى من مؤشر ForecastES. mq5 الشكل 2. مثال العملية الثانية من مؤشر ForecastES. mq5 ويبين الشكل 2 بوضوح أن 95 فترة الثقة التنبؤ غير متماثلة. ويرجع ذلك إلى أن تسلسل المدخلات يحتوي على قيم متطرفة كبيرة أدت إلى توزيع غير متناظر لأخطاء التنبؤ. أما المواقع الإلكترونية mql4 و mql5 فقد قدمت في وقت سابق مؤشرات استقراء. دعونا نأخذ واحدة من تلك - arextrapolatorofprice. mq5 وتعيين قيم المعلمة كما هو مبين في الشكل (3) لمقارنة نتائجها مع النتائج التي تم الحصول عليها باستخدام مؤشر وضعنا. الشكل 3. إعدادات مؤشر arextrapolatorofprice. mq5 تمت مقارنة تشغيل هذين المؤشرين بصريا على أطر زمنية مختلفة ل يوروس و أوسشف. على السطح، يبدو أن اتجاه التوقعات من كلا المؤشرين يتزامن في معظم الحالات. ومع ذلك، في ملاحظات أطول، قد تأتي واحدة عبر الاختلافات الخطيرة. أن يقال، arextrapolatorofprice. mq5 سوف تنتج دائما خط التنبؤ أكثر كسر. ويرد مثال على التشغيل في وقت واحد من ForecastES. mq5 ومؤشرات arextrapolatorofprice. mq5 في الشكل 4. الشكل 4. مقارنة نتائج التنبؤ يتم عرض التوقعات التي تنتجها مؤشر arextrapolatorprpr. mq5 في الشكل 4 كخط برتقالي أحمر ثابت. الخلاصة ملخص النتائج المتعلقة بهذا الموضوع والمادة السابقة: تم إدخال نماذج التجانس الأسي المستخدمة في التنبؤ بالسلاسل الزمنية تم اقتراح حلول برمجة لتنفيذ النماذج كانت هناك نظرة سريعة على القضايا المتعلقة باختيار القيم الأولية النموذجية والمعلمات النموذجية نظرا لتنفيذ البرمجة من الخوارزمية لإيجاد الحد الأدنى من وظيفة من عدة متغيرات باستخدام طريقة باولز وقدمت حلول البرمجة لتحسين المعلمة من نموذج التنبؤ باستخدام تسلسل المدخلات المقترحة وأظهرت بعض الأمثلة البسيطة لرفع مستوى خوارزمية التنبؤ وهناك طريقة ل تقدير فترات الثقة المتوقعة باستخدام بوتسترابينغ و كوانتيليز تم توضيحها بإيجاز تم تطوير مؤشر التوقعات ForecastES. mq5 الذي يحتوي على جميع الأساليب والخوارزميات الموصوفة في المقالات تم إعطاء عدد قليل من الروابط إلى المقالات والمجلات والكتب المتعلقة بهذا الموضوع. وفيما يتعلق بالمؤشر الناتج ForecastES. mq5، تجدر الإشارة إلى أن خوارزمية التحسين التي تستخدم طريقة باول قد تفشل في بعض الحالات في تحديد الحد الأدنى لوظيفة الهدف بدقة معينة. وفي هذه الحالة، سيتم الوصول إلى الحد الأقصى المسموح به من التكرارات وستظهر رسالة ذات صلة في السجل. ومع ذلك، فإن هذه الحالة لا تتم معالجتها بأي شكل من الأشكال في رمز المؤشر المقبول تماما لعرض الخوارزميات المبينة في المادة. ومع ذلك، عندما يتعلق الأمر بتطبيقات خطيرة، يجب رصد هذه الحالات ومعالجتها بطريقة أو بأخرى. ولمواصلة تطوير مؤشر التنبؤ وتحسينه، يمكن أن نقترح استخدام عدة نماذج مختلفة للتنبؤ في وقت واحد في كل خطوة بهدف زيادة اختيار واحد منها باستخدام ومعيار المعلومات أكايكس. أو في حالة استخدام عدة نماذج مماثلة في طبيعتها، لحساب متوسط ​​القيمة المرجحة لنتائج التنبؤ. ويمكن اختيار معاملات الترجيح في هذه الحالة تبعا لمعامل الخطأ المتوقع لكل نموذج. موضوع سلسلة زمنية التنبؤ واسع جدا لدرجة أن هذه المواد بالكاد خدش سطح بعض القضايا ذات الصلة. ومن المأمول فيه أن تساعد هذه المنشورات على استرعاء انتباه القراء إلى مسائل التنبؤ والأعمال المقبلة في هذا المجال. ريسورسميترادر ​​5 - الإحصاء والتحليل سلسلة الوقت التنبؤ باستخدام التمدد الأسي مقدمة هناك حاليا عدد كبير من مختلف أساليب التنبؤ المعروفة التي تقوم فقط على تحليل القيم السابقة من تسلسل زمني، أي الأساليب التي تستخدم المبادئ المستخدمة عادة في التقنية تحليل. والأداة الرئيسية لهذه الأساليب هي مخطط الاستقراء حيث تتجاوز خصائص التتابع المحددة في فترة زمنية معينة حدودها. وفي الوقت نفسه يفترض أن خصائص التسلسل في المستقبل ستكون هي نفسها كما في الماضي والحاضر. وهناك مخطط أكثر تعقيدا لاستقراء ينطوي على دراسة لديناميات التغيرات في خصائص التسلسل مع إيلاء الاعتبار الواجب لهذه الديناميات ضمن فترة التنبؤ أقل استخداما في التنبؤ. وربما تكون أكثر أساليب التنبؤ المعروفة استنادا إلى الاستقراء هي تلك التي تستخدم نموذج المتوسط ​​المتحرك المتكامل الانحداري الذاتي (أريما). وتعزى شعبية هذه الأساليب في المقام الأول إلى الأعمال التي يقوم بها صندوق وجينكينز الذين اقترحوا وتطوير نموذج متكامل أريما. وهناك بالطبع نماذج أخرى وطرق التنبؤ بصرف النظر عن النماذج التي قدمها صندوق وجينكينز. هذه المقالة سوف تغطي لفترة وجيزة نماذج أكثر بساطة - نماذج التمهيد الأسي التي اقترحها هولت وبراون جيدا قبل ظهور أعمال بوكس ​​و جينكينز. على الرغم من الأدوات الرياضية أكثر بساطة وواضحة، والتنبؤ باستخدام نماذج التجانس الأسي غالبا ما يؤدي إلى نتائج قابلة للمقارنة مع النتائج التي تم الحصول عليها باستخدام نموذج أريما. هذا ليس من المستغرب كما نماذج التمهيد الأسي هي حالة خاصة من نموذج أريما. وبعبارة أخرى، فإن كل نموذج تمهيد أسي قيد الدراسة في هذه المقالة يحتوي على نموذج أريما المكافئ المقابل. لن يتم النظر في هذه النماذج المكافئة في المقالة ويتم ذكرها للعلم فقط. ومن المعروف أن التنبؤ في كل حالة معينة يتطلب نهجا فرديا، وعادة ما ينطوي على عدد من الإجراءات. تحليل التسلسل الزمني للقيم المفقودة والقيم المتطرفة. تعديل هذه القيم. تحديد الاتجاه ونوعه. تحديد دورية التتابع. تحقق من ستاتيوناريتي من تسلسل. تسلسل تحليل المعالجة المسبقة (مع اللوغاريتمات، والاختلاف، وما إلى ذلك). اختيار النموذج. تحديد المعلمة النموذجية. التنبؤ استنادا إلى النموذج المحدد. نموذج تقييم دقة التنبؤ. تحليل أخطاء النموذج المختار. تحديد مدى ملاءمة النموذج المختار، واستبدال النموذج، إذا لزم الأمر، والعودة إلى البنود السابقة. وهذه ليست إلى حد بعيد القائمة الكاملة للإجراءات المطلوبة للتنبؤ الفعال. وينبغي التأكيد على أن تحديد معلمات النموذج والحصول على نتائج التنبؤات لا يشكلان إلا جزءا صغيرا من عملية التنبؤ العامة. ولكن يبدو أنه من المستحيل تغطية مجموعة كاملة من المشاكل بطريقة أو بأخرى تتعلق بالتنبؤ في مادة واحدة. وبالتالي فإن هذه المادة فقط التعامل مع نماذج التجانس الأسي واستخدام اقتباسات العملات غير المعالجة مسبقا كتسلسل اختبار. ومن المؤكد أنه لا يمكن تجنب المسائل المصاحبة في المادة تماما، ولكنها لن تطرق إلا بقدر ما تكون ضرورية لاستعراض النماذج. 1. ستاتيوناريتي مفهوم الاستقراء السليم يعني أن التنمية المستقبلية للعملية قيد الدراسة ستكون هي نفسها كما في الماضي والحاضر. وبعبارة أخرى، يتعلق الأمر بحيوية العملية. والعمليات الثابتة جذابة جدا من وجهة نظر التنبؤ، ولكنها للأسف لا توجد في الطبيعة، حيث أن أي عملية حقيقية قابلة للتغيير في سياق تطورها. وقد يكون للعمليات الحقيقية توقعات متباينة بشكل ملحوظ، والتباين والتوزيع على مر الزمن، ولكن العمليات التي تتغير خصائصها ببطء شديد يمكن أن تعزى على الأرجح إلى العمليات الثابتة. ويعني ببطء شديد في هذه الحالة أن التغييرات في خصائص العملية ضمن فترة المراقبة المحدودة تبدو غير ذات أهمية بحيث يمكن إهمال هذه التغييرات. ومن الواضح أن أقصر فترة المراقبة المتاحة (عينة قصيرة)، وارتفاع احتمال اتخاذ قرار خاطئ فيما يتعلق استقرارية العملية ككل. من ناحية أخرى، إذا كنا أكثر اهتماما بحالة العملية في وقت لاحق التخطيط لوضع توقعات على المدى القصير، وانخفاض في حجم العينة قد يؤدي في بعض الحالات إلى زيادة في دقة مثل هذه التوقعات. وإذا كانت العملية خاضعة للتغييرات، فإن معلمات التتابع التي تحدد ضمن فاصل المراقبة، ستكون مختلفة خارج حدودها. وهكذا، وكلما زاد الفاصل الزمني للتنبؤ، كلما كان تأثير تغير خصائص التتابع أقوى على خطأ التنبؤ. وبسبب هذه الحقيقة علينا أن نقتصر على توقعات قصيرة الأجل فقط انخفاض كبير في فترة التنبؤ يسمح للتوقع بأن خصائص تسلسل ببطء المتغير لن يؤدي إلى أخطاء التنبؤ كبيرة. وعلاوة على ذلك، فإن تقلب معلمات التتابع يؤدي إلى حقيقة أن القيمة التي يتم الحصول عليها عند تقدير الفاصل الزمني للمراقبة هي متوسطات، لأن المعلمات لا تظل ثابتة خلال الفاصل الزمني. ولذلك فإن قيم المعلمات التي تم الحصول عليها لن تكون مرتبطة بالحظة الأخيرة من هذه الفاصل الزمني ولكنها تعكس متوسطا معينا منها. لسوء الحظ، فإنه من المستحيل القضاء تماما على هذه الظاهرة غير السارة ولكن يمكن أن تنخفض إذا تم تقليل طول فترة المراقبة المشاركة في تقدير المعلمة نموذج (الفاصل الزمني الدراسة) إلى أقصى حد ممكن. وفي الوقت نفسه، لا يمكن اختصار فترة الدراسة إلى أجل غير مسمى لأنه إذا خفضت للغاية، فإنه بالتأكيد سوف يقلل من دقة تقدير المعلمة تسلسل. وينبغي للمرء أن يسعى إلى التوصل إلى حل توفيقي بين تأثير الأخطاء المرتبطة بتغير خصائص التسلسل وزيادة الأخطاء بسبب الانخفاض الشديد في الفاصل الزمني للدراسة. كل ما سبق ينطبق تماما على التنبؤ باستخدام نماذج التمهيد الأسي لأنها تستند إلى افتراض استقرارية العمليات، مثل نماذج أريما. ومع ذلك، وبغية البساطة، سنفترض فيما بعد تقليديا أن معلمات جميع التتابعات قيد النظر تتفاوت في غضون فترة المراقبة ولكن بطريقة بطيئة يمكن إهمال هذه التغييرات فيها. وهكذا، فإن المادة معالجة القضايا المتعلقة بالتنبؤ على المدى القصير من تسلسل مع خصائص متغيرة ببطء على أساس نماذج التمهيد الأسي. وينبغي للتنبؤ على المدى القصير في هذه الحالة أن يعني التنبؤ بفترة زمنية واحدة أو أكثر أو أكثر بدلا من التنبؤ لفترة تقل عن سنة كما يفهم عادة في الاقتصاد. 2. تسلسل اختبار عند كتابة هذه المقالة، تم حفظها مسبقا ورور، اليورو مقابل الدولار الأميركي، أوسجبي ونقلت شوس لل M1، M5، M30 و H1. يحتوي كل من الملفات المحفوظة على 1100 قيمة مفتوحة. توجد أقدم قيمة في بداية الملف وآخرها في النهاية. تقابل القيمة الأخيرة المحفوظة في الملف الوقت الذي تم فيه إنشاء الملف. تم إنشاء الملفات التي تحتوي على تسلسل اختبار باستخدام البرنامج النصي HistoryToCSV. mq5. توجد ملفات البيانات والنصوص التي تم إنشاؤها في نهاية المقالة في أرشيف Files. zip. كما سبق ذكره، يتم استخدام علامات الاقتباس المحفوظة في هذه المقالة دون أن يتم معالجتها مسبقا على الرغم من المشاكل الواضحة التي أود أن أوجه انتباهكم إليها. على سبيل المثال، يقتبس سعر EURRURH1 خلال اليوم من 12 إلى 13 بار، فإن عروض أسعار الدولار الأمريكي مقابل الدولار الأمريكي يوم الجمعة تحتوي على شريط واحد أقل من الأيام الأخرى. هذه الأمثلة تثبت أن يتم إنتاج علامات الاقتباس مع فاصل أخذ العينات غير النظامية وهذا أمر غير مقبول تماما للخوارزميات المصممة للعمل مع تسلسل الوقت الصحيح التي تشير إلى وجود فترة تكميم موحدة. وحتى إذا تم استنساخ قيم الاقتباس المفقودة باستخدام الاستقراء، فإن المسألة المتعلقة بعدم وجود علامات اقتباس في عطلة نهاية الأسبوع لا تزال مفتوحة. يمكننا أن نفترض أن الأحداث التي تحدث في العالم في عطلة نهاية الأسبوع لها نفس التأثير على الاقتصاد العالمي مثل أحداث أيام الأسبوع. الثورات، وأعمال الطبيعة، فضائح رفيعة المستوى، والتغييرات الحكومية وغيرها من الأحداث الكبيرة أو أقل من هذا النوع قد تحدث في أي وقت. إذا حدث مثل هذا الحدث يوم السبت، فإنه من الصعب أن يكون لها تأثير أقل على الأسواق العالمية مما حدث في أيام الأسبوع. ولعل هذه الأحداث تؤدي إلى ثغرات في علامات الاقتباس التي كثيرا ما يلاحظها في نهاية أسبوع العمل. على ما يبدو، فإن العالم يحافظ على الذهاب من خلال قواعدها الخاصة حتى عندما فوريكس لا تعمل. ولا يزال من غير الواضح ما إذا كان ينبغي استنساخ القيم الواردة في علامات الاقتباس المقابلة لعطلات نهاية الأسبوع والمخصصة للتحليل التقني وما هي الفائدة التي يمكن أن تعطيها. ومن الواضح أن هذه القضايا هي خارج نطاق هذه المادة ولكن للوهلة الأولى تسلسل دون أي فجوات ويبدو أن أكثر ملاءمة للتحليل، على الأقل من حيث الكشف عن المكونات الدورية (الموسمية). لا يمكن المبالغة في تقدير أهمية الإعداد الأولي للبيانات لمزيد من التحليل في حالتنا هو قضية مستقلة رئيسية كما يقتبس، والطريقة التي تظهر في المحطة، عموما ليست مناسبة حقا لتحليل تقني. وبصرف النظر عن القضايا ذات الصلة الفجوة أعلاه، وهناك الكثير من المشاكل الأخرى. عند تشكيل علامات الاقتباس، على سبيل المثال، يتم تعيين نقطة ثابتة من الوقت فتح وقفل القيم التي لا تنتمي إليها هذه القيم تتوافق مع الوقت تشكيل القراد بدلا من لحظة ثابتة من المخطط الزمني المحدد الإطار، في حين أنه من المعروف أن القراد في بعض الأحيان نادرة جدا. Another example can be seen in complete disregard of the sampling theorem, as nobody can guarantee that the sampling rate even within a minute interval satisfies the above theorem (not to mention other, bigger intervals). Furthermore, one should bear in mind the presence of a variable spread which in some cases may be superimposed on quote values. Let us however leave these issues out of the scope of this article and get back to the primary subject. 3. Exponential Smoothing Let us first have a look at the simplest model , X(t) (simulated) process under study, L(t) variable process level, r(t) zero mean random variable. As can be seen, this model comprises the sum of two components we are particularly interested in the process level L(t) and will try to single it out. It is well-known that the averaging of a random sequence may result in decreased variance, i. e. reduced range of its deviation from the mean. We can therefore assume that if the process described by our simple model is exposed to averaging (smoothing), we may not be able to get rid of a random component r(t) completely but we can at least considerably weaken it thus singling out the target level L(t) . For this purpose, we will use a simple exponential smoothing (SES). In this well known formula, the degree of smoothing is defined by alpha coefficient which can be set from 0 to 1. If alpha is set to zero, new incoming values of the input sequence X will have no effect whatsoever on the smoothing result. Smoothing result for any time point will be a constant value. Consequently, in extreme cases like this, the nuisance random component will be fully suppressed yet the process level under consideration will be smoothed out to a straight horizontal line. If the alpha coefficient is set to one, the input sequence will not be affected by smoothing at all. The level under consideration L(t) will not be distorted in this case and the random component will not be suppressed either. It is intuitively clear that when selecting the alpha value, one has to simultaneously satisfy the conflicting requirements. On the one hand, the alpha value shall be near zero in order to effectively suppress the random component r(t) . On the other, it is advisable to set the alpha value close to unity not to distort the L(t) component we are so interested in. In order to obtain the optimal alpha value, we need to identify a criterion according to which such value can be optimized. Upon determining such criterion, remember that this article deals with forecasting and not just smoothing of sequences. In this case regarding the simple exponential smoothing model, it is customary to consider value obtained at a given time as a forecast for any number of steps ahead. Hence, the forecast of the sequence value at the time t will be a one-step-ahead forecast made at the previous step In this case, one can use a one-step-ahead forecast error as a criterion for optimization of the alpha coefficient value Thus, by minimizing the sum of squares of these errors over the entire sample, we can determine the optimal value of the alpha coefficient for a given sequence. The best alpha value will of course be the one at which the sum of squares of the errors would be minimal. Figure 1 shows a plot of the sum of squares of one-step-ahead forecast errors versus alpha coefficient value for a fragment of test sequence USDJPY M1. Figure 1. Simple exponential smoothing The minimum on the resulting plot is barely discernible and is located close to the alpha value of approximately 0.8. But such picture is not always the case with regard to the simple exponential smoothing. When trying to obtain the optimal alpha value for test sequence fragments used in the article, we will more often than not get a plot continuously falling to unity. Such high values of the smoothing coefficient suggest that this simple model is not quite adequate for the description of our test sequences (quotes). It is either that the process level L(t) changes too fast or there is a trend present in the process. Let us complicate our model a little by adding another component , It is known that linear regression coefficients can be determined by double smoothening of a sequence: For coefficients a1 and a2 obtained in this manner, the m-step-ahead forecast at the time t will be equal to It should be noted that the same alpha coefficient is used in the above formulas for the first and repeated smoothing. This model is called the additive one-parameter model of linear growth. Let us demonstrate the difference between the simple model and the model of linear growth. Suppose that for a long time the process under study represented a constant component, i. e. it appeared on the chart as a straight horizontal line but at some point a linear trend started to emerge. A forecast for this process made using the above mentioned models is shown in Figure 2. Figure 2. Model comparison As can be seen, the simple exponential smoothing model is appreciably behind the linearly varying input sequence and the forecast made using this model is moving yet further away. We can see a very a different pattern when the linear growth model is used. When the trend emerges, this model is as if trying to come up with the linearly varying sequence and its forecast is closer to the direction of varying input values. If the smoothing coefficient in the given example was higher, the linear growth model would be able to reach the input signal over the given time and its forecast would nearly coincide with the input sequence. Despite the fact that the linear growth model in the steady state gives good results in the presence of a linear trend, it is easy to see that it takes a certain time for it to catch up with the trend. Therefore there will always be a gap between the model and input sequence if the direction of a trend frequently changes. Besides, if the trend grows nonlinearly but instead follows the square law, the linear growth model will not be able to reach it. But despite these drawbacks, this model is more beneficial than the simple exponential smoothing model in the presence of a linear trend. As already mentioned, we used a one-parameter model of linear growth. In order to find the optimal value of the alpha parameter for a fragment of test sequence USDJPY M1, let us build a plot of the sum of squares of one-step-ahead forecast errors versus alpha coefficient value. This plot built on the basis of the same sequence fragment as the one in Figure 1, is displayed in Figure 3. Figure 3. Linear growth model As compared with the result in Figure 1, the optimal value of the alpha coefficient has in this case decreased to approximately 0.4. The first and second smoothing have the same coefficients in this model, although theoretically their values can be different. The linear growth model with two different smoothing coefficients will be reviewed further. Both exponential smoothing models we considered have their analogs in MetaTrader 5 where they exist in the form of indicators. These are well-known EMA and DEMA which are not designed for forecasting but for smoothing of sequence values. It should be noted that when using DEMA indicator, a value corresponding to the a1 coefficient is displayed instead of the one-step forecast value. The a2 coefficient (see the above formulas for the linear growth model) is in this case not calculated nor used. In addition, the smoothing coefficient is calculated in terms of the equivalent period n For example, alpha equal to 0.8 will correspond to n being approximately equal to 2 and if alpha is 0.4, n is equal to 4. 4. Initial Values As already mentioned, a smoothing coefficient value shall in one way or another be obtained upon application of exponential smoothing. But this appears to be insufficient. Since in exponential smoothing the current value is calculated on the basis of the previous one, there is a situation where such value does not yet exist at the time zero. In other words, initial value of S or S1 and S2 in the linear growth model shall in some way be calculated at the time zero. The problem of obtaining initial values is not always easy to solve. If (as in the case of using quotes in MetaTrader 5) we have a very long history available, the exponential smoothing curve will, had the initial values been inaccurately determined, have time to stabilize by a current point, having corrected our initial error. This will require about 10 to 200 (and sometimes even more) periods depending on the smoothing coefficient value. In this case it would be enough to roughly estimate the initial values and start the exponential smoothing process 200-300 periods before the target time period. It gets more difficult, though, when the available sample only contains e. g. 100 values. There are various recommendations in literature regarding the choice of initial values. For example, the initial value in the simple exponential smoothing can be equated to the first element in a sequence or calculated as the mean of three to four initial elements in a sequence with a view to smoothing random outliers. The initial values S1 and S2 in the linear growth model can be determined based on the assumption that the initial level of the forecasting curve shall be equal to the first element in a sequence and the slope of the linear trend shall be zero. One can find yet more recommendations in different sources regarding the choice of initial values but none of them can ensure the absence of noticeable errors at early stages of the smoothing algorithm. It is particularly noticeable with the use of low value smoothing coefficients when a great number of periods is required in order to attain a steady state. Therefore in order to minimize the impact of problems associated with the choice of initial values (especially for short sequences), we sometimes use a method which involves a search for such values that will result in the minimum forecast error. It is a matter of calculating a forecast error for the initial values varying at small increments over the entire sequence. The most appropriate variant can be selected after calculating the error within the range of all possible combinations of initial values. This method is however very laborious requiring a lot of calculations and is almost never used in its direct form. The problem described has to do with optimization or search for a minimum multi-variable function value. Such problems can be solved using various algorithms developed to considerably reduce the scope of calculations required. We will get back to the issues of optimization of smoothing parameters and initial values in forecasting a bit later. 5. Forecast Accuracy Assessment Forecasting procedure and selection of the model initial values or parameters give rise to the problem of estimating the forecast accuracy. Assessment of accuracy is also important when comparing two different models or determining the consistency of the obtained forecast. There is a great number of well-known estimates for the forecast accuracy assessment but the calculation of any of them requires the knowledge of the forecast error at every step. As already mentioned, a one-step-ahead forecast error at the time t is equal to Probably the most common forecast accuracy estimate is the mean squared error (MSE): where n is the number of elements in a sequence. Extreme sensitivity to occasional single errors of large value is sometimes pointed out as a disadvantage of MSE. It derives from the fact that the error value when calculating MSE is squared. As an alternative, it is advisable to use in this case the mean absolute error (MAE). The squared error here is replaced by the absolute value of the error. It is assumed that the estimates obtained using MAE are more stable. Both estimates are quite appropriate for e. g. assessment of forecast accuracy of the same sequence using different model parameters or different models but they appear to be of little use for comparison of the forecast results received in different sequences. Besides, the values of these estimates do not expressly suggest the quality of the forecast result. For example, we cannot say whether the obtained MAE of 0,03 or any other value is good or bad. To be able to compare the forecast accuracy of different sequences, we can use relative estimates RelMSE and RelMAE: The obtained estimates of forecast accuracy are here divided by the respective estimates obtained using the test method of forecasting. As a test method, it is suitable to use the so-called naive method suggesting that the future value of the process will be equal to the current value. If the mean of forecast errors equals the value of errors obtained using the naive method, the relative estimate value will be equal to one. If the relative estimate value is less than one, it means that, on the average, the forecast error value is less than in the naive method. In other words, the accuracy of forecast results ranks over the accuracy of the naive method. And vice versa, if the relative estimate value is more than one, the accuracy of the forecast results is, on the average, poorer than in the naive method of forecasting. These estimates are also suitable for assessment of the forecast accuracy for two or more steps ahead. A one-step forecast error in calculations just needs to be replaced with the value of forecast errors for the appropriate number of steps ahead. As an example, the below table contains one-step ahead forecast errors estimated using RelMAE in one-parameter model of linear growth. The errors were calculated using the last 200 values of each test sequence. Table 1. One-step-ahead forecast errors estimated using RelMAE RelMAE estimate allows to compare the effectiveness of a selected method when forecasting different sequences. As the results in Table 1 suggest, our forecast was never more accurate than the naive method - all RelMAE values are more than one. 6. Additive Models There was a model earlier in the article that comprised the sum of the process level, linear trend and a random variable. We will expand the list of the models reviewed in this article by adding another model which in addition to the above components includes a cyclic, seasonal component. Exponential smoothing models comprising all components as a sum are called the additive models. Apart from these models there are multiplicative models where one, more or all components are comprised as a product. Let us proceed to reviewing the group of additive models. The one-step-ahead forecast error has repeatedly been mentioned earlier in the article. This error has to be calculated in nearly any application related to forecasting based on exponential smoothing. Knowing the value of the forecast error, the formulas for the exponential smoothing models introduced above can be presented in a somewhat different form (error-correcting form). The form of the model representation we are going to use in our case contains an error in its expressions that is partially or fully added to the previously obtained values. Such representation is called the additive error model. Exponential smoothing models can also be expressed in a multiplicative error form which will however not be used in this article. Let us have a look at additive exponential smoothing models. Simple exponential smoothing: Additive linear growth model: In contrast to the earlier introduced one-parameter linear growth model, two different smoothing parameters are used here. Linear growth model with damping: The meaning of such damping is that the trend slope will recede at every subsequent forecasting step depending on the value of the damping coefficient. This effect is demonstrated in Figure 4. Figure 4. Damping coefficient effect As can be seen in the figure, when making a forecast, a decreasing value of the damping coefficient will cause the trend to be losing its strength faster, thus the linear growth will get more and more damped. By adding a seasonal component as a sum to each of these three models we will get three more models. Simple model with additive seasonality: Linear growth model with additive seasonality: Linear growth model with damping and additive seasonality: There are also ARIMA models equivalent to the models with seasonality but they will be left out here as they will hardly have any practical importance whatsoever. Notations used in the formulas provided are as follows: It is easy to see that the formulas for the last model provided include all six variants under consideration. If in the formulas for the linear growth model with damping and additive seasonality we take , the seasonality will be disregarded in forecasting. Further, where , a linear growth model will be produced and where , we will get a linear growth model with damping. The simple exponential smoothing model will correspond to . When employing the models that involve seasonality, the presence of cyclicity and period of the cycle should first be determined using any available method in order to further use this data for initialization of values of seasonal indices. We didnt manage to detect a considerable stable cyclicity in the fragments of test sequences used in our case where the forecast is made over short time intervals. Therefore in this article we will not give relevant examples and expand on the characteristics associated with seasonality. In order to determine the probability prediction intervals with regard to the models under consideration, we will use analytical derivations found in the literature 3. The mean of the sum of squares of one-step-ahead forecast errors calculated over the entire sample of size n will be used as the estimated variance of such errors. Then the following expression will be true for determination of the estimated variance in a forecast for 2 and more steps ahead for the models under consideration: Having calculated the estimated variance of the forecast for every step m, we can find the limits of the 95 prediction interval: We will agree to name such prediction interval the forecast confidence interval. Let us implement the expressions provided for the exponential smoothing models in a class written in MQL5. 7. Implementation of the AdditiveES Class The implementation of the class involved the use of the expressions for the linear growth model with damping and additive seasonality. As mentioned earlier, other models can be derived from it by an appropriate selection of parameters. Let us briefly review methods of AdditiveES class. double s - sets the initial value of the smoothed level double t - sets the initial value of the smoothed trend double alpha1 - sets the smoothing parameter for the level of the sequence double gamma0 - sets the smoothing parameter for the trend double phi1 - sets the damping parameter double delta0 - sets the smoothing parameter for seasonal indices int nses1 - sets the number of periods in the seasonal cycle. It returns a one-step-ahead forecast calculated on the basis of the initial values set. The Init method shall be called in the first place. This is required for setting the smoothing parameters and initial values. It should be noted that the Init method does not provide for initialization of seasonal indices at arbitrary values when calling this method, seasonal indices will always be set to zero. Int m - seasonal index number double is - sets the value of the seasonal index number m. The IniIs(. ) method is called when the initial values of seasonal indices need to be other than zero. Seasonal indices should be initialized right after calling the Init(. ) method. double y new value of the input sequence It returns a one-step-ahead forecast calculated on the basis of the new value of the sequence This method is designed for calculating a one-step-ahead forecast every time a new value of the input sequence is entered. It should only be called after the class initialization by the Init and, where necessary, IniIs methods. int m forecasting horizon of 1,2,3, period It returns the m-step-ahead forecast value. This method calculates only the forecast value without affecting the state of the smoothing process. It is usually called after calling the NewY method. int m forecasting horizon of 1,2,3, period It returns the coefficient value for calculating the forecast variance. This coefficient value shows the increase in the variance of a m-step-ahead forecast compared to the variance of the one-step-ahead forecast. GetS, GetT, GetF, GetIs methods These methods provide access to the protected variables of the class. GetS, GetT and GetF return values of the smoothed level, smoothed trend and a one-step-ahead forecast, respectively. GetIs method provides access to seasonal indices and requires the indication of the index number m as an input argument. The most complex model out of all we have reviewed is the linear growth model with damping and additive seasonality based on which the AdditiveES class is created. This brings up a very reasonable question - what would the remaining, simpler models be needed. Despite the fact, that more complex models should seemingly have a clear advantage over simpler ones, it is actually not always the case. Simpler models that have less parameters will in the vast majority of cases result in lesser variance of forecast errors, i. e. their operation will be more steady. This fact is employed in creating forecasting algorithms based on simultaneous parallel operation of all available models, from the simplest to the most complex ones. Once the sequence have been fully processed, a forecasting model that demonstrated the lowest error, given the number of its parameters (i. e. its complexity), is selected. There is a number of criteria developed for this purpose, e. g. Akaikes Information Criterion (AIC). It will result in selection of a model which is expected to produce the most stable forecast. To demonstrate the use of the AdditiveES class, a simple indicator was created all smoothing parameters of which are set manually. The source code of the indicator AdditiveESTest. mq5 is set forth below. A call or a repeated initialization of the indicator sets the exponential smoothing initial values There are no initial settings for seasonal indices in this indicator, their initial values are therefore always equal to zero. Upon such initialization, the influence of seasonality on the forecast result will gradually increase from zero to a certain steady value, with the introduction of new incoming values. The number of cycles required to reach a steady-state operating condition depends on the value of the smoothing coefficient for seasonal indices: the smaller the smoothing coefficient value, the more time it will require. The operation result of the AdditiveESTest. mq5 indicator with default settings is shown in Figure 5. Figure 5. The AdditiveESTest. mq5 indicator Apart from the forecast, the indicator displays an additional line corresponding to the one-step forecast for the past values of the sequence and limits of the 95 forecast confidence interval. The confidence interval is based on the estimated variance of the one-step-ahead error. To reduce the effect of inaccuracy of the selected initial values, the estimated variance is not calculated over the entire length nHist but only with regard to the last bars the number of which is specified in the input parameter nTest. Files. zip archive at the end of the article includes AdditiveES. mqh and AdditiveESTest. mq5 files. When compiling the indicator, it is necessary that the include AdditiveES. mqh file is located in the same directory as AdditiveESTest. mq5. While the problem of selecting the initial values was to some extent solved when creating the AdditiveESTest. mq5 indicator, the problem of selecting the optimal values of smoothing parameters has remained open. 8. Selection of the Optimal Parameter Values The simple exponential smoothing model has a single smoothing parameter and its optimal value can be found using the simple enumeration method. After calculating the forecast error values over the entire sequence, the parameter value is changed at a small increment and a full calculation is made again. This procedure is repeated until all possible parameter values have been enumerated. Now we only need to select the parameter value which resulted in the smallest error value. In order to find an optimal value of the smoothing coefficient in the range of 0.1 to 0.9 at 0.05 increments, the full calculation of the forecast error value will need to be made seventeen times. As can be seen, the number of calculations required is not so big. But the linear growth model with damping involves the optimization of three smoothing parameters and in this case it will take 4913 calculation runs in order to enumerate all their combinations in the same range at the same 0.05 increments. The number of full runs required for enumeration of all possible parameter values rapidly increases with the increase in the number of parameters, decrease in the increment and expansion of the enumeration range. Should it further be necessary to optimize the initial values of the models in addition to the smoothing parameters, it will be quite difficult to do using the simple enumeration method. Problems associated with finding the minimum of a function of several variables are well studied and there is quite a lot of algorithms of this kind. Description and comparison of various methods for finding the minimum of a function can be found in the literature 7. All these methods are primarily aimed at reducing the number of calls of the objective function, i. e. reducing the computational efforts in the process of finding the minimum. Different sources often contain a reference to the so-called quasi-Newton methods of optimization. Most likely this has to do with their high efficiency but the implementation of a simpler method should also be sufficient to demonstrate an approach to the optimization of forecasting. Let us opt for Powells method. Powells method does not require calculation of derivatives of the objective function and belongs to search methods. This method, like any other method, may be programmatically implemented in various ways. The search should be completed when a certain accuracy of the objective function value or the argument value is attained. Besides, a certain implementation may include the possibility of using limitations on the permissible range of function parameter changes. In our case, the algorithm for finding an unconstrained minimum using Powells method is implemented in PowellsMethod. class. The algorithm stops searching once a given accuracy of the objective function value is attained. In the implementation of this method, an algorithm found in the literature 8 was used as a prototype. Below is the source code of the PowellsMethod class. The Optimize method is the main method of the class. double ampp - array that at the input contains the initial values of parameters the optimal values of which shall be found the obtained optimal values of these parameters are at the output of the array. int n0 - number of arguments in array p. Where n0, the number of parameters is considered to be equal to the size of array p. It returns the number of iterations required for operation of the algorithm, or -1 if the maximum permissible number thereof has been reached . When searching for optimal parameter values, an iterative approximation to the minimum of the objective function occurs. The Optimize method returns the number of iterations required to reach the function minimum with a given accuracy. The objective function is called several times at every iteration, i. e. the number of calls of the objective function may be significantly (ten and even hundred times) bigger than the number of iterations returned by the Optimize method. Other methods of the class. Int n - maximum permissible number of iterations in Powells method. The default value is 200. It sets the maximum permissible number of iterations once this number is reached, the search will be over regardless of whether the minimum of the objective function with a given accuracy was found. And a relevant message will be added to the log. double er - accuracy. Should this value of deviation from the minimum value of the objective function be reached, Powells method stops searching. The default value is 1e-6. Int n - maximum permissible number of iterations for an auxiliary Brents method. The default value is 200. It sets the maximum permissible number of iterations. Once it is reached, the auxiliary Brents method will stop searching and a relevant message will be added to the log. double er accuracy. This value defines accuracy in the search of the minimum for the auxiliary Brents method. The default value is 1e-4. It returns the minimum value of the objective function obtained. It returns the number of iterations required for operation of the algorithm. Virtual function func(const double ampp) const double ampp address of the array containing the optimized parameters. The size of the array corresponds to the number of function parameters. It returns the function value corresponding to the parameters passed to it. The virtual function func() shall in every particular case be redefined in a class derived from the PowellsMethod class. The func() function is the objective function the arguments of which corresponding to the minimum value returned by the function will be found when applying the search algorithm. This implementation of Powells method employs Brents univariate parabolic interpolation method for determining the direction of search with regard to each parameter. The accuracy and maximum permissible number of iterations for these methods can be set separately by calling SetItMaxPowell, SetFtolPowell, SetItMaxBrent and SetFtolBrent. So the default characteristics of the algorithm can be changed in this manner. This may appear useful when the default accuracy set to a certain objective function turns out to be too high and the algorithm requires too many iterations in the search process. The change in the value of the required accuracy can optimize the search with regard to different categories of objective functions. Despite the seeming complexity of the algorithm that employs Powells method, it is quite simple in use. Let us review an example. Assume, we have a function and we need to find the values of parameters and at which the function will have the smallest value. Let us write a script demonstrating a solution to this problem. When writing this script, we first create the func() function as a member of the PMTest class which calculates the value of the given test function using the passed values of parameters p0 and p1. Then in the body of the OnStart() function, the initial values are assigned to the required parameters. The search will start from these values. Further, a copy of the PMTest class is created and the search for the required values of p0 and p1 starts by calling the Optimize method the methods of the parent PowellsMethod class will call the redefined func() function. Upon completion of the search, the number of iterations, function value at the minimum point and the obtained parameter values p00.5 and p16 will be added to the log. PowellsMethod. mqh and a test case PMTest. mq5 are located at the end of the article in Files. zip archive. In order to compile PMTest. mq5, it should be located in the same directory as PowellsMethod. mqh. 9. Optimization of the Model Parameter Values The previous section of the article dealt with implementation of the method for finding the function minimum and gave a simple example of its use. We will now proceed to the issues related to optimization of the exponential smoothing model parameters. For a start, let us simplify the earlier introduced AdditiveES class to the maximum by excluding from it all elements associated with the seasonal component, as the models that take into consideration seasonality are not going to be further considered in this article anyway. This will allow to make the source code of the class much easier to comprehend and reduce the number of calculations. In addition, we will also exclude all calculations related to forecasting and computations of the forecast confidence intervals for an easy demonstration of an approach to the optimization of parameters of the linear growth model with damping under consideration. The OptimizeES class derives from the PowellsMethod class and includes redefining of the virtual function func(). As mentioned earlier, the parameters whose calculated value will be minimized in the course of optimization shall be passed at the input of this function. In accordance with the maximum likelihood method, the func() function calculates the logarithm of the sum of squares of one-step-ahead forecast errors. The errors are calculated in a loop with regard to NCalc recent values of the sequence. To preserve the stability of the model, we should impose limitations on the range of changes in its parameters. This range for Alpha and Gamma parameters will be from 0.05 to 0.95, and for Phi parameter - from 0.05 to 1.0. But for optimization in our case, we use a method for finding an unconstrained minimum which does not imply the use of limitations on the arguments of the objective function. We will try to turn the problem of finding the minimum of the multi-variable function with limitations into a problem of finding an unconstrained minimum, to be able to take into consideration all limitations imposed on the parameters without changing the search algorithm. For this purpose, the so-called penalty function method will be used. This method can easily be demonstrated for a one-dimensional case. Suppose that we have a function of a single argument (whose domain is from 2.0 to 3.0) and an algorithm which in the search process can assign any values to this function parameter. In this case, we can do as follows: if the search algorithm has passed an argument which exceeds the maximum permissible value, e. g. 3.5, the function can be calculated for the argument equal to 3.0 and the obtained result is further multiplied by a coefficient proportional to the excess of the maximum value, for example k1(3.5-3)200. If similar operations are performed with regard to argument values that turned out to be below the minimum permissible value, the resulting objective function is guaranteed to increase outside the permissible range of changes in its argument. Such artificial increase in the resulting value of the objective function allows to keep the search algorithm unaware of the fact that the argument passed to the function was in any way limited and guarantee that the minimum of the resulting function will be within the set limits of the argument. Such approach is easily applied to a function of several variables. The main method of the OptimizeES class is the Calc method. A call of this method is responsible for reading data from a file, search for optimal parameter values of a model and estimation of the forecast accuracy using RelMAE for the obtained parameter values. The number of processed values of the sequence read from a file is in this case set in the variable NCalc. Below is the example of the OptimizationTest. mq5 script that uses the OptimizeES class. Following the execution of this script, the obtained result will be as shown below. Figure 6. OptimizationTest. mq5 script result Although we can now find optimal parameter values and initial values of the model, there is yet one parameter which cannot be optimized using simple tools - the number of sequence values used in optimization. In optimization with regard to a sequence of great length, we will obtain the optimal parameter values that, on the average, ensure a minimum error over the entire length of the sequence. However if the nature of the sequence varied within this interval, the obtained values for some of its fragments will no longer be optimal. On the other hand, if the sequence length is dramatically decreased, there is no guarantee that the optimal parameters obtained for such a short interval will be optimal over a longer time lag. OptimizeES. mqh and OptimizationTest. mq5 are located at the end of the article in Files. zip archive. When compiling, it is necessary that OptimizeES. mqh and PowellsMethod. mqh are located in the same directory as the compiled OptimizationTest. mq5. In the given example, USDJPYM11100.TXT file is used that contains the test sequence and that should be located in the directory MQL5FilesDataset. Table 2 shows the estimates of the forecast accuracy obtained using RelMAE by means of this script. Forecasting was done with regard to eight test sequences mentioned earlier in the article using the last 100, 200 and 400 values of each of these sequences. Table 2. Forecast errors estimated using RelMAE As can be seen, the forecast error estimates are close to unity but in the majority of cases the forecast for the given sequences in this model is more accurate than in the naive method. 10. The IndicatorES. mq5 Indicator The AdditiveESTest. mq5 indicator based on the AdditiveES. mqh class was mentioned earlier upon review of the class. All smoothing parameters in this indicator were set manually. Now after considering the method allowing to optimize the model parameters, we can create a similar indicator where the optimal parameter values and initial values will be determined automatically and only the processed sample length will need to be set manually. That said, we will exclude all calculations related to seasonality. The source code of the CIndiatorES class used in creating the indicator is set forth below. This class contains CalcPar and GetPar methods the first one is designed for calculation of the optimal parameter values of the model, the second one is intended for accessing those values. Besides, the CIndicatorES class comprises the redefining of the virtual function func(). The source code of the IndicatorES. mq5 indicator: With every new bar, the indicator finds the optimal values of the model parameters, makes calculations in the model for a given number of bars NHist, builds a forecast and defines the forecast confidence limits. The only parameter of the indicator is the length of the processed sequence the minimum value of which is limited to 24 bars. All calculations in the indicator are made on the basis of the open values. The forecasting horizon is 12 bars. The code of the IndicatorES. mq5 indicator and CIndicatorES. mqh file are located at the end of the article in Files. zip archive. Figure 7. Operation result of the IndicatorES. mq5 indicator An example of the operation result of the IndicatorES. mq5 indicator is shown in Figure 7. In the course of operation of the indicator, the 95 forecast confidence interval will take values corresponding to the obtained optimal parameter values of the model. The bigger the smoothing parameter values, the faster the increase in the confidence interval upon the increasing forecasting horizon. With a simple improvement, the IndicatorES. mq5 indicator can be used not only for forecasting currency quotes but also for forecasting values of various indicators or preprocessed data. Conclusion The main objective of the article was to familiarize the reader with additive exponential smoothing models used in forecasting. While demonstrating their practical use, some accompanying issues were also dealt with. However the materials provided in the article can be considered merely an introduction to the large range of problems and solutions associated with forecasting. I would like to draw your attention to the fact that the classes, functions, scripts and indicators provided were created in the process of writing the article and are primarily designed to serve as examples to the materials of the article. Therefore no serious testing for stability and errors was performed. Besides, the indicators set forth in the article should be considered to be only a demonstration of the implementation of the methods involved. The forecast accuracy of the IndicatorES. mq5 indicator introduced in the article can most likely be somewhat improved by using the modifications of the applied model which would be more adequate in terms of peculiarities of the quotes under consideration. The indicator can also be amplified by other models. But these issues fall beyond the scope of this article. In conclusion, it should be noted that exponential smoothing models can in certain cases produce forecasts of the same accuracy as the forecasts obtained by applying more complex models thus proving once again that even the most complex model is not always the best. المراجع

No comments:

Post a Comment