Sunday 11 February 2018

استراتيجيات التداول r


استراتيجيات التداول r
الحصول على فيا أب ستور قراءة هذه المشاركة في التطبيق لدينا!
R: إعادة اختبار استراتيجية التداول. مبتدئين إلى كوانتمود و R.
أنا جديدة جدا ل R ومحاولة ل باكتست استراتيجية لقد برمجت بالفعل في ويالثلاب.
عدة أشياء لا أفهمها (ولا تعمل بشكل واضح :)
أنا لا تحصل على أسعار قريبة بشكل جيد في ناقلات. أو نوع من ناقلات ولكن يبدأ مع بنية وأنا لا أفهم حقا ما هذه الوظيفة لا. ولهذا السبب قد لا تعمل دعوتي [1] على الأرجح.
n & لوت؛ - نرو (سيريز) لا يعمل إما، ولكن أنا بحاجة إلى ذلك ل حلقة.
لذلك أعتقد إذا حصلت على هذه الأسئلة 2 أجاب استراتيجيتي يجب أن تعمل. أنا ممتن جدا لأي مساعدة .. R يبدو معقدا جدا حتى مع تجربة البرمجة في لغات أخرى.
بدءا من السؤال الثاني.
حتى إذا كنت ترغب في العمل على كائن شتس الفعلي تحتاج إلى استخدام الحصول على.
حول سؤالك الأول - لا أعتقد أنك حقا بحاجة إلى سحب البيانات كناقلات - كائن شتس هو صفيف مفهرسة حسب التاريخ وأنه من السهل أن تعمل مع. إذا كنت لا تزال ترغب في الحصول على البيانات التي يمكنك استخدامها.
الآن، للحصول على انك بدأت مع عودة اختبار بسيط من الاستراتيجيات وسوف أقترح العمل في الخطوات التالية.
تحديد الاستراتيجية الخاصة بك. 2. إنشاء مصفوفة أو إضافة عمود إلى كائن شتس الخاص بك الذي سيمثل موقفك لكل يوم. 1 لفترة طويلة، 0 لأي موقف و -1 قصيرة (في وقت لاحق يمكنك أن تلعب مع عدد للرافعة المالية). 3. مضاعفة كل أيام العودة مع الموقف وستحصل على استراتيجية ناقلات العودة الخاص بك. 4. فحص النتائج - توصيتي هي بيرفورمانساناليتيكش.
استراتيجية بسيطة - شراء عند إغلاق SMA20، بيع تحت.

استراتيجية التداول الكمية باستخدام R: دليل خطوة بخطوة.
في هذا المنصب سوف نناقش حول بناء استراتيجية التداول باستخدام R. قبل السكن في المصطلحات التجارية باستخدام R دعونا نقضي بعض الوقت فهم ما هو R. R هو مصدر مفتوح. هناك أكثر من 4000 إضافة على الحزم، 18000 بالإضافة إلى أعضاء مجموعة لينكيدين وما يقرب من 80 R مجموعات ميتوب الموجودة حاليا. بل هو أداة مثالية للتحليل الإحصائي وخاصة لتحليل البيانات. الإعداد موجزة من شبكة الأرشيف R شاملة يعرف كما كران يوفر لك قائمة الحزم جنبا إلى جنب مع تركيب قاعدة المطلوبة. هناك الكثير من الحزم المتاحة اعتمادا على تحليل يجب القيام به. لتنفيذ استراتيجية التداول، وسوف نستخدم حزمة تسمى كوانسترات.
عملية أربع خطوات من أي استراتيجية تجارة أساسية.
تكوين الفرضية اختبار تكرير الإنتاج.
وقد صيغت فرضيتنا على أنها "السوق يعني العودة". متوسط ​​العائد هو نظرية تشير إلى أن الأسعار تتحرك في نهاية المطاف إلى القيمة المتوسطة. أما الخطوة الثانية فتتضمن اختبار الفرضية التي نقوم بصياغة إستراتيجية لها على فرضيتنا وحساب المؤشرات والإشارات ومقاييس الأداء. يمكن تقسيم مرحلة الاختبار إلى ثلاث خطوات، والحصول على البيانات، وكتابة الاستراتيجية وتحليل الإخراج. في هذا المثال نعتبر نيفتي النحل. وهو صندوق تداول تبادل تدار من قبل جولدمان ساكس. نس لديها حجم ضخم للأداة وبالتالي فإننا نعتبر هذا. تظهر الصورة أدناه السعر المفتوح-العالي-المنخفض-إغلاق نفسه.
وضعنا مستوى عتبة لمقارنة التقلبات في السعر. في حالة ارتفاع / نقص السعر نقوم بتحديث عمود العتبة. يتم مقارنة سعر الإغلاق مع الفرقة العليا ومع الفرقة السفلى. عندما يتم عبر الشريط العلوي، هو إشارة للبيع. وبالمثل عندما يتم عبور النطاق السفلي، بل هو إشارة للبيع.
ويمكن تلخيص قسم الترميز على النحو التالي،
ويرد في الرسم البياني أدناه عرض لطائرات الهليكوبتر باتجاه إنتاج الاستراتيجية.
وبالتالي فإن فرضيتنا أن السوق يعني العودة يتم دعم. وبما أن هذا هو الاختبار الخلفي لدينا مجال لتنقيح المعلمات التجارية التي من شأنها تحسين متوسط ​​عوائدنا والأرباح المحققة. ويمكن القيام بذلك عن طريق تحديد مستويات عتبة مختلفة، وقواعد دخول أكثر صرامة، ووقف الخسارة وما إلى ذلك يمكن للمرء أن يختار المزيد من البيانات للاختبار الخلفي، واستخدام نهج بايسيان لعتبة اقامة، تأخذ التقلب بعين الاعتبار.
مرة كنت واثقا من استراتيجية التداول المدعومة من نتائج الاختبار الخلفي هل يمكن أن خطوة إلى التداول المباشر. بيئة الإنتاج هو موضوع كبير في حد ذاته وانها خارج النطاق في سياق المقال. لشرح باختصار هذا ينطوي على كتابة الاستراتيجية على منصة التداول.
كما ذكرنا سابقا، سنقوم ببناء النموذج باستخدام حزمة كوانسترات. يوفر كوانتسترات بنية تحتية عامة لنموذج واستراتيجيات باكتست إشارة القائمة على إشارة. بل هو طبقة التجريد رفيعة المستوى (التي بنيت على شتس، فينانسيالينسترومنت، النازل، الخ) التي تسمح لك لبناء واختبار الاستراتيجيات في عدد قليل جدا من خطوط التعليمات البرمجية.
الملامح الرئيسية ل كوانسترات هي،
يدعم الاستراتيجيات التي تشمل المؤشرات والإشارات والقواعد يسمح الاستراتيجيات التي سيتم تطبيقها على المحافظ متعددة الأصول يدعم السوق، والحد، و ستوبليميت، وأنواع ستوبترايلينغ النظام يدعم ترتيب التحجيم وتحسين المعلمة.
في هذا المنصب نبني استراتيجية تتضمن المؤشرات والإشارات والقواعد.
وفيما يتعلق بالنموذج العام القائم على الإشارة التالية،
الأدوات - تحتوي على بيانات السوق المؤشرات - القيم الكمية المستمدة من بيانات السوق الإشارات - نتيجة التفاعل بين بيانات السوق والمؤشرات القواعد - إصدار الأوامر باستخدام بيانات السوق والمؤشرات والإشارات.
دون الكثير من اللغط دعونا مناقشة جزء الترميز. نحن نفضل R ستوديو للترميز وتصر على استخدام نفس. يجب أن يكون لديك حزم معينة مثبتة قبل برمجة الاستراتيجية.
تقوم مجموعة الأوامر التالية بتثبيت الحزم الضرورية.
بمجرد تثبيت الحزم التي استيرادها لمزيد من الاستخدام.
قراءة البيانات من ملف كسف وتحويله إلى كائن شتس.
نقوم بتهيئة المحفظة مع المخزون والعملة وحقوق الملكية الأولية ونوع الاستراتيجية.
أضف حد الموضع إذا كنت ترغب في التداول أكثر من مرة على نفس الجانب.
إنشاء كائن الاستراتيجية.
نحن نبني وظيفة تحسب العتبات التي نريد التجارة. إذا تحرك السعر من قبل thresh1 نقوم بتحديث عتبة السعر الجديد. نطاقات جديدة للتداول هي عتبة +/- ثريش 2. الإخراج هو كائن شتس على الرغم من أننا نستخدم وظيفة إعادة التصنيف لضمان.
أضف المؤشر والإشارة وقاعدة التداول.
تشغيل الاستراتيجية وإلقاء نظرة على كتاب النظام.
تحديث محفظة وعرض إحصاءات التجارة.
هنا هو رمز كامل.
مرة واحدة كنت على دراية بهذه الأساسيات يمكن أن نلقي نظرة على كيفية البدء في استخدام حزمة كوانتيمود في R. أو في حال كنت جيدة في C ++، نلقي نظرة على استراتيجية نموذج مشفرة في C ++.
إذا كنت تاجر التجزئة أو المهنية المهنية تبحث لبدء مكتب التداول الآلي الخاص بك، والبدء في تعلم ألغو التداول اليوم! تبدأ مع المفاهيم الأساسية مثل هندسة التداول الآلي، المجهرية السوق، باكتستينغ استراتيجية ونظام إدارة النظام.
التعليقات مغلقة.
المشاركات الشعبية الأخيرة.
أكثر المقالات التي تمت زيارتها في الأسبوع.
وظائف للمستخدمين R.
هو مدعوم من وورد باستخدام تصميم بافوتاسان.
كوبيرايت & كوبي؛ 2017 R - المدونين. كل الحقوق محفوظة. الشروط والأحكام لهذا الموقع.

و التاجر R.
استخدام R والأدوات ذات الصلة في التمويل الكمي.
تصور بيانات سلسلة الوقت في R.
أنا مسرور جدا أن أعلن بلدي داتاكامب بالطبع على تصور البيانات سلسلة الوقت في R. هذا بالطبع هو أيضا جزء من سلسلة الوقت مع R المهارات المسار. لا تتردد في الحصول على نظرة، والفصل الأول هو حر!
وصف المساقات.
وكما يقول المثل، "الرسم البياني يستحق ألف كلمة". هذا هو السبب في التصور هو الطريقة الأكثر استخداما وقوية للحصول على فهم أفضل للبيانات الخاصة بك. بعد هذا بالطبع سيكون لديك نظرة عامة جيدة جدا من R سلسلة الوقت قدرات التصور، وسوف تكون قادرة على اتخاذ قرار أفضل النموذج الذي يختار للتحليل اللاحق. سوف تكون قادرة على نقل الرسالة التي تريد تسليم بطريقة فعالة وجميلة.
بالطبع مخطط.
الفصل 1: R التصور سلسلة الوقت أدوات.
هذا الفصل سوف أعرض لكم الأساسية R سلسلة الوقت أدوات التصور.
الفصل 2: ​​سلسلة زمنية أحادية المتغير.
وقد صممت األراضي املتعددة املتغريات لتعلم قدر اإلمكان عن التوزيع والتوجه املركزي وانتشار البيانات املتوفرة. في هذا الفصل سوف يتم تقديمك مع بعض الأدوات البصرية المستخدمة لتشخيص سلسلة أحادية المتغيرات.
الفصل الثالث: سلسلة زمنية متعددة المتغيرات.
ماذا تفعل إذا كان لديك للتعامل مع سلاسل زمنية متعددة المتغيرات؟ في هذا الفصل، سوف تتعلم كيفية تحديد أنماط في التوزيع، والاتجاه المركزي وانتشار على أزواج أو مجموعات من البيانات.
الفصل الرابع: دراسة حالة: اختيار بصريا الأسهم التي تحسن المحفظة الحالية.
اسمحوا & # 8217؛ ق وضع كل ما تعلمته حتى الآن في الممارسة العملية! تخيل أنك تملك بالفعل محفظة من الأسهم وكان لديك بعض النقود الاحتياطية للاستثمار، وكيف يمكنك بحكمة اختيار الأسهم الجديدة للاستثمار النقدية الخاصة بك إضافية؟ ويعد تحليل الخصائص الإحصائية للأسهم الفردية مقابل المحفظة القائمة وسيلة جيدة لمعالجة المشكلة.
ربط R إلى إقفيد مع حزمة كوانتولس.
يوفر إقفيد تدفق خدمات البيانات والحلول التجارية التي تغطي السوق الزراعي والطاقة والمالية. بل هو معروف ومعترف به مزود تغذية البيانات الموجهة نحو مستخدمي التجزئة والمؤسسات الصغيرة. يبدأ سعر الاشتراك في حوالي 80 $ / الشهر.
وقد وضعت ستانيسلاف كوفاليفسكي حزمة تسمى كوانتولس. بل هو حزمة في كل واحدة تهدف إلى تعزيز النمذجة التداول الكمي. فإنه يسمح لتحميل وتنظيم بيانات السوق التاريخية من مصادر متعددة مثل ياهو، جوجل، فينام، موكس و إكيفيد. الميزة التي تهمني أكثر هي القدرة على ربط إكفيد ل R. أنا & # 8217؛ لقد تم استخدام إكفيد لبضع سنوات وأنا & # 8217؛ م سعيد معها (أنا & # 8217؛ م لا ينتمي إلى الشركة في أي الطريق). ويمكن الاطلاع على مزيد من المعلومات هنا. أنا & # 8217؛ كنت تبحث عن التكامل داخل R لفترة من الوقت وهنا هو. ونتيجة لذلك، بعد أن ركضت بعض الاختبارات، انتقلت التعليمات البرمجية التي كانت لا تزال في بيثون إلى R. مجرد اكتمال، وهنا & # 8217؛ ق رابط يشرح كيفية تحميل البيانات التاريخية من إكفيد باستخدام بايثون.
كوانتولس يقدم أربع وظائف رئيسية هي: الحصول على بيانات السوق، مخزن / استرداد بيانات السوق، مؤامرة البيانات سلسلة الوقت والاختبار مرة أخرى.
تأكد أولا من أن إقفيد مفتوح. يمكنك إما تحميل البيانات اليومية أو خلال اليوم. أدناه رمز التنزيلات الأسعار اليومية (المفتوحة، عالية، منخفضة، إغلاق) ل سبي من 1 يناير 2017 إلى 1 يونيو 2017.
أدناه رمز التنزيلات البيانات اللحظية من 1 مايو 2017 إلى 3 مايو 2017.
لاحظ معلمة الفترة. يمكن أن تأخذ أي من القيم التالية: القراد، 1min، 5min، 10min، 15min، 30min، ساعة، يوم، أسبوع، شهر، اعتمادا على التردد الذي تحتاجه.
كوانتولس يجعل عملية إدارة وتخزين بيانات سوق القراد سهلة. كنت فقط الإعداد معلمات التخزين وكنت على استعداد للذهاب. المعلمات هي حيث، منذ التاريخ والرموز التي ترغب في أن يتم تخزينها. في أي وقت يمكنك إضافة المزيد من الرموز وإذا لم تكن موجودة في التخزين، كوانتولس يحاول الحصول على البيانات من تاريخ البدء المحدد. سيقوم الرمز أدناه بحفظ البيانات في الدليل التالي: & # 8220؛ C: / وسرس / أرنو / دوكومينتس / ماركيت داتا / إكفيد & # 8221 ؛. هناك مجلد فرعي واحد من قبل أداة والبيانات هو أفيد في ملفات. rds.
يمكنك أيضا تخزين البيانات بين تواريخ محددة. استبدل السطر الأخير من الشفرة أعلاه بأحد الخيارات التالية.
الآن إذا كنت ترغب في الحصول على العودة بعض البيانات التي قمت بتخزينها، مجرد تشغيل شيء مثل:
لاحظ أن القراد فقط معتمد في التخزين المحلي لذلك يجب أن تكون الفترة & # 8216؛ علامة & # 8217؛
كوانتولس يوفر وظيفة plot_ts لرسم البيانات سلسلة الوقت دون عطلة نهاية الأسبوع، والعطلات والثغرات بين عشية وضحاها. في المثال أدناه، أنا أولا استرداد البيانات المخزنة أعلاه، ثم حدد أول 100 الملاحظات السعر وأخيرا رسم المخطط.
أمران أن نلاحظ: الجاسوس الأول هو كائن data. table وبالتالي بناء الجملة أعلاه. للحصول على لمحة سريعة عن قدرات data. table لها نظرة على هذه الورقة الغش ممتازة من داتاكامب. ثانيا المعلمة المحلية ترو كما يتم استرجاع البيانات من وحدة التخزين الداخلية.
كوانتولس يسمح لكتابة استراتيجية التداول الخاصة بك باستخدام C ++ أبي. أنا & # 8217؛ م لن نتحدث عن هذا لأن هذا هو أساسا C ++ التعليمات البرمجية. يمكنك الرجوع إلى قسم الأمثلة على موقع كوانتولس.
عموما أجد حزمة مفيدة للغاية وموثقة بشكل جيد. الشيء الوحيد المفقود هو تغذية حية بين R و إقفيد والتي سوف تجعل حزمة نهاية حقيقية لإنهاء الحل.
كالمعتاد أي تعليقات موضع ترحيب.
بيرت: الوافد الجديد في اتصال R إكسيل.
قبل بضعة أشهر قارئ يشير لي من هذه الطريقة الجديدة لربط R و إكسيل. أنا لا أعرف كم من الوقت كان هذا حولها، ولكن أنا لم تأتي عبر ذلك وأنا & # 8217؛ لم أر أي مشاركة بلوق أو مقالة حول هذا الموضوع. لذلك قررت أن أكتب وظيفة كأداة حقا يستحق ذلك وقبل أن يسأل أي شخص، أنا & # 8217؛ م لا علاقة للشركة بأي شكل من الأشكال.
يقف بيرت لمجموعة أدوات إكسيل R الأساسية. إنه مجاني (مرخص بموجب غل v2) وقد تم تطويره من قبل ستروتوريد داتا ليك. في وقت كتابة النسخة الحالية من بيرت هو 1.07. ويمكن الاطلاع على مزيد من المعلومات هنا. من منظور أكثر تقنية، تم تصميم بيرت لدعم تشغيل وظائف R من خلايا جداول البيانات إكسل. في عبارات إكسيل، فإنه يتم كتابة المهام التي يحددها المستخدم (أودفس) في R.
في هذا المنصب أنا & # 8217؛ م لن تظهر لك كيف R و إكسيل التفاعل عبر بيرت. هناك دروس جيدة جدا هنا، هنا وهنا. بدلا من ذلك أريد أن تظهر لك كيف استخدمت بيرت لبناء & # 8220؛ برج التحكم & # 8221؛ لتداول بلدي.
يتم إنشاء إشارات التداول الخاصة بي باستخدام قائمة طويلة من الملفات R ولكن أنا بحاجة إلى مرونة إكسيل لعرض النتائج بسرعة وكفاءة. كما هو مبين أعلاه بيرت يمكن أن تفعل هذا بالنسبة لي ولكن أريد أيضا أن خياط التطبيق لاحتياجاتي. من خلال الجمع بين قوة شمل، فبا، R و بيرت يمكنني إنشاء تطبيق جيد حتى الآن قوية في شكل ملف إكسيل مع الحد الأدنى من التعليمات البرمجية فبا. في نهاية المطاف لدي ملف اكسل واحد جمع كل المهام اللازمة لإدارة محفظتي: تحديث قاعدة البيانات، توليد إشارة، تقديم الطلبات الخ & # 8230؛ ويمكن تقسيم نهجي في الخطوات الثلاث التالية:
استخدم شمل لإنشاء قوائم وأزرار محددة من قبل المستخدم في ملف إكسيل. القوائم المذكورة أعلاه وأزرار هي أساسا يدعو إلى وظائف فبا. تلك الوظائف فبا هي التفاف حول وظائف R المعرفة باستخدام بيرت.
مع هذا النهج يمكنني الحفاظ على تمييز واضح بين جوهر بلدي رمز الاحتفاظ بها في R، سكل وبيثون وكل ما يستخدم لعرض وتنسيق النتائج أبقى في إكسيل، فبا & أمب؛ XML. في الأقسام التالية أقدم الشرط الأساسي لتطوير مثل هذا النهج ودليل خطوة بخطوة يوضح كيف يمكن استخدام بيرت لمجرد تمرير البيانات من R إلى إكسيل مع الحد الأدنى من التعليمات البرمجية فبا.
1 & # 8211؛ تحميل وتثبيت بيرت من هذا الرابط. بمجرد اكتمال التثبيت يجب أن يكون لديك قائمة الوظائف الإضافية الجديدة في إكسيل مع الأزرار كما هو موضح أدناه. هذه هي الطريقة التي تحققت بيرت في إكسيل.
2 & # 8211؛ تنزيل وتثبيت محرر واجهة مستخدم مخصص: يسمح محرر واجهة المستخدم المخصص بإنشاء قوائم وأزرار محددة من قبل المستخدم في شريط إكسيل. يتوفر إجراء خطوة بخطوة هنا.
1 & # 8211؛ R كود: وظيفة R أدناه هي قطعة بسيطة جدا من التعليمات البرمجية لأغراض التوضيح فقط. ويحسب ويعيد البقايا من الانحدار الخطي. هذا هو ما نريد استرداد في إكسيل. حفظ هذا في ملف يسمى myRCode. R (أي اسم آخر على ما يرام) في دليل من اختيارك.
2 & # 8211؛ functions. R في بيرت: من إكسيل حدد الوظائف الإضافية - & غ؛ الصفحة الرئيسية الدليل وفتح الملف يسمى functions. R. في هذا الملف قم بلصق التعليمة البرمجية التالية. تأكد من إدراج المسار الصحيح.
هذا هو مجرد مصادر في بيرت ملف R قمت بإنشائه أعلاه. ثم حفظ وإغلاق الملف functions. R. إذا كنت تريد إجراء أي تغيير على ملف R الذي تم إنشاؤه في الخطوة 1 سيكون لديك لإعادة تحميله باستخدام زر بيرت & # 8220؛ تحديث ملف بدء التشغيل & # 8221؛ من القائمة الوظائف الإضافية في إكسيل.
3 & # 8211؛ في إكسيل: إنشاء وحفظ ملف يسمى myFile. xslm (أي اسم آخر على ما يرام). هذا هو ملف تمكين ماكرو الذي تقوم بحفظه في الدليل الذي تختاره. مرة واحدة يتم حفظ الملف إغلاقه.
4 & # 8211؛ افتح الملف الذي تم إنشاؤه أعلاه في محرر واجهة المستخدم المخصصة: بعد فتح الملف، الصق الشفرة التالية.
يجب أن يكون لديك شيء من هذا القبيل في محرر شمل:
أساسا هذه القطعة من رمز شمل يخلق قائمة إضافية (رترادر)، مجموعة جديدة (مجموعتي) وزر تعريف المستخدم (زر جديد) في الشريط إكسيل. بعد الانتهاء من إجراء ذلك، افتح myFile. xslm في إكسيل وأغلق محرر واجهة المستخدم المخصص. يجب أن نرى شيئا من هذا القبيل.
5 & ​​# 8211؛ فتح محرر فبا: في myFile. xlsm إدراج وحدة نمطية جديدة. قم بلصق التعليمة البرمجية أدناه في الوحدة النمطية التي تم إنشاؤها حديثا.
يؤدي ذلك إلى محو النتائج السابقة في ورقة العمل قبل التعامل مع نتائج جديدة.
6 & # 8211؛ انقر فوق زر جديد: الآن عد إلى جدول البيانات وفي القائمة رترادر ​​انقر فوق & # 8220؛ زر جديد & # 8221؛ زر. يجب أن تشاهد شيئا مثل ما يظهر أدناه.
الدليل أعلاه هو نسخة أساسية جدا من ما يمكن تحقيقه باستخدام بيرت لكنه يظهر لك كيفية الجمع بين قوة عدة أدوات محددة لبناء التطبيق المخصص الخاص بك. من وجهة نظري مصلحة هذا النهج هو القدرة على الغراء معا R و إكسيل الواضح ولكن أيضا لتشمل عن طريق شمل (والدفعة) قطعة من التعليمات البرمجية من بايثون، سكل وأكثر من ذلك. هذا هو بالضبط ما كنت بحاجة إليه. وأخيرا أود أن تكون غريبة لمعرفة ما إذا كان أي شخص لديه أي خبرة مع بيرت؟
استراتيجية التداول: الاستفادة القصوى من البيانات من العينة.
عند اختبار استراتيجيات التداول هناك نهج مشترك هو تقسيم مجموعة البيانات الأولية إلى بيانات العينة: الجزء من البيانات المصممة لمعايرة النموذج والخروج من بيانات العينة: جزء من البيانات المستخدمة للتحقق من صحة المعايرة وضمان أن الأداء التي تم إنشاؤها في عينة ستنعكس في العالم الحقيقي. وكقاعدة عامة يمكن استخدام حوالي 70٪ من البيانات الأولية للمعايرة (أي في العينة) و 30٪ للتحقق (أي من العينة). ثم تساعد مقارنة البيانات داخل وخارج العينة على تحديد ما إذا كان النموذج قويا بما فيه الكفاية. ويهدف هذا المنصب إلى المضي قدما خطوة أخرى ويوفر طريقة إحصائية لتقرير ما إذا كان خارج العينة البيانات يتماشى مع ما تم إنشاؤه في العينة.
في الرسم البياني أدناه تمثل المنطقة الزرقاء خارج أداء العينة لأحد استراتيجياتي.
فحص بصري بسيط يكشف عن تناسب جيد بين داخل وخارج أداء العينة ولكن ما هي درجة الثقة لدي في هذا؟ في هذه المرحلة ليس كثيرا، وهذه هي القضية. والمطلوب حقا هو مقياس للتشابه بين مجموعات البيانات داخل وخارج العينة. ومن الناحية الإحصائية، يمكن ترجمة ذلك على أنه احتمال أن تأتي أرقام أداء العينة وخارجها من نفس التوزيع. هناك اختبار إحصائي غير بارامتري الذي يفعل بالضبط هذا: اختبار كروسكال واليس. ويمكن العثور على تعريف جيد لهذا الاختبار على R-توتور & # 8220؛ مجموعة من عينات البيانات مستقلة إذا كانت تأتي من السكان غير ذات الصلة والعينات لا تؤثر على بعضها البعض. باستخدام اختبار كروسكال واليس، يمكننا أن نقرر ما إذا كانت التوزيعات السكانية متطابقة دون افتراض أنها تتبع التوزيع الطبيعي. & # 8221؛ الفائدة الإضافية لهذا الاختبار لا يفترض توزيع طبيعي.
وتوجد اختبارات أخرى من نفس الطبيعة يمكن أن تتلاءم مع هذا الإطار. اختبار مان-ويتني-ويلكوكسون أو اختبارات كولموغوروف-سميرنوف يناسب تماما الإطار يصف هنا ولكن هذا خارج نطاق هذه المقالة لمناقشة إيجابيات وسلبيات كل من هذه الاختبارات. ويمكن الاطلاع على وصف جيد جنبا إلى جنب مع الأمثلة R هنا.
هنا الرمز المستخدم لإنشاء الرسم البياني أعلاه والتحليل:
في المثال أعلاه في فترة العينة أطول من خارج الفترة عينة ولذلك أنا عشوائيا إنشاء 1000 مجموعات فرعية من البيانات في العينة كل واحد لها نفس طول البيانات خارج العينة. ثم اختبرت كل عينة فرعية في مقابل عينة من البيانات وسجلت قيم p. هذه العملية لا تخلق قيمة P واحدة لاختبار كروسكال واليس ولكن التوزيع يجعل التحليل أكثر قوة. في هذا المثال يكون متوسط ​​قيم p أعلى بكثير من الصفر (0.478) مما يشير إلى أنه يجب قبول الفرضية الصفرية: فهناك أدلة قوية على أن البيانات داخل وخارج العينة تأتي من نفس التوزيع.
كالمعتاد ما هو عرض في هذا المنصب هو مثال لعبة أن خدوش فقط على سطح المشكلة ويجب أن تكون مصممة لتلبية الاحتياجات الفردية. ومع ذلك أعتقد أنه يقترح إطارا إحصائيا للاهتمام والعقلاني لتقييم نتائج العينة.
هذه المقالة مستوحاة من الورقتين التاليتين:
فيجيل ألكسندر، شميل سوان (2007)، "آثار وظائف التحسين المختلفة على الخروج من عينة أداء استراتيجيات التداول المتطورة وراثيا"، التنبؤ مؤتمر الأسواق المالية.
فيجيل ألكسندر، شميل سوان (2010)، "عملية التحسين لتحسين / الخروج من عينة الاتساق، حالة سوق الأوراق المالية»، مؤتمر مورغان كازينوف الملكية الكمية، لندن أكتوبر 2010.
تقديم فيدلر: فينانسيال داتا لوادير.
فيدلر هو رستوديو أدين تهدف إلى تبسيط عملية تنزيل البيانات المالية من مختلف مقدمي الخدمات. هذا الإصدار الأولي هو المجمع حول وظيفة جيتسيمبولس في حزمة كوانتمود وياهو فقط، جوجل، فريد و أواندا معتمدة. أنا ربما إضافة وظائف مع مرور الوقت. كالمعتاد مع هذه الأشياء مجرد تذكير نوع: & # 8220؛ يتم توفير البرنامج & # 8220؛ كما هو & # 8221؛، دون ضمان من أي نوع & # 8230؛ & # 8221؛
كيفية تثبيت واستخدام فيدلر؟
يمكنك الحصول على أدين / حزمة من مستودع جيثب هنا (وسوف يسجل على كران في وقت لاحق) تثبيت أدين. هناك تعليمي ممتاز لتثبيت رستوديو أدينز هنا. بمجرد تثبيت أدين يجب أن تظهر في القائمة أدين. اخترت فقط فيدلر في القائمة ونافذة كما في الصورة أدناه يجب أن تظهر. اختر موفر بيانات من القائمة المنسدلة المصدر. حدد نطاق تاريخ من قائمة التاريخ أدخل الرمز الذي ترغب في تنزيله في مربع النص الخاص بالأداة. لتحميل عدة رموز فقط أدخل الرموز مفصولة بفواصل. استخدام أزرار الراديو لاختيار ما إذا كنت ترغب في تحميل الصك في ملف كسف أو في البيئة العالمية. سيتم حفظ ملف كسف في دليل العمل وسيكون هناك ملف كسف واحد لكل أداة. اضغط على تشغيل للحصول على البيانات أو إغلاق لإغلاق أدين.
يتم التعامل مع رسائل الخطأ والتحذيرات من قبل الحزم الأساسية (كوانتمود و لامعة) ويمكن قراءتها من وحدة التحكم.
هذه هي النسخة الأولى جدا من المشروع لذلك لا نتوقع الكمال ولكن نأمل أنه سوف تتحسن مع مرور الوقت. يرجى الإبلاغ عن أي تعليق، اقتراح، علة الخ & # 8230؛ إلى: ثيرترادرغميل.
الحفاظ على قاعدة بيانات لملفات الأسعار في R.
القيام بالبحث الكمي ينطوي على الكثير من البيانات الطحن واحد يحتاج إلى بيانات نظيفة وموثوق بها لتحقيق ذلك. ما هو مطلوب حقا هو البيانات النظيفة التي يمكن الوصول إليها بسهولة (حتى من دون اتصال بالإنترنت). وكانت الطريقة الأكثر فعالية للقيام بذلك بالنسبة لي للحفاظ على مجموعة من ملفات كسف. من الواضح أن هذه العملية يمكن التعامل معها في نواح كثيرة ولكن وجدت العمل الإضافي فعالة جدا وبسيطة للحفاظ على الدليل حيث يمكنني تخزين وتحديث ملفات كسف. لدي ملف كسف واحد لكل أداة ويسمى كل ملف بعد الصك أنه يحتوي على. والسبب في ذلك هو شقين: أولا، لا أريد تحميل البيانات (السعر) من ياهو، غوغل وغيرها & # 8230؛ في كل مرة أريد أن اختبر فكرة جديدة ولكن الأهم من ذلك مرة واحدة حددت وثابتة مشكلة، أنا لا تريد أن تفعل ذلك مرة أخرى في المرة القادمة أنا بحاجة إلى نفس الأداة. بسيطة لكنها فعالة جدا حتى الآن. يتم تلخيص العملية في الرسم البياني أدناه.
في كل ما يلي، أفترض أن البيانات تأتي من ياهو. يجب تعديل الشفرة للبيانات من غوغل، كواندل إتك & # 8230؛ وبالإضافة إلى ذلك أقدم عملية تحديث بيانات الأسعار اليومية. سيكون الإعداد مختلفا عن بيانات التردد الأعلى والنوع الآخر من مجموعات البيانات (أي مختلف عن الأسعار).
1 & # 8211؛ تنزيل البيانات الأولية (listOfInstruments. R & HistoryData. R)
ملف listOfInstruments. R هو ملف يحتوي فقط على قائمة بجميع الصكوك.
إذا لم يكن أحد الأدوات جزءا من قائمتي (أي ملف كسف في مجلد البيانات) أو إذا قمت بذلك للمرة الأولى، عليك تنزيل مجموعة البيانات التاريخية الأولية. المثال أدناه ينزل مجموعة من صناديق المؤشرات المتداولة يوميا من ياهو فينانس إلى يناير 2000 وتخزين البيانات في ملف كسف.
2 & # 8211؛ تحديث البيانات الموجودة (updateData. R)
يبدأ رمز أدناه من الملفات الموجودة في مجلد مخصص وتحديث كل منهم واحدا تلو الآخر. أنا عادة تشغيل هذه العملية كل يوم إلا عندما أنا & # 8217؛ م في عطلة. لإضافة أداة جديدة، ببساطة تشغيل الخطوة 1 أعلاه لهذا الصك وحده.
3 & # 8211؛ إنشاء ملف دفعي (updateDailyPrices. bat)
جزء مهم آخر من المهمة هو إنشاء ملف دفعي يقوم بأتمتة عملية التحديث أعلاه (I & # 8217؛ م مستخدم ويندوز). هذا يتجنب فتح R / رستوديو وتشغيل التعليمات البرمجية من هناك. يتم وضع التعليمات البرمجية أدناه على ملف بت. (يجب تعديل المسار مع إعداد القارئ & # 8217؛ s). لاحظ أنني أضفت ملف الإخراج (updateLog. txt) لتتبع التنفيذ.
العملية المذكورة أعلاه بسيطة للغاية لأنها تصف فقط كيفية تحديث بيانات الأسعار اليومية. أنا & # 8217؛ لقد تم استخدام هذا لفترة من الوقت، وأنها كانت تعمل بسلاسة جدا بالنسبة لي حتى الآن. للحصول على بيانات أكثر تقدما و / أو ترددات أعلى، يمكن للأشياء الحصول على أكثر صعوبة.
كالمعتاد أي تعليقات موضع ترحيب.
صعود الروبوتات (المستشارين & # 8230؛)
إن صناعة إدارة الأصول على وشك إحداث تغيير كبير. على مدى العامين الماضيين ظهرت الروبوتات المستشارين (را) لاعبين جدد. المصطلح نفسه يصعب تعريفه لأنه يشمل مجموعة كبيرة ومتنوعة من الخدمات. تم تصميم بعضها لمساعدة المستشارين التقليديين لتخصيص أفضل أموال عملائها والبعض الحقيقي & # 8220؛ الصندوق الأسود & # 8221؛. يدخل المستخدم بعض المعايير (العمر والدخل والأطفال الخ & # 8230؛) والروبوت يقترح تخصيص مخصص. بين هذين النقيضين مجموعة كاملة من العروض المتاحة. لقد وجدت تعريف ويكيبيديا جيدة جدا. & # 8220؛ هم فئة من المستشار المالي الذي يوفر إدارة المحافظ على الانترنت مع الحد الأدنى من التدخل البشري & # 8221؛. وبصورة أدق، يستخدمون إدارة الحافظة القائمة على الخوارزميات لتقديم مجموعة كاملة من الخدمات التي سيقدمها مستشار تقليدي: إعادة استثمار الأرباح، وتقارير الامتثال، وإعادة توازن المحفظة، وحصاد الخسائر الضريبية، إلخ & # 8230؛ (حسنا هذا هو ما يقوم به مجتمع الاستثمار الكمي لعقود!). هذه الصناعة لا تزال في مهدها مع معظم اللاعبين لا تزال تدير كمية صغيرة من المال ولكن أدركت فقط مدى عميق كان التغيير عندما كنت في مدينة نيويورك قبل أيام قليلة. عندما را الحصول على أسمائهم على التلفزيون يضيف أو على سقف سيارة أجرة مدينة نيويورك كنت أعرف شيئا كبيرا يحدث & # 8230؛
فإنه يحصل على المزيد والمزيد من الاهتمام من وسائل الإعلام وقبل كل شيء يجعل الكثير من الشعور من وجهة نظر المستثمرين. هناك في الواقع اثنين من المزايا الرئيسية في استخدام را:
رسوم أقل بكثير على المستشارين التقليديين يتم جعل الاستثمار أكثر شفافية وأبسط وأكثر جاذبية للأشخاص ذوي المعرفة المالية المحدودة.
في هذا المنصب R هو مجرد عذر لتقديم لطيف ما هو الاتجاه الرئيسي في صناعة إدارة الأصول. ويبين الرسم البياني أدناه حصص السوق من را الأكثر شعبية اعتبارا من نهاية عام 2014. التعليمات البرمجية المستخدمة لتوليد الرسم البياني أدناه يمكن العثور عليها في نهاية هذا المنصب والبيانات هنا.
هذه الأرقام هي مؤرخة قليلا نظرا لمدى سرعة هذه الصناعة تتطور ولكن لا تزال مفيدة للغاية. ليس من المستغرب أن يهيمن على السوق من قبل مقدمي الولايات المتحدة مثل ويالثفرونت و بيترمنت ولكن را لا تظهر في جميع أنحاء العالم: آسيا (8Now!)، سويسرا (إنفستغلاس)، فرنسا (ماري كوانتييه) & # 8230؛ .. انها بدأت تؤثر بشكل كبير طريقة مديري الأصول التقليدية يقومون بأعمال تجارية. ومن الأمثلة البارزة على ذلك الشراكة بين "الإخلاص" و "بيترمنت". منذ ديسمبر 2014 بيترمنت الماضي علامة 2000000000 $ أوم.
على الرغم من كل ما سبق، أعتقد أن التغيير الحقيقي هو أمامنا. ولأنهم يستخدمون وسطاء أقل ومنتجات عمولة منخفضة (مثل صناديق الاستثمار المتداولة)، فإنهم يتقاضون رسوما أقل بكثير من الرسوم التي يحصل عليها المستشارون التقليديون. ومن المؤكد أن إدارة األبحاث ستكتسب حصصا سوقية كبيرة ولكنها ستخفض أيضا الرسوم التي تتحملها الصناعة ككل. في نهاية المطاف سوف تؤثر على طريقة الشركات الاستثمارية التقليدية القيام بأعمال تجارية. إدارة محفظة النشطة التي تواجه وقتا صعبا لبعض سنوات الآن سوف تعاني أكثر من ذلك. إن الرسوم المرتفعة التي تتكبدها ستكون أكثر صعوبة لتبريرها ما لم تعيد اختراع نفسها. ومن الآثار المحتملة الأخرى ارتفاع صنادیق الاستثمار المتداولة والمنتجات المالیة منخفضة العمولات بشکل عام. ومن الواضح أن هذا قد بدأ منذ فترة ولكنني أعتقد أن التأثير سيكون أكثر وضوحا في السنوات المقبلة. وتتبع الأجيال الجديدة لصناديق الاستثمار المتداولة مؤشرات أكثر تعقيدا واستراتيجيات مخصصة. وسيزداد حتما هذا الاتجاه.
كالمعتاد أي تعليقات موضع ترحيب.
R الوقت المالي نصائح سلسلة يجب أن يعرف الجميع عنه.
هناك العديد من R سلسلة الدروس الوقت العائمة حول على شبكة الإنترنت لم يتم تصميم هذا المنصب ليكون واحدا منهم. بدلا من ذلك أريد أن أعرض قائمة من الحيل الأكثر فائدة جئت عبر التعامل مع سلسلة الوقت المالي في R. بعض من الوظائف المقدمة هنا قوية بشكل لا يصدق ولكن للأسف دفن في الوثائق وبالتالي رغبتي في إنشاء وظيفة مخصصة. أنا فقط عنوان اليومية أو أقل تردد مرات سلسلة. يتطلب التعامل مع البيانات ذات التردد العالي أدوات محددة: حزم البيانات أو حزم التردد العالي هي بعض منها.
شتس: حزمة زتس هو يجب أن يكون عندما يتعلق الأمر إلى سلسلة مرات في R. المثال أدناه تحميل الحزمة ويخلق سلسلة زمنية يومية من 400 يوما عوائد موزعة بشكل طبيعي.
merge. xts (باكستس شتس): هذا هو قوي بشكل لا يصدق عندما يتعلق الأمر ملزمة اثنين أو أكثر من سلسلة مرات معا سواء لديهم نفس الطول أم لا. ووسيطة الانضمام يفعل السحر! فإنه يحدد كيف يتم الربط.
application. yearly / application. monthly (باكستس شتس): تطبيق دالة محددة لكل فترة متميزة في كائن سلسلة زمنية معينة. المثال التالي يحسب العائدات الشهرية والسنوية من السلسلة الثانية في كائن تسينتر. لاحظ أني استخدم مجموع العوائد (لا تفاقم)
إندبوانتس (باكيج شتس): استخراج قيم الفهرس للكائن زتس معين المقابلة للملاحظات الأخيرة نظرا لفترة محددة من قبل. يعطي المثال اليوم الأخير من الشهر إرجاع لكل سلسلة في كائن تسينتر باستخدام نقطة النهاية لتحديد التاريخ.
na. locf (حزمة حديقة الحيوان): وظيفة عامة لاستبدال كل نا مع أحدث غير نا قبل ذلك. مفيدة للغاية عند التعامل مع سلسلة زمنية مع عدد قليل & # 8220؛ ثقوب & # 8221؛ وعندما يتم استخدام هذه السلسلة الزمنية لاحقا كإدخال لوظائف R التي لا تقبل الوسيطات مع نا. في المثال أنا إنشاء سلسلة زمنية من أسعار عشوائية ثم يتضمن مصطنع عدد قليل من المنظمات غير الحكومية في ذلك واستبدالها مع أحدث قيمة.
charts. PerformanceSummary (باكيج بيرفورمانساناليتيكش): بالنسبة لمجموعة من العوائد، قم بإنشاء مخطط مؤشر الثروة، أشرطة لأداء كل فترة، والمخطط تحت الماء للتخفيض. هذا مفيد بشكل لا يصدق كما أنه يعرض على نافذة واحدة جميع المعلومات ذات الصلة لفحص بصري سريع لاستراتيجية التداول. المثال أدناه يتحول سلسلة الأسعار إلى كائن شتس ثم يعرض نافذة مع 3 المخططات المذكورة أعلاه.
القائمة أعلاه ليست بأي حال من الأحوال شاملة ولكن بمجرد السيطرة على وظائف تصف في هذا المنصب فإنه يجعل التلاعب من سلسلة الوقت المالي أسهل كثيرا، رمز أقصر وقراءة من التعليمات البرمجية بشكل أفضل.
كالمعتاد أي تعليقات موضع ترحيب.
تقييم العوامل في إدارة الحافظة الكمية.
وعندما يتعلق الأمر بإدارة محفظة من الأسهم مقابل معيار مرجعي، فإن المشكلة تختلف كثيرا عن تحديد استراتيجية العودة المطلقة. في السابق يجب أن تعقد المزيد من الأسهم مما كانت عليه في وقت لاحق حيث لا يمكن الاحتفاظ بأي أسهم على الإطلاق إذا لم تكن هناك فرصة جيدة بما فيه الكفاية. والسبب في ذلك هو خطأ التتبع. ويعرف هذا على أنه الانحراف المعياري لعائد المحفظة مطروحا منه العائد المرجعي. وكلما قلت المخزونات مقابل مقياس مرجعي كلما زاد خطأ التتبع (مثل ارتفاع المخاطر).
التحليل التالي هو مستوحى إلى حد كبير من كتاب & # 8220؛ إدارة المحافظ النشطة & # 8221؛ بواسطة غرينولد & أمب؛ كان. هذا هو الكتاب المقدس لأي شخص مهتم في تشغيل محفظة ضد المعيار. وأنا أشجع بقوة أي شخص لديه مصلحة في هذا الموضوع لقراءة الكتاب من البداية إلى النهاية. انها & # 8217؛ ق مكتوبة بشكل جيد جدا ويضع أسس إدارة المحافظ النشطة النشطة (ليس لدي أي انتماء إلى المحرر أو المؤلفين).
هنا نحن & # 8217؛ محاولة لترتيب بأكبر قدر ممكن من الأسهم في عالم الاستثمار على أساس العودة إلى الأمام. العديد من الناس جاءوا مع العديد من الأدوات و تم تطوير عدد لا يحصى من تلك الأدوات لتحقيق ذلك. في هذا المنصب، أركز على مقياسين بسيطين ومستخدمين على نطاق واسع: معامل المعلومات (إيك) وعائد الكميات (ريال قطري).
و إيك يعطي لمحة عامة عن القدرة التنبؤ عامل. وبشكل أدق، هذا مقياس لمدى تصنيف العامل للأسهم على أساس العائد الآجل. ويعرف إيك بأنه ارتباط الرتبة (ρ) بين المقياس (مثل العامل) والعائد الآجل. ومن الناحية الإحصائية، فإن ارتباط الرتبة هو مقياس غير حسابي للاعتماد بين متغيرين. وبالنسبة لعينة من الحجم n، يتم تحويل الدرجات الخام n إلى الرتب، وتحسب ρ من:
ويجب أن يحدد المحلل الأفق للعودة الآجلة، كما أنه يمثل دالة لدوران الإستراتيجية وتسوس ألفا (كان هذا موضوع بحث موسع). من الواضح أن المراآز يجب أن تكون على أعلى مستوى ممكن من حيث القيمة المطلقة.
للقارئ الحريص، في كتاب غرينولد & أمب؛ كاهن وتعطى صيغة ربط نسبة المعلومات (إر) و إيك: مع اتساع عدد من الرهانات مستقلة (الصفقات). وتعرف هذه الصيغة بالقانون الأساسي للإدارة الفعالة. المشكلة هي أنه في كثير من الأحيان، وتحديد اتساع بدقة ليست سهلة كما يبدو.
من أجل الحصول على تقدير أكثر دقة للقوة التنبؤية للعامل فإنه من الضروري أن يذهب خطوة أبعد وأسهم المجموعة حسب كمية قيم عامل ثم تحليل متوسط ​​العائد إلى الأمام (أو أي مقياس ميل مركزي آخر) لكل من تلك quantiles. فائدة هذه الأداة هي واضحة. يمكن أن يكون لعامل إيك جيد ولكن قد تنحصر قدرته التنبؤية على عدد قليل من الأسهم. هذا ليس جيدا كما مدير محفظة سيكون لديك لاختيار الأسهم داخل الكون كله من أجل تلبية قيود خطأ التتبع. وتتميز عودة الكميات الجيدة بعلاقة رتيبة بين الكميات الفردية والعوائد الآجلة.
جميع الأسهم في مؤشر S & أمب؛ P500 (في وقت كتابة هذا التقرير). ومن الواضح أن هناك تحيز سفينة البقاء على قيد الحياة: قائمة الأسهم في المؤشر قد تغيرت بشكل ملحوظ بين بداية ونهاية الفترة العينة، ومع ذلك انها جيدة بما فيه الكفاية لأغراض التوضيح فقط.
ينزل الرمز أدناه أسعار الأسهم الفردية في مؤشر S & أمب؛ P500 بين يناير / كانون الثاني 2005 واليوم (يستغرق الأمر بعض الوقت) ويتحول إلى أسعار الخام خلال الأشهر ال 12 الماضية والشهر الماضي. الأول هو عاملنا، وسيتم استخدام هذا الأخير كمقياس العودة إلى الأمام.
وفيما يلي رمز لحساب معامل المعلومات وعودة الكميات. لاحظ أنني استخدمت الشرائح الخمسية في هذا المثال ولكن يمكن استخدام أي طريقة تجميع أخرى (تيرسيلز، ديسيلس إتك & # 8230؛). فإنه يعتمد حقا على حجم العينة، ما تريد التقاط والطقس تريد أن يكون لمحة عامة أو التركيز على ذيول التوزيع. ولتقدير العائدات في كل خمسية، استخدم الوسيط كمقدر للنزعة المركزية. هذا المقياس أقل حساسية بكثير من القيم المتطرفة من الوسط الحسابي.
وأخيرا رمز لإنتاج الرسم البياني كوانتيز ريتورن.
3 & # 8211؛ كيفية استغلال المعلومات أعلاه؟
في الرسم البياني أعلاه Q1 هو أدنى 12 شهرا الماضية عودة و Q5 أعلى. هناك زيادة رتيبة تقريبا في العائد الكمي بين Q1 و Q5 مما يشير بوضوح إلى أن الأسهم التي تندرج في Q5 تفوق تلك التي تندرج في الربع الأول بنحو 1٪ شهريا. هذا مهم جدا وقوي لمثل هذا عامل بسيط (ليس حقا مفاجأة على الرغم من & # 8230؛). لذلك هناك فرص أكبر للتغلب على المؤشر من خلال زيادة الوزن للأسهم المتساقطة في Q5 وتخفيض الوزن لتلك التي تقع في الربع الأول بالنسبة إلى المؤشر المعياري.
إيك من 0.0206 قد لا يعني الكثير في حد ذاته لكنه يختلف كثيرا عن 0 ويشير إلى قوة تنبؤية جيدة من الأشهر ال 12 الماضية يعود عموما. يمكن تقييم اختبارات الأهمية الرسمية ولكن هذا خارج نطاق هذه المقالة.
الإطار أعلاه ممتاز لتقييم عامل الاستثمار & # 8217؛ ق الجودة ولكن هناك عدد من القيود العملية التي يجب معالجتها لتنفيذ الحياة الحقيقية:
إعادة التوازن: في الوصف أعلاه، فقد افترضنا أنه في نهاية كل شهر يتم إعادة توازن المحفظة بالكامل. وهذا يعني أن جميع الأسهم التي تندرج في الربع الأول من هذا العام تعاني من نقص الوزن، وأن جميع الأسهم التي تندرج في Q5 هي زيادة في الوزن مقارنة بالمؤشر المعياري. هذا ليس دائما ممكنا لأسباب عملية: بعض الأسهم قد تكون مستبعدة من عالم الاستثمار، وهناك قيود على الصناعة أو وزن القطاع، وهناك قيود على دوران الخ & # 8230؛ تكاليف المعاملات: هذا لم يؤخذ في الاعتبار في التحليل أعلاه وهذا هو فرامل خطيرة لتنفيذ الحياة الحقيقية. وعادة ما يتم تنفيذ اعتبارات دوران في الحياة الحقيقية في شكل عقوبة على جودة عامل. معامل التحويل: هذا هو امتداد للقانون الأساسي للإدارة النشطة ويخفف من افتراض نموذج غرينولد & # 8217؛ أن المديرين لا يواجهون أي قيود تحول دون ترجمتهم رؤى استثماراتهم مباشرة إلى رهانات المحفظة.
وأخيرا، أنا & # 8217؛ م دهشتها ما يمكن تحقيقه في أقل من 80 سطر من التعليمات البرمجية مع R & # 8230؛
كالمعتاد أي تعليقات موضع ترحيب.
المخاطر ك & # 8220؛ بقاء متغير & # 8221؛
I come across a lot of strategies on the blogosphere some are interesting some are a complete waste of time but most share a common feature: people developing those strategies do their homework in term of analyzing the return but much less attention is paid to the risk side its random nature. I’ve seen comment like “a 25% drawdown in 2011 but excellent return overall”. Well my bet is that no one on earth will let you experience a 25% loss with their money (unless special agreements are in place). In the hedge fund world people have very low tolerance for drawdown. Generally, as a new trader in a hedge fund, assuming that you come with no reputation, you have very little time to prove yourself. You should make money from day 1 and keep on doing so for a few months before you gain a bit of credibility.
First let’s say you have a bad start and you lose money at the beginning. With a 10% drawdown you’re most certainly out but even with a 5% drawdown the chances of seeing your allocation reduced are very high. This has significant implications on your strategies. Let’s assume that if you lose 5% your allocation is divided by 2 and you come back to your initial allocation only when you passed the high water mark again (e. g. the drawdown comes back to 0). In the chart below I simulated the experiment with one of my strategies.
You start trading in 1st June 2003 and all goes well until 23rd Jul. 2003 where your drawdown curve hits the -5% threshold (**1**). Your allocation is cut by 50% and you don’t cross back the high water mark level until 05th Dec. 2003 (**3**). If you have kept the allocation unchanged, the high water mark level would have been crossed on 28th Oct. 2003 (**2**) and by the end of the year you would have made more money.
But let’s push the reasoning a bit further. Still on the chart above, assume you get really unlucky and you start trading toward mid-June 2003. You hit the 10% drawdown limit by the beginning of August and you’re most likely out of the game. You would have started in early August your allocation would not have been cut at all and you end up doing a good year in only 4 full months of trading. In those two examples nothing has changed but your starting date….
The trading success of any individual has some form of path dependency and there is not much you can do about it. However you can control the size of a strategy’s drawdown and this should be addressed with great care. A portfolio should be diversified in every possible dimension: asset classes, investment strategies, trading frequencies etc…. From that perspective risk is your “survival variable”. If managed properly you have a chance to stay in the game long enough to realise the potential of your strategy. Otherwise you won’t be there next month to see what happens.

The R Trader.
Using R and related tools in Quantitative Finance.
Archive for the ‘Trading Strategies’ الفئة.
Linking R to IQFeed with the QuantTools package.
IQFeed provides streaming data services and trading solutions that cover the Agricultural, Energy and Financial marketplace. It is a well known and recognized data feed provider geared toward retail users and small institutions. The subscription price starts at around $80/month.
Stanislav Kovalevsky has developed a package called QuantTools. It is an all in one package designed to enhance quantitative trading modelling. It allows to download and organize historical market data from multiple sources like Yahoo, Google, Finam, MOEX and IQFeed. The feature that interests me the most is the ability to link IQFeed to R. I’ve been using IQFeed for a few years and I’m happy with it (I’m not affiliated to the company in any way). More information can be found here. I’ve been looking for an integration within R for a while and here it is. As a result, after I ran a few tests, I moved my code that was still in Python into R. Just for completeness, here’s a link that explains how to download historical data from IQFeed using Python.
QuantTools offers four main functionalities: Get market data, Store/Retrieve market data, Plot time series data and Back testing.
First make sure that IQfeed is open. You can either download daily or intraday data. The below code downloads daily prices (Open, High, Low, Close) for SPY from 1st Jan 2017 to 1st June 2017.
The below code downloads intraday data from 1st May 2017 to 3rd May 2017.
Note the period parameter. It can take any of the following values: tick, 1min, 5min, 10min, 15min, 30min, hour, day, week, month, depending on the frequency you need.
QuantTools makes the process of managing and storing tick market data easy. You just setup storage parameters and you are ready to go. The parameters are where, since what date and which symbols you would like to be stored. Any time you can add more symbols and if they are not present in a storage, QuantTools tries to get the data from specified start date. The code below will save the data in the following directory: “C:/Users/Arnaud/Documents/Market Data/iqfeed”. There is one sub folder by instrument and the data is aved in. rds files.
You can also store data between specific dates. Replace the last line of code above with one of the below.
Now should you want to get back some of the data you stored, just run something like:
Note that only ticks are supported in local storage so period must be ‘tick’
QuantTools provides plot_ts function to plot time series data without weekend, holidays and overnight gaps. In the example below, I first retrieve the data stored above, then select the first 100 price observations and finally draw the chart.
Two things to notice: First spy is a data. table object hence the syntax above. To get a quick overview of data. table capabilities have a look at this excellent cheat sheet from DataCamp. Second the local parameter is TRUE as the data is retrieved from internal storage.
QuantTools allows to write your own trading strategy using its C++ API. I’m not going to elaborate on this as this is basically C++ code. You can refer to the Examples section on QuantTools website.
Overall I find the package extremely useful and well documented. The only missing bit is the live feed between R and IQFeed which will make the package a real end to end solution.
As usual any comments welcome.
BERT: a newcomer in the R Excel connection.
A few months ago a reader point me out this new way of connecting R and Excel. I don’t know for how long this has been around, but I never came across it and I’ve never seen any blog post or article about it. So I decided to write a post as the tool is really worth it and before anyone asks, I’m not related to the company in any way.
BERT stands for Basic Excel R Toolkit. It’s free (licensed under the GPL v2) and it has been developed by Structured Data LLC. At the time of writing the current version of BERT is 1.07. More information can be found here. From a more technical perspective, BERT is designed to support running R functions from Excel spreadsheet cells. In Excel terms, it’s for writing User-Defined Functions (UDFs) in R.
In this post I’m not going to show you how R and Excel interact via BERT. There are very good tutorials here, here and here. Instead I want to show you how I used BERT to build a “control tower” for my trading.
My trading signals are generated using a long list of R files but I need the flexibility of Excel to display results quickly and efficiently. As shown above BERT can do this for me but I also want to tailor the application to my needs. By combining the power of XML, VBA, R and BERT I can create a good looking yet powerful application in the form of an Excel file with minimum VBA code. Ultimately I have a single Excel file gathering all the necessary tasks to manage my portfolio: database update, signal generation, orders submission etc… My approach could be broken down in the 3 steps below:
Use XML to build user defined menus and buttons in an Excel file. The above menus and buttons are essentially calls to VBA functions. Those VBA functions are wrapup around R functions defined using BERT.
With this approach I can keep a clear distinction between the core of my code kept in R, SQL and Python and everything used to display and format results kept in Excel, VBA & XML. In the next sections I present the prerequisite to developed such an approach and a step by step guide that explains how BERT could be used for simply passing data from R to Excel with minimal VBA code.
1 & # 8211؛ Download and install BERT from this link . Once the installation has completed you should have a new Add-Ins menu in Excel with the buttons as shown below. This is how BERT materialized in Excel.
2 & # 8211؛ Download and install Custom UI editor : The Custom UI Editor allows to create user defined menus and buttons in Excel ribbon. A step by step procedure is available here.
1 & # 8211؛ R Code: The below R function is a very simple piece of code for illustration purposes only. It calculates and return the residuals from a linear regression. This is what we want to retrieve in Excel. Save this in a file called myRCode. R (any other name is fine) in a directory of your choice.
2 & # 8211؛ functions. R in BERT : From Excel select Add-Ins -> Home Directory and open the file called functions. R . In this file paste the following code. Make sure you insert the correct path.
This is just sourcing into BERT the R file you created above. Then save and close the file functions. R. Should you want to make any change to the R file created in step 1 you will have to reload it using the BERT button “Reload Startup File” from the Add-Ins menu in Excel.
3 & # 8211؛ In Excel: Create and save a file called myFile. xslm (any other name is fine). This is a macro-enabled file that you save in the directory of your choice. Once the file is saved close it.
4 & # 8211؛ Open the file created above in Custom UI editor : Once the file is open, paste the below code.
You should have something like this in the XML editor:
Essentially this piece of XML code creates an additional menu (RTrader), a new group (My Group) and a user defined button (New Button) in the Excel ribbon. Once you’re done, open myFile. xslm in Excel and close the Custom UI Editor. You should see something like this.
5 & ​​# 8211؛ Open VBA editor : In myFile. xlsm insert a new module. Paste the code below in the newly created module.
This erases previous results in the worksheet prior to coping new ones.
6 & # 8211؛ Click New Button : Now go back to the spreadsheet and in the RTrader menu click the “New Button” زر. You should see something like the below appearing.
The guide above is a very basic version of what can be achieved using BERT but it shows you how to combine the power of several specific tools to build your own custom application. From my perspective the interest of such an approach is the ability to glue together R and Excel obviously but also to include via XML (and batch) pieces of code from Python, SQL and more. This is exactly what I needed. Finally I would be curious to know if anyone has any experience with BERT?
Trading strategy: Making the most of the out of sample data.
When testing trading strategies a common approach is to divide the initial data set into in sample data: the part of the data designed to calibrate the model and out of sample data: the part of the data used to validate the calibration and ensure that the performance created in sample will be reflected in the real world. As a rule of thumb around 70% of the initial data can be used for calibration (i. e. in sample) and 30% for validation (i. e. out of sample). Then a comparison of the in and out of sample data help to decide whether the model is robust enough. This post aims at going a step further and provides a statistical method to decide whether the out of sample data is in line with what was created in sample.
In the chart below the blue area represents the out of sample performance for one of my strategies.
A simple visual inspection reveals a good fit between the in and out of sample performance but what degree of confidence do I have in this? At this stage not much and this is the issue. What is truly needed is a measure of similarity between the in and out of sample data sets. In statistical terms this could be translated as the likelihood that the in and out of sample performance figures coming from the same distribution. There is a non-parametric statistical test that does exactly this: the Kruskall-Wallis Test . A good definition of this test could be found on R-Tutor “A collection of data samples are independent if they come from unrelated populations and the samples do not affect each other. Using the Kruskal-Wallis Test , we can decide whether the population distributions are identical without assuming them to follow the normal distribution.” The added benefit of this test is not assuming a normal distribution.
It exists other tests of the same nature that could fit into that framework. The Mann-Whitney-Wilcoxon test or the Kolmogorov-Smirnov tests would perfectly suits the framework describes here however this is beyond the scope of this article to discuss the pros and cons of each of these tests. A good description along with R examples can be found here.
Here’s the code used to generate the chart above and the analysis:
In the example above the in sample period is longer than the out of sample period therefore I randomly created 1000 subsets of the in sample data each of them having the same length as the out of sample data. Then I tested each in sample subset against the out of sample data and I recorded the p-values. This process creates not a single p-value for the Kruskall-Wallis test but a distribution making the analysis more robust. In this example the mean of the p-values is well above zero (0.478) indicating that the null hypothesis should be accepted: there are strong evidences that the in and out of sample data is coming from the same distribution.
As usual what is presented in this post is a toy example that only scratches the surface of the problem and should be tailored to individual needs. However I think it proposes an interesting and rational statistical framework to evaluate out of sample results.
This post is inspired by the following two papers:
Vigier Alexandre, Chmil Swann (2007), “Effects of Various Optimization Functions on the Out of Sample Performance of Genetically Evolved Trading Strategies”, Forecasting Financial Markets Conference.
Vigier Alexandre, Chmil Swann (2010), « An optimization process to improve in/out of sample consistency, a Stock Market case», JP Morgan Cazenove Equity Quantitative Conference, London October 2010.
Introducing fidlr: FInancial Data LoadeR.
fidlr is an RStudio addin designed to simplify the financial data downloading process from various providers. This initial version is a wrapper around the getSymbols function in the quantmod package and only Yahoo, Google, FRED and Oanda are supported. I will probably add functionalities over time. As usual with those things just a kind reminder: “THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND…”
How to install and use fidlr?
You can get the addin/package from its Github repository here (I will register it on CRAN later on) Install the addin. There is an excellent tutorial to install RStudio Addins here. Once the addin is installed it should appear in the Addin menu. Just chose fidlr in the menu and a window as pictured below should appear. Choose a data provider from the the Source dropdown menu. Select a date range from the Date menu Enter the symbol you wish to download in the instrument text box. To download several symbols just enter the symbols separated by commas. Use the Radio buttons to choose whether you want to download the instrument in a csv file or in the global environment. The csv file will be saved in the working directory and there will be one csv file per instrument. Press Run to get the data or Close to close down the addin.
Error messages and warnings are handled by the underlying packages (quantmod and Shiny) and can be read from the console.
This is a very first version of the project so do not expect perfection but hopefully it will get better over time. Please report any comment, suggestion, bug etc… to: thertradergmail.
Maintaining a database of price files in R.
Doing quantitative research implies a lot of data crunching and one needs clean and reliable data to achieve this. What is really needed is clean data that is easily accessible (even without an internet connection). The most efficient way to do this for me has been to maintain a set of csv files. Obviously this process can be handled in many ways but I found very efficient and simple overtime to maintain a directory where I store and update csv files. I have one csv file per instrument and each file is named after the instrument it contains. The reason I do so is twofold: First, I don’t want to download (price) data from Yahoo, Google etc… every time I want to test a new idea but more importantly once I identified and fixed a problem, I don’t want to have to do it again the next time I need the same instrument. Simple yet very efficient so far. The process is summarized in the chart below.
In everything that follows, I assume that data is coming from Yahoo. The code will have to be amended for data from Google, Quandl etc… In addition I present the process of updating daily price data. The setup will be different for higher frequency data and other type of dataset (i. e. different from prices).
1 & # 8211؛ Initial data downloading (listOfInstruments. R & historicalData. R)
The file listOfInstruments. R is a file containing only the list of all instruments.
If an instrument isn’t part of my list (i. e. no csv file in my data folder) or if you do it for the very first time you have to download the initial historical data set. The example below downloads a set of ETFs daily prices from Yahoo Finance back to January 2000 and store the data in a csv file.
2 & # 8211؛ Update existing data (updateData. R)
The below code starts from existing files in the dedicated folder and updates all of them one after the other. I usually run this process everyday except when I’m on holiday. To add a new instrument, simply run step 1 above for this instrument alone.
3 & # 8211؛ Create a batch file (updateDailyPrices. bat)
Another important part of the job is creating a batch file that automates the updating process above (I’m a Windows user). This avoids opening R/RStudio and run the code from there. The code below is placed on a. bat file (the path has to be amended with the reader’s setup). Note that I added an output file (updateLog. txt) to track the execution.
The process above is extremely simple because it only describes how to update daily price data. I’ve been using this for a while and it has been working very smoothly for me so far. For more advanced data and/or higher frequencies, things can get much trickier.
As usual any comments welcome.
Factor Evaluation in Quantitative Portfolio Management.
When it comes to managing a portfolio of stocks versus a benchmark the problem is very different from defining an absolute return strategy. In the former one has to hold more stocks than in the later where no stocks at all can be held if there is not good enough opportunity. The reason for that is the tracking error . This is defined as the standard deviation of the portfolio return minus the benchmark return. The less stocks is held vs. a benchmark the higher the tracking error (e. g higher risk).
The analysis that follows is largely inspired by the book “Active Portfolio Management” by Grinold & Kahn. This is the bible for anyone interested in running a portfolio against a benchmark. I strongly encourage anyone with an interest in the topic to read the book from the beginning to the end. It’s very well written and lays the foundations of systematic active portfolio management (I have no affiliation to the editor or the authors).
Here we’re trying to rank as accurately as possible the stocks in the investment universe on a forward return basis. Many people came up with many tools and countless variant of those tools have been developed to achieve this. In this post I focus on two simple and widely used metrics: Information Coefficient (IC) and Quantiles Return (QR).
The IC gives an overview of the factor forecasting ability. More precisely, this is a measure of how well the factor ranks the stocks on a forward return basis. The IC is defined as the rank correlation ( ρ ) between the metric (e. g. factor) and the forward return. In statistical terms the rank correlation is a nonparametric measure of dependance between two variables. For a sample of size n , the n raw scores are converted to ranks , and ρ is computed from:
The horizon for the forward return has to be defined by the analyst and it’s a function of the strategy’s turnover and the alpha decay (this has been the subject of extensive research). Obviously ICs must be as high as possible in absolute terms.
For the keen reader, in the book by Grinold & Kahn a formula linking Information Ratio (IR) and IC is given: with breadth being the number of independent bets (trades). This formula is known as the fundamental law of active management . The problem is that often, defining breadth accurately is not as easy as it sounds.
In order to have a more accurate estimate of the factor predictive power it’s necessary to go a step further and group stocks by quantile of factor values then analyse the average forward return (or any other central tendency metric) of each of those quantiles. The usefulness of this tool is straightforward. A factor can have a good IC but its predictive power might be limited to a small number of stocks. This is not good as a portfolio manager will have to pick stocks within the entire universe in order to meet its tracking error constraint. Good quantiles return are characterised by a monotonous relationship between the individual quantiles and forward returns.
All the stocks in the S&P500 index (at the time of writing). Obviously there is a survival ship bias: the list of stocks in the index has changed significantly between the start and the end of the sample period, however it’s good enough for illustration purposes only.
The code below downloads individual stock prices in the S&P500 between Jan 2005 and today (it takes a while) and turns the raw prices into return over the last 12 months and the last month. The former is our factor, the latter will be used as the forward return measure.
Below is the code to compute Information Coefficient and Quantiles Return. Note that I used quintiles in this example but any other grouping method (terciles, deciles etc…) can be used. it really depends on the sample size, what you want to capture and wether you want to have a broad overview or focus on distribution tails. For estimating returns within each quintile, median has been used as the central tendency estimator. This measure is much less sensitive to outliers than arithmetic mean.
And finally the code to produce the Quantiles Return chart.
3 & # 8211؛ How to exploit the information above?
In the chart above Q1 is lowest past 12 months return and Q5 highest. There is an almost monotonic increase in the quantiles return between Q1 and Q5 which clearly indicates that stocks falling into Q5 outperform those falling into Q1 by about 1% per month. This is very significant and powerful for such a simple factor (not really a surprise though…). Therefore there are greater chances to beat the index by overweighting the stocks falling into Q5 and underweighting those falling into Q1 relative to the benchmark.
An IC of 0.0206 might not mean a great deal in itself but it’s significantly different from 0 and indicates a good predictive power of the past 12 months return overall. Formal significance tests can be evaluated but this is beyond the scope of this article.
The above framework is excellent for evaluating investments factor’s quality however there are a number of practical limitations that have to be addressed for real life implementation:
Rebalancing : In the description above, it’s assumed that at the end of each month the portfolio is fully rebalanced. This means all stocks falling in Q1 are underweight and all stocks falling in Q5 are overweight relative to the benchmark. This is not always possible for practical reasons: some stocks might be excluded from the investment universe, there are constraints on industry or sector weight, there are constraints on turnover etc… Transaction Costs : This has not be taken into account in the analysis above and this is a serious brake to real life implementation. Turnover considerations are usually implemented in real life in a form of penalty on factor quality. Transfer coefficient : This is an extension of the fundamental law of active management and it relaxes the assumption of Grinold’s model that managers face no constraints which preclude them from translating their investments insights directly into portfolio bets.
And finally, I’m amazed by what can be achieved in less than 80 lines of code with R…
As usual any comments welcome.
Risk as a “Survival Variable”
I come across a lot of strategies on the blogosphere some are interesting some are a complete waste of time but most share a common feature: people developing those strategies do their homework in term of analyzing the return but much less attention is paid to the risk side its random nature. I’ve seen comment like “a 25% drawdown in 2011 but excellent return overall”. Well my bet is that no one on earth will let you experience a 25% loss with their money (unless special agreements are in place). In the hedge fund world people have very low tolerance for drawdown. Generally, as a new trader in a hedge fund, assuming that you come with no reputation, you have very little time to prove yourself. You should make money from day 1 and keep on doing so for a few months before you gain a bit of credibility.
First let’s say you have a bad start and you lose money at the beginning. With a 10% drawdown you’re most certainly out but even with a 5% drawdown the chances of seeing your allocation reduced are very high. This has significant implications on your strategies. Let’s assume that if you lose 5% your allocation is divided by 2 and you come back to your initial allocation only when you passed the high water mark again (e. g. the drawdown comes back to 0). In the chart below I simulated the experiment with one of my strategies.
You start trading in 1st June 2003 and all goes well until 23rd Jul. 2003 where your drawdown curve hits the -5% threshold (**1**). Your allocation is cut by 50% and you don’t cross back the high water mark level until 05th Dec. 2003 (**3**). If you have kept the allocation unchanged, the high water mark level would have been crossed on 28th Oct. 2003 (**2**) and by the end of the year you would have made more money.
But let’s push the reasoning a bit further. Still on the chart above, assume you get really unlucky and you start trading toward mid-June 2003. You hit the 10% drawdown limit by the beginning of August and you’re most likely out of the game. You would have started in early August your allocation would not have been cut at all and you end up doing a good year in only 4 full months of trading. In those two examples nothing has changed but your starting date….
The trading success of any individual has some form of path dependency and there is not much you can do about it. However you can control the size of a strategy’s drawdown and this should be addressed with great care. A portfolio should be diversified in every possible dimension: asset classes, investment strategies, trading frequencies etc…. From that perspective risk is your “survival variable”. If managed properly you have a chance to stay in the game long enough to realise the potential of your strategy. Otherwise you won’t be there next month to see what happens.
As usual any comments welcome.
A Simple Shiny App for Monitoring Trading Strategies – الجزء الثاني.
This is a follow up on my previous post “A Simple Shiny App for Monitoring Trading Strategies“. I added a few improvements that make the app a bit better (at least for me!). Below is the list of new features :
A sample. csv file (the one that contains the raw data) A “EndDate” drop down box allowing to specify the end of the period. A “Risk” page containing a VaR analysis and a chart of worst performance over various horizons A “How To” page explaining how to use and tailor the app to individual needs.
I also made the app totally self contained. It is now available as a stand alone product and there is no need to have R/RStudio installed on your computer to run it. It can be downloaded from the R Trader Google drive account. This version of the app runs using portable R and portable Chrome. For the keen reader, this link explains in full details how to package a Shiny app into a desktop app (Windows only for now).
1 & # 8211؛ How to install & run the app on your computer.
Create a specific folder Unzip the contain of the. zip file onto that new folder. Change the paths in the runShinyApp file to match your setings To run the app, you just have launch the run. vbs file. I also included an icon (RTraderTradingApp. ico) should you want to create a shortcut on your desktop.
ui. R: controls the layout and appearance of the app server. R: contains the instructions needed to build the app. You can load as much strategies as you want as long as the corresponding csv file has the right format (see below). shinyStrategyGeneral. R: loads the required packages and launches the app.
3 & # 8211؛ How to add a trading strategy?
Create the corresponding. csv file in the right directory Create a new input in the data reactive function (within the server. R file) Add an extra element to the choice parameter in the first selectInput in the sidebarPanel (within the ui. R file). The element’s name should match the name of the new input above.
Remove the input in the data reactive function corresponding to the strategy you want to remove (within the server. R file) Remove the element in the choice parameter in the first selectInput in the sidebarPanel corresponding to the strategy you want to remove (within the ui. R file).
Please feel free to get in touch should you have any suggestion.
A Simple Shiny App for Monitoring Trading Strategies.
In a previous post I showed how to use R, Knitr and LaTeX to build a template strategy report. This post goes a step further by making the analysis interactive. Besides the interactivity, the Shiny App also solves two problems :
I can now access all my trading strategies from a single point regardless of the instrument traded. Coupled with the Shiny interactivity, it allows easier comparison. I can focus on a specific time period.
The code used in this post is available on a Gist/Github repository. There are essentially 3 files.
ui. R : controls the layout and appearance of the app. server. R : contains the instructions needed to build the app. It loads the data and format it. There is one csv file per strategy each containing at least two columns: date and return with the following format: (“2010-12-22″,”0.04%” ). You can load as much strategies as you want as long as they have the right format. shinyStrategyG eneral. R : loads the required packages and launches the app.
This app is probably far from perfect and I will certainly improve it in the future. Feel free to get in touch should you have any suggestion.
A big thank you to the RStudio/Shiny team for such a great tool.
Using Genetic Algorithms in Quantitative Trading.
The question one should always asked him/herself when using technical indicators is what would be an objective criteria to select indicators parameters (e. g., why using a 14 days RSI rather than 15 or 20 days?). Genetic algorithms (GA) are well suited tools to answer that question. In this post I’ll show you how to set up the problem in R. Before I proceed the usual reminder: What I present in this post is just a toy example and not an invitation to invest. It’s not a finished strategy either but a research idea that needs to be further researched, developed and tailored to individual needs.
What are genetic algorithms?
The best description of GA I came across comes from Cybernatic Trading a book by Murray A. Ruggiero. “Genetic Algorithms were invented by John Holland in the mid-1970 to solve hard optimisation problems. This method uses natural selection, survival of the fittest”. The general process follows the steps below:
Encode the problem into chromosomes Using the encoding, develop a fitness function for use in evaluating each chromosome’s value in solving a given problem Initialize a population of chromosomes Evaluate each chromosome in the population Create new chromosomes by mating two chromosomes. This is done by muting and recombining two parents to form two children (parents are selected randomly but biased by their fitness) Evaluate the new chromosome Delete a member of the population that is less fit than the new chromosome and insert the new chromosome in the population. If the stop criteria is reached (maximum number of generations, fitness criteria is good enough…) then return the best chromosome alternatively go to step 4.
From a trading perspective GA are very useful because they are good at dealing with highly nonlinear problems. However they exhibit some nasty features that are worth mentioning:
Over fitting: This is the main problem and it’s down to the analyst to set up the problem in a way that minimises this risk. Computing time : If the problem isn’t properly defined, it can be extremely long to reach a decent solution and the complexity increases exponentially with the number of variables. Hence the necessity to carefully select the parameters.
There are several R packages dealing with GA, I chose to use the most common one: rgenoud.
Daily closing prices for most liquid ETFs from Yahoo finance going back to January 2000. The in sample period goes from January 2000 to December 2010. The Out of sample period starts on January 2011.
The logic is as following: the fitness function is optimised over the in sample period to obtain a set of optimal parameters for the selected technical indicators. The performance of those indicators is then evaluated in the out of sample period. But before doing so the technical indicators have to be selected.
The equity market exhibits two main characteristics that are familiar to anyone with some trading experience. Long term momentum and short term reversal. Those features can be translated in term of technical indicators by: moving averages cross over and RSI. This represents a set of 4 parameters: Look-back periods for long and short term moving averages, look-back period for RSI and RSI threshold. The sets of parameters are the chromosomes . The other key element is the fitness function . We might want to use something like: maximum return or Sharpe ratio or minimum average Drawdown. In what follows, I chose to maximise the Sharpe ratio.
The R implementation is a set of 3 functions:
fitnessFunction : defines the fitness function (e. g., maximum Sharpe ratio) to be used within the GA engine tradingStatistics : summary of trading statistics for the in and out of sample periods for comparison purposes genoud : the GA engine from the rgenoud package.
The genoud function is rather complex but I’m not going to explain what each parameter means as I want to keep this post short (and the documentation is really good).
In the table below I present for each instrument the optimal parameters (RSI look-back period, RSI threshold, Short Term Moving Average, and Long Term Moving Average) along with the in and out of sample trading statistics.
Before commenting the above results, I want to explain a few important points. To match the logic defined above, I bounded the parameters to make sure the look-back period for the long term moving average is always longer that the shorter moving average. I also constrained the optimiser to choose only the solutions with more than 50 trades in the in sample period (e. g;, statistical significance).
Overall the out of sample results are far from impressive. The returns are low even if the number of trades is small to make the outcome really significant. However there’s a significant loss of efficiency between in and out of sample period for Japan (EWJ) which very likely means over fitting.
This post is intended to give the reader the tools to properly use GA in a quantitative trading framework. Once again, It’s just an example that needs to be further refined. A few potential improvement to explore would be:
fitness function : maximising the Sharpe ratio is very simplistic. A “smarter” function would certainly improve the out of sample trading statistics pattern : we try to capture a very straightforward pattern. A more in depth pattern research is definitely needed. optimisation : there are many ways to improve the way the optimisation is conducted. This would improve both the computation speed and the rationality of the results.
The code used in this post is available on a Gist repository.

No comments:

Post a Comment