Sunday 4 March 2018

R نظام تداول اللغة


أرشيف المبتدئين R تغذية رسس لهذا القسم استخدام الاحتمالات والإحصاءات في كل مكان في التمويل الكمي. كل من الأسعار الملحوظة، وحجم، ومعدلات وصول النظام، وما إلى ذلك، ويرجع ذلك إلى العرض والطلب الاختلالات. ومع ذلك، فإن تتبع جميع اختلالات العرض والطلب يصبح مرهقا مع زيادة عدد المتغيرات. أدوات إحصائية حيوية في شرح ونمذجة هذه هيليب في هذه المحاضرة سوف نناقش المقدرين الإحصائيين، والتحقيق في قانون الأعداد الكبيرة، ونظرية الحد المركزي وننظر في تنفيذ كل هذه المفاهيم ضمن R. السكان مقابل عينة الإحصاءات النظر في مجموعة من الأرقام : 102، 103.2، 102، 101.2، 499، 103.2 101.23، 99.2. وهنا بعض الأسئلة التي قد ترغب في طرحها حول هذه هيليب تحليل الانحدار الانحدار هو موضوع مهم جدا. وهو أداة إحصائية تستخدم على نطاق واسع في الاقتصاد، نانسي والتجارة. R يوفر وظائف مكتوبة مسبقا التي تؤدي الانحدارات الخطية بطريقة واضحة جدا. هناك عدة حزم إضافية تسمح بالوظائف الأكثر تقدما. في هذه الفئة، ونحن سوف تستخدم فقط لم () الدالة التي هيليب المصفوفات في R مصفوفة هو بناء رياضي مفيد جدا. المصفوفات توفر آلية للتلاعب بسهولة مجموعات كبيرة من البيانات. مصفوفة الرياضيات هو موضوع واسع، وهناك العديد من الأوراق والمنشورات التي تتحدث عن جميع الاستخدامات الممكنة للمصفوفات. ويكفي أن أقول أن هذه الفئة هو الذهاب فقط إلى هيليب الطبقة الأولى بمثابة مقدمة ل R البيئة. تم عرض حاويات البيانات الأساسية c ()، ماتريكس ()، data. frame ()، والقائمة () وعرضت بعض الوظائف المفيدة. هذه الفئة الثانية سوف تغطي وظائف المعرفة من قبل المستخدم. عند التعامل مع أي نوع من مشروع تحليل البيانات، من المهم أن تكون قادرة على خلق وظائف بسيطة هيليبيست لغة البرمجة لأنظمة التداول حسابي واحدة من الأسئلة الأكثر شيوعا التي أتلقى في كيس البريد قس هو ما هي أفضل لغة برمجة للتداول حسابي. الجواب القصير هو أنه لا توجد أفضل لغة. يجب النظر في معايير الاستراتيجية، والأداء، نمطية، والتنمية، والمرونة والتكلفة. سوف توضح هذه المقالة المكونات الضرورية لهيكل نظام التداول الخوارزمي وكيف تؤثر القرارات المتعلقة بالتنفيذ على اختيار اللغة. أولا، سيتم النظر في المكونات الرئيسية لنظام التداول الخوارزمي، مثل أدوات البحث، ومحفظة المحفظة، ومدير المخاطر ومحرك التنفيذ. وفي وقت لاحق، سيتم دراسة استراتيجيات التداول المختلفة وكيفية تأثيرها على تصميم النظام. على وجه الخصوص وتيرة التداول وحجم التداول المحتمل على حد سواء سيتم مناقشتها. مرة واحدة وقد تم اختيار استراتيجية التداول، فمن الضروري لمهندس النظام بأكمله. وهذا يشمل اختيار الأجهزة، ونظام التشغيل (ق) ومرونة النظام ضد الأحداث النادرة، التي يحتمل أن تكون كارثية. وبينما يجري النظر في العمارة، يجب إيلاء الاعتبار الواجب للأداء - سواء لأدوات البحث أو لبيئة التنفيذ المباشر. ما هو نظام التداول محاولة القيام به قبل اتخاذ قرار بشأن أفضل لغة لكتابة نظام التداول الآلي من الضروري تحديد المتطلبات. هل سيستمر النظام على أساس التنفيذ بحتة هل يتطلب النظام إدارة المخاطر أو وحدة بناء المحفظة سوف يتطلب النظام باكتستر عالي الأداء بالنسبة لمعظم الاستراتيجيات يمكن تقسيم نظام التداول إلى فئتين: البحث وتوليد الإشارة. وتتعلق البحوث بتقييم أداء الاستراتيجية على البيانات التاريخية. إن عملية تقييم إستراتيجية التداول على بيانات السوق السابقة تعرف ب "الاختبار المسبق". وسيكون حجم البيانات والتعقيد الخوارزمي لها تأثير كبير على كثافة الحسابية من باكتستر. سرعة وحدة المعالجة المركزية والتزامن غالبا ما تكون العوامل المحددة في تحسين سرعة تنفيذ البحث. ويتعلق توليد الإشارة بتوليد مجموعة من إشارات التداول من خوارزمية وإرسال هذه الأوامر إلى السوق، وعادة عن طريق الوساطة. بالنسبة لبعض الإستراتیجیات، یلزم وجود مستوى عال من الأداء. غالبا ما تكون قضايا إو مثل عرض النطاق الترددي للشبكة والكمون العامل المحدد في تحسين أنظمة التنفيذ. وبالتالي فإن اختيار اللغات لكل مكون من مكونات النظام بأكمله قد يكون مختلفا تماما. النوع والتواتر وحجم االستراتيجية سيكون لنوع االستراتيجية الخوارزمية المستخدمة تأثير كبير على تصميم النظام. وسوف يكون من الضروري النظر في الأسواق التي يجري تداولها، والاتصال ببائعي البيانات الخارجية، وتواتر وحجم الاستراتيجية، والمفاضلة بين سهولة التنمية وتحسين الأداء، فضلا عن أي أجهزة مخصصة، بما في ذلك العرف المشترك والخوادم، وحدات معالجة الرسومات أو فبغا التي قد تكون ضرورية. خيارات التكنولوجيا لاستراتيجية منخفضة الأسهم الأسهم الولايات المتحدة سوف تختلف اختلافا كبيرا عن تلك التي من استراتيجية عالية التردد التحكيم الإحصائية التداول في سوق العقود الآجلة. قبل اختيار اللغة يجب تقييم العديد من بائعي البيانات التي تتعلق باستراتيجية في متناول اليد. سيكون من الضروري النظر في الاتصال بالمورد، وهيكل أي واجهات برمجة تطبيقات، وتوقيت البيانات، ومتطلبات التخزين والمرونة في مواجهة البائع الذي يعمل دون اتصال. ومن الحكمة أيضا أن تمتلك إمكانية الوصول السريع إلى بائعين متعددين تمتلك الأدوات المختلفة جميعها مخزونات تخزين خاصة بها، ومن الأمثلة على ذلك رموز شريط متعددة للأسهم وتاريخ انتهاء الصلاحية للعقود الآجلة (ناهيك عن أي بيانات أوتك محددة). ويتعين مراعاة ذلك في تصميم المنصة. ومن المرجح أن يكون تكرار الاستراتيجية واحدا من أكبر العوامل الدافعة لكيفية تحديد كومة التكنولوجيا. الاستراتيجيات التي تستخدم بيانات أكثر تواترا من الحانات بدقة أو الثانية تتطلب اهتماما كبيرا فيما يتعلق بالأداء. وتؤدي الاستراتيجية التي تتجاوز الحدود الثانية (أي بيانات القراد) إلى تصميم مدعوم بالأداء باعتباره الشرط الأساسي. وبالنسبة للاستراتيجيات ذات التردد العالي، سيلزم تخزين كمية كبيرة من بيانات السوق وتقييمها. برامج مثل HDF5 أو كدب تستخدم عادة لهذه الأدوار. من أجل معالجة كميات واسعة من البيانات اللازمة لتطبيقات هفت، يجب أن تستخدم على نطاق واسع باكتستر ونظام التنفيذ. سيسي (ربما مع بعض المجمع) من المرجح أن أقوى مرشح اللغة. وسوف تتطلب استراتيجيات فائقة التردد تقريبا تقريبا الأجهزة المخصصة مثل فبغاس وتبادل تبادل الموقع و كيرنالنيتورك واجهة ضبط. نظم البحوث نظم البحوث عادة ما تنطوي على مزيج من التنمية التفاعلية والنصوص الآلي. وغالبا ما يحدث الأول داخل إيد مثل فيسوال ستوديو، ماتلاب أو R ستوديو. ويشمل هذا الأخير حسابات عددية واسعة النطاق على العديد من المعلمات ونقاط البيانات. وهذا يؤدي إلى اختيار اللغة توفير بيئة مباشرة لاختبار التعليمات البرمجية، ولكن أيضا يوفر أداء كافيا لتقييم الاستراتيجيات على أبعاد متعددة المعلمة. تتضمن إيديس النموذجية في هذا المجال ميكروسوفت فيسوال سيسي، الذي يحتوي على أدوات مساعدة التصحيح واسعة، وقدرات اكتمال التعليمات البرمجية (عبر إنتليزنس) ومحات عامة مباشرة من كومة المشروع بأكمله (عبر قاعدة البيانات أورم، لينق) ماتلاب. والتي تم تصميمها لالجبر العددي واسعة العمليات الجبرية و فيكتوريسد، ولكن بطريقة تفاعلية وحدة التحكم R ستوديو. الذي يلتف وحدة تحكم اللغة الإحصائية R في إيد إكليبس إيد كاملة لينكس جافا و C و إيدس شبه الملكية مثل إنوهت الستارة ل بيثون، والتي تشمل مكتبات تحليل البيانات مثل نومبي. SciPy. سسيكيت-تعلم والباندا في بيئة تفاعلية واحدة (وحدة التحكم). ل باكتستينغ العددية، جميع اللغات المذكورة أعلاه هي مناسبة، على الرغم من أنه ليس من الضروري استخدام غويد كما سيتم تنفيذ التعليمات البرمجية في الخلفية. الاعتبار الرئيسي في هذه المرحلة هو سرعة التنفيذ. وغالبا ما تكون اللغة المترجمة (مثل C) مفيدة إذا كانت أبعاد معلمة باكتستينغ كبيرة. تذكر أنه من الضروري أن نكون حذرين من مثل هذه الأنظمة إذا كان هذا هو الحال في اللغات المترجمة مثل بيثون في كثير من الأحيان الاستفادة من المكتبات عالية الأداء مثل نومبيبانداس لخطوة باكتستينغ، من أجل الحفاظ على درجة معقولة من القدرة التنافسية مع معادلات مجمعة. في نهاية المطاف سيتم تحديد اللغة المختارة لل باكتستينغ من قبل الاحتياجات الخوارزمية محددة وكذلك مجموعة من المكتبات المتاحة في اللغة (أكثر على ذلك أدناه). ومع ذلك، فإن اللغة المستخدمة لباكتستر والبيئات البحثية يمكن أن تكون مستقلة تماما عن تلك المستخدمة في بناء محفظة، وإدارة المخاطر ومكونات التنفيذ، كما سيتبين. إدارة المحفظة وإدارة المخاطر غالبا ما يتم تجاهل مكونات بناء المحفظة وإدارة المخاطر من قبل تجار التجزئة الخوارزمية. هذا هو دائما تقريبا خطأ. وتوفر هذه الأدوات الآلية التي سيتم من خلالها الحفاظ على رأس المال. أنها لا تحاول فقط لتخفيف عدد الرهانات محفوفة بالمخاطر، ولكن أيضا تقليل زبد من الصفقات نفسها، والحد من تكاليف المعاملات. يمكن أن يكون للإصدارات المتطورة من هذه المكونات تأثير كبير على جودة وانسجام الربحية. فمن السهل إنشاء استراتيجيات مستقرة حيث يمكن بسهولة تعديل آلية بناء المحفظة ومدير المخاطر للتعامل مع أنظمة متعددة. ومن ثم ينبغي اعتبارها عناصر أساسية في بداية تصميم نظام تجاري حسابي. وظيفة نظام بناء محفظة هو اتخاذ مجموعة من الصفقات المطلوبة وإنتاج مجموعة من الصفقات الفعلية التي تقلل من زبد، والحفاظ على التعرض لعوامل مختلفة (مثل القطاعات وفئات الأصول والتقلب وغيرها) وتحسين تخصيص رأس المال لمختلف استراتيجيات في محفظة. غالبا ما يقلل بناء الحافظة من مشكلة الجبر الخطي (مثل معامل المصفوفة)، وبالتالي يعتمد الأداء بشكل كبير على فعالية تنفيذ الجبر الخطي العددي المتوفر. وتشمل المكتبات العامة أوبلاس. لاباك و ناغ ل C. ماتلاب تمتلك أيضا عمليات مصفوفة الأمثل على نطاق واسع. يستخدم بيثون نومبيسيبي لمثل هذه الحسابات. وستتطلب المحفظة التي تتم إعادة توازنها بشكل متكرر مكتبة مصفوفة مجمعة (ومثبتة جيدا) لتنفيذ هذه الخطوة، حتى لا تعيق نظام التداول. إدارة المخاطر جزء آخر مهم للغاية من نظام التداول الخوارزمي. يمكن أن تأتي المخاطر بأشكال عديدة: زيادة التقلبات (على الرغم من أن ذلك قد يكون مرغوبا فيه لاستراتيجيات معينة)، وزيادة الارتباطات بين فئات الأصول، والتخلف عن الطرف المقابل، وانقطاعات الخادم، وأحداث البجعة السوداء، والبق غير المكتشفة في رمز التداول، قليل. وتسعى مكونات إدارة المخاطر إلى التنبؤ بآثار التقلبات المفرطة والروابط بين فئات األصول وتأثيرها الالحق على رأس المال المتداول. في كثير من الأحيان هذا يقلل إلى مجموعة من الحسابات الإحصائية مثل اختبارات الإجهاد مونت كارلو. وهذا يشبه إلى حد كبير الاحتياجات الحسابية لمحرك تسعير المشتقات وعلى هذا النحو سوف تكون مرتبطة بو. هذه المحاكاة هي موازية للغاية (انظر أدناه)، وإلى حد ما، فمن الممكن لرمي الأجهزة في هذه المشكلة. أنظمة التنفيذ تتمثل مهمة نظام التنفيذ في تلقي إشارات التداول التي تمت تصفيتها من مكونات بناء المحفظة وإدارة المخاطر وإرسالها إلى وساطة أو أي وسيلة أخرى للوصول إلى الأسواق. بالنسبة لمعظم استراتيجيات التداول خوارزمية التجزئة وهذا ينطوي على اتصال أبي أو فيكس إلى الوساطة مثل وسطاء التفاعلية. الاعتبارات الأساسية عند اتخاذ قرار بشأن لغة تشمل جودة أبي، توفر اللغة المجمع ل أبي، وتيرة التنفيذ والانزلاق المتوقع. تشير جودة أبي إلى مدى توثيقها بشكل جيد، أي نوع من الأداء الذي توفره، سواء كانت تحتاج إلى برنامج مستقل يمكن الوصول إليه أو ما إذا كان يمكن إنشاء بوابة بطريقة بدون رأس (أي عدم وجود واجهة المستخدم الرسومية). في حالة الوسطاء التفاعليين، يجب أن تعمل أداة ترادر ​​وركستاتيون في بيئة واجهة المستخدم الرسومية من أجل الوصول إلى واجهة برمجة التطبيقات الخاصة بهم. كان لي مرة واحدة لتثبيت طبعة أوبونتو سطح المكتب على خادم سحابة الأمازون للوصول إلى وسطاء التفاعلية عن بعد، بحتة لهذا السبب معظم واجهات برمجة التطبيقات توفر واجهة C أندور جافا. وعادة ما يصل إلى المجتمع لتطوير مغلفات لغة محددة ل C، بيثون، R، إكسل و ماتلاب. لاحظ أنه مع كل الإضافات الإضافية المستخدمة (وخاصة أبي مغلفات) هناك مجال للخلل لزحف إلى النظام. دائما اختبار الإضافات من هذا النوع وضمان الحفاظ عليها بنشاط. مقياس جدير بالاهتمام هو معرفة عدد التحديثات الجديدة التي تم إجراؤها على كودباس في الأشهر الأخيرة. تردد التنفيذ هو في غاية الأهمية في خوارزمية التنفيذ. لاحظ أن المئات من الطلبات قد يتم إرسالها كل دقيقة، وعلى هذا النحو أمر بالغ الأهمية. سوف يتم تكبد الانزلاق من خلال نظام التنفيذ سيئة الأداء وهذا سيكون له تأثير كبير على الربحية. وتعتبر اللغات المكتوبة إحصائيا (انظر أدناه) مثل سغافا هي الأمثل عموما للتنفيذ ولكن هناك مفاضلة في وقت التطوير والاختبار وسهولة الصيانة. اللغات التي يتم كتابتها ديناميكيا، مثل بيثون و بيرل هي الآن سريعة بشكل عام. تأكد دائما من تصميم المكونات بطريقة نمطية (انظر أدناه) بحيث يمكن تبديلها خارجا كمقاييس النظام. التخطيط المعماري وعملية التطوير تمت مناقشة مكونات نظام التداول ومتطلباته من حيث الحجم والحجم، ولكن البنية التحتية للنظام لم يتم تغطيتها بعد. أولئك الذين يعملون كمتاجر التجزئة أو يعملون في صندوق صغير من المرجح أن يرتدي العديد من القبعات. وسوف يكون من الضروري أن تغطي نموذج ألفا، وإدارة المخاطر والتنفيذ المعلمات، وأيضا التنفيذ النهائي للنظام. قبل مناقشة لغات محددة، سيتم مناقشة تصميم بنية النظام الأمثل. الفصل بين الشواغل من أهم القرارات التي يجب اتخاذها في البداية كيفية فصل شواغل نظام تجاري. في تطوير البرمجيات، وهذا يعني أساسا كيفية تفريق مختلف جوانب النظام التجاري إلى مكونات وحدات منفصلة. من خلال تعريض الواجهات في كل من المكونات من السهل مبادلة أجزاء من النظام للنسخ الأخرى التي تساعد على الأداء، والموثوقية أو الصيانة، دون تعديل أي رمز التبعية الخارجية. وهذه هي أفضل ممارسة لهذه النظم. وبالنسبة للاستراتيجيات في الترددات المنخفضة، ينصح بهذه الممارسات. فبالنسبة لتداول الترددات العالية جدا، قد يكون من الضروري تجاهل قاعدة البيانات على حساب التغيير والتبديل في النظام للحصول على المزيد من الأداء. قد يكون من المرغوب فيه نظام أكثر إحكاما. إن إنشاء خريطة مكونة لنظام التداول الخوارزمي يستحق مقالا في حد ذاته. ومع ذلك، فإن النهج الأمثل هو التأكد من وجود مكونات منفصلة للمدخلات بيانات السوق التاريخية والحقيقية، وتخزين البيانات، أبي الوصول إلى البيانات، باكتستر، معايير الاستراتيجية، بناء محفظة وإدارة المخاطر وأنظمة التنفيذ الآلي. على سبيل المثال، إذا كان مخزن البيانات قيد الاستخدام حاليا ضعيفا، حتى عند مستويات كبيرة من التحسين، يمكن تبديله مع الحد الأدنى من إعادة الكتابة إلى ابتلاع البيانات أو أبي الوصول إلى البيانات. بقدر ما باكتستر والمكونات اللاحقة المعنية، ليس هناك فرق. فائدة أخرى من المكونات فصل هو أنه يسمح لمجموعة متنوعة من لغات البرمجة لاستخدامها في النظام العام. ليست هناك حاجة إلى أن تقتصر على لغة واحدة إذا كانت طريقة الاتصال من مكونات اللغة مستقلة. وسيكون هذا هو الحال إذا كانت تتصل عبر تكبيب، زيرومق أو بعض بروتوكول آخر اللغة مستقلة. كمثال ملموس، والنظر في حالة نظام باكتستينغ يجري كتابتها في C لعدد أداء الطحن، في حين تتم كتابة مدير محفظة ونظم التنفيذ في بايثون باستخدام سسيبي و إبي. اعتبارات الأداء الأداء هو أحد الاعتبارات الهامة لمعظم استراتيجيات التداول. لاستراتيجيات تردد أعلى هو العامل الأكثر أهمية. الأداء يغطي مجموعة واسعة من القضايا، مثل سرعة التنفيذ الخوارزمية، الكمون الشبكة، عرض النطاق الترددي، إو البيانات، كونكورنسيباراليليسم والتحجيم. كل من هذه المجالات هي التي تغطيها بشكل فردي الكتب المدرسية الكبيرة، لذلك هذه المادة سوف تخدش فقط سطح كل موضوع. سيتم الآن مناقشة الهندسة المعمارية واختيار اللغة من حيث آثارها على الأداء. الحكمة السائدة كما ذكر دونالد نوث. واحدة من آباء علوم الحاسوب، هو أن التحسين المبكر هو جذر كل الشر. هذا هو الحال دائما تقريبا - إلا عند بناء خوارزمية التداول عالية التردد بالنسبة لأولئك الذين يرغبون في استراتيجيات التردد المنخفض، نهج مشترك هو بناء نظام في أبسط طريقة ممكنة وتحسين فقط كما تبدأ الاختناقات في الظهور. وتستخدم أدوات التنميط لتحديد أين تنشأ الاختناقات. يمكن أن تكون ملامح لجميع العوامل المذكورة أعلاه، إما في بيئة ويندوز أو لينوكس. هناك العديد من أنظمة التشغيل وأدوات اللغة المتاحة للقيام بذلك، فضلا عن المرافق طرف ثالث. وسيتم الآن مناقشة اختيار اللغة في سياق الأداء. C، جافا، بيثون، R و ماتلاب كلها تحتوي على مكتبات عالية الأداء (إما كجزء من معيارها أو خارجيا) لبنية البيانات الأساسية والعمل الخوارزمية. C مع مكتبة قالب قياسي، في حين يحتوي بيثون نومبيسيبي. المهام الرياضية المشتركة هي التي يمكن العثور عليها في هذه المكتبات ونادرا ما تكون مفيدة لكتابة تنفيذ جديد. ويتمثل أحد الاستثناءات في ما إذا كانت معمارية الأجهزة عالية التخصيص مطلوبة، وأن الخوارزمية تستخدم استخداما موسعا للملحقات الخاصة (مثل مخابئ مخصصة). ومع ذلك، في كثير من الأحيان إعادة اختراع الوقت النفايات العجلة التي يمكن أن تنفق بشكل أفضل تطوير وتحسين أجزاء أخرى من البنية التحتية التجارية. وقت التطوير ثمين للغاية وخاصة في سياق المطورين الوحيد. وكثيرا ما يكون الكمون مشكلة في نظام التنفيذ حيث أن أدوات البحث عادة ما تكون موجودة على نفس الجهاز. بالنسبة إلى السابق، يمكن أن يحدث الكمون عند نقاط متعددة على طول مسار التنفيذ. يجب استشارة قواعد البيانات (الكمون ديسكنتورك)، يجب أن يتم إنشاء إشارات (التشغيل سيست، الكمون الرسائل الكمون)، إشارات التجارة المرسلة (نيك الكمون) وأوامر معالجتها (الكمون نظم التبادل الداخلي). لعمليات تردد أعلى من الضروري أن تصبح مألوفة على نحو وثيق مع التحسين الأمثل، فضلا عن الأمثل لنقل الشبكة. هذا هو مجال عميق و هو إلى حد كبير خارج نطاق هذه المادة ولكن إذا كان المطلوب خوارزمية أوفت ثم يكون على بينة من عمق المعرفة المطلوبة التخزين المؤقت مفيد جدا في مجموعة أدوات مطور التداول الكمي. التخزين المؤقت يشير إلى مفهوم تخزين البيانات التي يتم الوصول إليها بشكل متكرر بطريقة تسمح بالوصول إلى الأداء العالي، على حساب احتمال عدم دقة البيانات. تحدث حالة الاستخدام الشائعة في تطوير الويب عند أخذ البيانات من قاعدة بيانات علائقية تدعمها الأقراص ووضعها في الذاكرة. أي طلبات لاحقة للبيانات لا تضطر إلى ضرب قاعدة البيانات وبالتالي المكاسب الأداء يمكن أن تكون كبيرة. للتداول حالات التخزين المؤقت يمكن أن تكون مفيدة للغاية. على سبيل المثال، يمكن تخزين الحالة الحالية لمحفظة إستراتيجية في ذاكرة التخزين المؤقت حتى يتم إعادة توازنها، بحيث لا تحتاج القائمة إلى إعادة توليدها عند كل حلقة من خوارزمية التداول. ومن المرجح أن يكون هذا وحدة المعالجة المركزية عالية أو عملية إو القرص من هذا التجدد. ومع ذلك، التخزين المؤقت لا يخلو من القضايا الخاصة بها. تجديد بيانات ذاكرة التخزين المؤقت في كل مرة، ويرجع ذلك إلى طبيعة فوليلي تخزين ذاكرة التخزين المؤقت، يمكن أن تضع طلبا كبيرا على البنية التحتية. قضية أخرى هي الكلب تتراكم. حيث يتم تنفيذ أجيال متعددة من نسخة مخبأ جديدة تحت حمولة عالية للغاية، الأمر الذي يؤدي إلى فشل سلسلة. تخصيص الذاكرة الديناميكية عملية مكلفة في تنفيذ البرامج. وبالتالي فإنه من الضروري لتطبيقات التداول أداء أعلى أن تكون على بينة جيدا كيف يتم تخصيص الذاكرة وإزالة ديالوكاتد خلال تدفق البرنامج. معايير اللغة الأحدث مثل جافا و C و بيثون جميعها تؤدي تلقائيا لجمع القمامة. الذي يشير إلى ديالوكاتيون الذاكرة المخصصة حيوي عندما تخرج الكائنات من النطاق. جمع القمامة مفيد للغاية أثناء التطوير لأنه يقلل من الأخطاء ويساعد القراءة. ومع ذلك، فإنه غالبا ما يكون دون المستوى الأمثل لبعض استراتيجيات التداول عالية التردد. عادة ما تكون هناك حاجة لجمع القمامة المخصصة لهذه الحالات. في جافا، على سبيل المثال، من خلال ضبط جامع القمامة وتكوين كومة الذاكرة المؤقتة، فمن الممكن الحصول على أداء عال لاستراتيجيات هفت. C لا توفر جامع القمامة الأصلي ولذلك فمن الضروري التعامل مع جميع تخصيص الذاكرة تخصيص كجزء من تنفيذ الكائنات. في حين يحتمل أن يكون عرضة للخطأ (يحتمل أن يؤدي إلى مؤشرات التعلق) من المفيد للغاية أن يكون التحكم الدقيق الحبيبات لكيفية ظهور الكائنات على كومة لتطبيقات معينة. عند اختيار لغة تأكد من دراسة كيفية عمل جامع القمامة وما إذا كان يمكن تعديلها لتحسين حالة استخدام معينة. العديد من العمليات في أنظمة التداول الخوارزمية هي قابلة للتوازي. ويشير هذا إلى مفهوم تنفيذ عمليات برمجية متعددة في نفس الوقت، أي بالتوازي. ما يسمى خوارزميات موازية محرج تشمل الخطوات التي يمكن حسابها بشكل مستقل تماما عن الخطوات الأخرى. بعض العمليات الإحصائية، مثل محاكاة مونتي كارلو، هي مثال جيد للخوارزميات المتوازية بشكل محرج حيث يمكن حساب كل سحب عشوائي وعملية المسار اللاحقة دون معرفة مسارات أخرى. الخوارزميات الأخرى هي موازية جزئيا فقط. ديناميات السوائل المحاكاة هي مثل هذا المثال، حيث مجال الحساب يمكن تقسيمها، ولكن في نهاية المطاف يجب أن هذه المجالات التواصل مع بعضها البعض، وبالتالي فإن العمليات هي متتابعة جزئية. خوارزميات متوازية تخضع لقانون أمدهلز. التي توفر حد أعلى نظريا لزيادة أداء خوارزمية موازية عندما تخضع لعمليات منفصلة N (على سبيل المثال على وحدة المعالجة المركزية الأساسية أو موضوع). أصبح باراليليساتيون ذات أهمية متزايدة كوسيلة للتحسين منذ ركض سرعة المعالج على مدار الساعة، كما تحتوي المعالجات الأحدث العديد من النوى التي لإجراء حسابات موازية. وقد أدى ارتفاع أجهزة الرسومات الاستهلاكية (في الغالب لألعاب الفيديو) إلى تطوير وحدات المعالجة الرسومية (غبوس)، التي تحتوي على مئات من النوى لعمليات متزامنة للغاية. وأصبحت وحدات معالجة الجرافيك هذه بأسعار معقولة جدا. وقد أدت الأطر الرفيعة المستوى، مثل نفيدياس كودا، إلى اعتماد واسع النطاق في الأوساط الأكاديمية والمالية. هذه الأجهزة غبو عادة ما تكون مناسبة فقط للجانب البحثي من التمويل الكمي، في حين يتم استخدام الأجهزة الأخرى أكثر تخصصا (بما في ذلك الميدان بوابة برمجة صفائف - فبغاس) ل (U) هفت. في الوقت الحاضر، معظم لانغوجيس الحديثة تدعم درجة من التزامنالتزامن. وبالتالي فمن مباشرة لتحسين باكتستر، لأن جميع الحسابات مستقلة بشكل عام عن الآخرين. يشير التحجيم في هندسة البرمجيات والعمليات إلى قدرة النظام على التعامل مع الأحمال المتزايدة باستمرار في شكل طلبات أكبر، واستخدام المعالج العالي والمزيد من تخصيص الذاكرة. في التداول الخوارزمي استراتيجية قادرة على نطاق إذا كان يمكن قبول كميات أكبر من رأس المال، ولا تزال تنتج عائدات متسقة. جداول تكديس تكنولوجيا التداول إذا كان يمكن أن تحمل حجم التجارة أكبر وزيادة الكمون، دون الاختناقات. في حين يجب أن تصمم النظم على نطاق واسع، فإنه غالبا ما يكون من الصعب التنبؤ مسبقا حيث سيحدث عنق الزجاجة. وسيساعد قطع الأشجار، والاختبار، والتنميط، والرصد على نحو كبير في السماح للنظام بتوسيع نطاقه. وغالبا ما توصف اللغات نفسها بأنها غير قابلة للتحصيل. وهذا عادة ما يكون نتيجة للتضليل، وليس الحقيقة الصعبة. هذا هو إجمالي كومة التكنولوجيا التي ينبغي التأكد من قابلية، وليس اللغة. ومن الواضح أن لغات معينة لها أداء أكبر من غيرها في حالات الاستخدام على وجه الخصوص، ولكن لغة واحدة أفضل من أي شيء آخر بكل معنى الكلمة. إحدى وسائل إدارة المقياس هي فصل المخاوف، كما ذكرنا سابقا. ومن أجل زيادة القدرة على التعامل مع الزيادات في النظام (أي التقلبات المفاجئة التي تؤدي إلى مجموعة كبيرة من الصفقات)، من المفيد إنشاء بنية انتظار للطوابع. وهذا يعني ببساطة وضع نظام طابور رسائل بين المكونات بحيث يتم تجميع أوامر حتى إذا كان مكون معين غير قادر على معالجة العديد من الطلبات. بدلا من أن يتم فقدان الطلبات يتم الاحتفاظ بها ببساطة في كومة حتى يتم التعامل مع الرسالة. هذا مفيد بشكل خاص لإرسال الصفقات إلى محرك التنفيذ. إذا كان المحرك يعاني تحت الكمون الثقيل ثم فإنه سيتم النسخ الاحتياطي الصفقات. وهناك طابور بين مولد إشارة التجارة و أبي التنفيذ تخفيف هذه المسألة على حساب احتمال انزلاق التجارة. A وسيط قائمة انتظار رسالة مفتوحة المصدر يحظى باحترام كبير هو رابيتمق. الأجهزة وأنظمة التشغيل الأجهزة التي تعمل استراتيجيتك يمكن أن يكون لها تأثير كبير على ربحية خوارزمية الخاص بك. هذه ليست قضية تقتصر على التجار عالية التردد إما. يمكن أن يؤدي اختيار ضعيف في الأجهزة ونظام التشغيل إلى تعطل الجهاز أو إعادة التشغيل في اللحظة الأكثر من غير المناسب. وبالتالي فمن الضروري النظر في المكان الذي سيقام فيه طلبك. الاختيار هو عادة بين جهاز سطح المكتب الشخصي، خادم بعيد، مزود سحابة أو خادم تبادل مشترك. أجهزة سطح المكتب بسيطة لتثبيت وإدارة، وخاصة مع أحدث أنظمة التشغيل ودية المستخدم مثل ويندوز 78، ماك أوسك و أوبونتو. ولكن أنظمة سطح المكتب تمتلك بعض العيوب الهامة. في المقام الأول هو أن إصدارات أنظمة التشغيل المصممة لآلات سطح المكتب من المرجح أن تتطلب إعادة التشغيل (وغالبا في أسوأ الأوقات). كما أنها تستخدم المزيد من الموارد الحسابية بحكم الحاجة إلى واجهة المستخدم الرسومية (غوي). استخدام الأجهزة في المنزل (أو المكتب المحلي) البيئة يمكن أن يؤدي إلى الاتصال بالإنترنت ومشاكل الطاقة الجهوزية. الفائدة الرئيسية لنظام سطح المكتب هو أن القدرة الحصانية الحاسوبية كبيرة يمكن شراؤها لجزء من تكلفة خادم مخصص عن بعد (أو نظام سحابة القائمة) من سرعة مماثلة. إن الخادم المخصص أو الجهاز القائم على السحابة، في حين غالبا ما يكون أكثر تكلفة من خيار سطح المكتب، يسمح للبنية التحتية أكثر أهمية التكرار، مثل النسخ الاحتياطي للبيانات الآلية، والقدرة على أكثر وضوحا ضمان الجهوزية والرصد عن بعد. فهي أصعب لإدارة لأنها تتطلب القدرة على استخدام قدرات تسجيل الدخول عن بعد من نظام التشغيل. في ويندوز هذا عموما عن طريق بروتوكول سطح المكتب البعيد واجهة المستخدم الرسومية (رديب). في الأنظمة المستندة إلى أونيكس يتم استخدام سطر الأوامر الآمنة شل (سش). البنية التحتية للخادم المستندة إلى يونيكس هي دائما تقريبا سطر الأوامر على أساس الذي يجعل على الفور أدوات البرمجة القائمة على واجهة المستخدم الرسومية (مثل ماتلاب أو إكسيل) لتكون غير صالحة للاستعمال. والخادم المتواجد في الموقع، حيث تستخدم العبارة في أسواق رأس المال، هو ببساطة خادم مخصص يتواجد داخل تبادل من أجل تقليل زمن الاستجابة لخوارزمية التداول. وهذا ضروري للغاية لبعض استراتيجيات التداول عالية التردد، والتي تعتمد على الكمون المنخفض من أجل توليد ألفا. الجانب الأخير لاختيار الأجهزة واختيار لغة البرمجة هو منصة الاستقلال. هل هناك حاجة لتشغيل التعليمات البرمجية عبر أنظمة تشغيل مختلفة متعددة هل التعليمات البرمجية المصممة ليتم تشغيلها على نوع معين من بنية المعالج مثل إنتيل x86x64 أو سيكون من الممكن تنفيذ معالجات ريس مثل تلك المصنعة بواسطة أرم وستعتمد هذه القضايا اعتمادا كبيرا على تواتر ونوع الاستراتيجية الجاري تنفيذها. المرونة والاختبار واحدة من أفضل الطرق لتفقد الكثير من المال على التداول الخوارزمي هو إنشاء نظام مع عدم المرونة. هذا يشير إلى متانة النظام عند التعرض لأحداث نادرة، مثل إفلاس الوساطة، التقلبات المفاجئة المفاجئة، التوقف على نطاق المنطقة لموفر خادم السحابة أو الحذف العرضي لقاعدة بيانات التداول بأكملها. سنوات من الأرباح يمكن القضاء عليها في غضون ثوان مع بنية سيئة التصميم. فمن الضروري للغاية للنظر في قضايا مثل ديبوجنغ، والاختبار، وقطع الأشجار، والنسخ الاحتياطي، وتوافر عالية والرصد والمكونات الأساسية للنظام الخاص بك. ومن المرجح أنه في أي المعقدة المعقولة معقول تطبيق التداول الكمي على الأقل 50 من وقت التطوير سوف تنفق على التصحيح والاختبار والصيانة. تقريبا جميع لغات البرمجة إما السفينة مع المصحح المصاحبة أو تمتلك بدائل طرف ثالث يحظى باحترام كبير. في جوهرها، يسمح مصحح الأخطاء تنفيذ برنامج مع إدراج نقاط التعسفي التعسفي في مسار التعليمات البرمجية، والتي توقف مؤقتا التنفيذ من أجل التحقيق في حالة النظام. الفائدة الرئيسية من التصحيح هو أنه من الممكن للتحقيق في سلوك التعليمات البرمجية قبل نقطة تحطم معروفة. التصحيح هو عنصر أساسي في مربع الأدوات لتحليل أخطاء البرمجة. ومع ذلك، فهي تستخدم على نطاق واسع في اللغات المترجمة مثل C أو جافا، كما لغات تفسير مثل بيثون غالبا ما يكون من الأسهل لتصحيح الأخطاء بسبب لوك أقل والبيانات أقل مطول. على الرغم من هذا الاتجاه بيثون لا السفينة مع بدب. والتي هي أداة التصحيح متطورة. ميكروسوفت فيسوال C إيد يمتلك الأدوات المساعدة التصحيح واجهة المستخدم الرسومية واسعة، في حين أن سطر الأوامر لينوكس C مبرمج، مصحح أخطاء غب موجود. ويشير الاختبار في تطوير البرمجيات إلى عملية تطبيق معلمات ونتائج معروفة على وظائف وأساليب وكائنات محددة داخل كوديباس، وذلك لمحاكاة السلوك وتقييم مسارات كود متعددة، مما يساعد على ضمان أن يتصرف النظام كما ينبغي. ويعرف النموذج الأحدث باسم "التطوير القائم على الاختبار" (تد)، حيث يتم تطوير شفرة الاختبار على واجهة محددة دون تنفيذ. قبل الانتهاء من كوديباس الفعلية سوف تفشل جميع الاختبارات. كما يتم كتابة التعليمات البرمجية لملء الفراغات، والاختبارات في نهاية المطاف كل تمر، وعند هذه النقطة يجب أن تتوقف التنمية. تد يتطلب واسعة تصميم مواصفات مقدما فضلا عن درجة صحية من الانضباط من أجل القيام بنجاح. في C، يوفر بوست إطار اختبار الوحدة. في جافا، توجد مكتبة جونيت لتحقيق الغرض نفسه. لدى بيثون أيضا وحدة ونيتست كجزء من المكتبة القياسية. العديد من اللغات الأخرى تمتلك أطر اختبار الوحدة وغالبا ما تكون هناك خيارات متعددة. في بيئة الإنتاج، قطع الأشجار المتطورة ضروري للغاية. يشير التسجيل إلى عملية إخراج الرسائل، بدرجات متفاوتة من الشدة، فيما يتعلق بسلوك تنفيذ النظام إلى ملف مسطح أو قاعدة بيانات. السجلات هي السطر الأول من الهجوم عند البحث عن سلوك وقت تشغيل البرنامج غير متوقع. لسوء الحظ فإن أوجه القصور في نظام قطع الأشجار تميل فقط إلى اكتشافها بعد حقيقة كما هو الحال مع النسخ الاحتياطية التي نوقشت أدناه، ينبغي إيلاء نظام تسجيل الدخول الاعتبار الواجب قبل تصميم النظام. كل من مايكروسوفت ويندوز و لينوكس تأتي مع قدرة واسعة لتسجيل النظام و لغات البرمجة تميل إلى السفينة مع مكتبات التسجيل القياسية التي تغطي معظم حالات الاستخدام. غالبا ما يكون من الحكمة تركيز معلومات التسجيل من أجل تحليلها في وقت لاحق، حيث أنها يمكن أن تؤدي في كثير من الأحيان إلى أفكار حول تحسين الأداء أو الحد من الأخطاء، والتي سيكون لها بالتأكيد تأثير إيجابي على عوائد التداول. وفي حين أن تسجيل النظام سيوفر معلومات عما حدث في الماضي، فإن رصد تطبيق ما سيوفر نظرة ثاقبة لما يحدث الآن. وينبغي النظر في جميع جوانب النظام لأغراض الرصد. توفر مقاييس مستوى النظام مثل استخدام القرص والذاكرة المتوفرة وعرض النطاق الترددي للشبكة واستخدام وحدة المعالجة المركزية معلومات التحميل الأساسية. وينبغي أيضا مراقبة مقاييس التداول مثل السعر غير الطبيعي، والتخفيضات السريعة المفاجئة، وتعرض الحسابات لمختلف القطاعات القطاعية. وعلاوة على ذلك، ينبغي التحريض على نظام العتبة الذي يوفر الإخطار عند اختراق بعض المقاييس، ورفع طريقة الإخطار (البريد الإلكتروني، والرسائل القصيرة، مكالمة هاتفية آلية) اعتمادا على شدة المقياس. مراقبة النظام غالبا ما يكون مجال مسؤول النظام أو مدير العمليات. However, as a sole trading developer, these metrics must be established as part of the larger design. Many solutions for monitoring exist: proprietary, hosted and open source, which allow extensive customisation of metrics for a particular use case. Backups and high availability should be prime concerns of a trading system. Consider the following two questions: 1) If an entire production database of market data and trading history was deleted (without backups) how would the research and execution algorithm be affected 2) If the trading system suffers an outage for an extended period (with open positions) how would account equity and ongoing profitability be affected The answers to both of these questions are often sobering It is imperative to put in place a system for backing up data and also for testing the restoration of such data. Many individuals do not test a restore strategy. If recovery from a crash has not been tested in a safe environment, what guarantees exist that restoration will be available at the worst possible moment Similarly, high availability needs to be baked in from the start. Redundant infrastructure (even at additional expense) must always be considered, as the cost of downtime is likely to far outweigh the ongoing maintenance cost of such systems. I wont delve too deeply into this topic as it is a large area, but make sure it is one of the first considerations given to your trading system. Choosing a Language Considerable detail has now been provided on the various factors that arise when developing a custom high-performance algorithmic trading system. The next stage is to discuss how programming languages are generally categorised. Type Systems When choosing a language for a trading stack it is necessary to consider the type system . The languages which are of interest for algorithmic trading are either statically - or dynamically-typed . A statically-typed language performs checks of the types (e. g. integers, floats, custom classes etc) during the compilation process. Such languages include C and Java. A dynamically-typed language performs the majority of its type-checking at runtime. Such languages include Python, Perl and JavaScript. For a highly numerical system such as an algorithmic trading engine, type-checking at compile time can be extremely beneficial, as it can eliminate many bugs that would otherwise lead to numerical errors. However, type-checking doesnt catch everything, and this is where exception handling comes in due to the necessity of having to handle unexpected operations. Dynamic languages (i. e. those that are dynamically-typed) can often lead to run-time errors that would otherwise be caught with a compilation-time type-check. For this reason, the concept of TDD (see above) and unit testing arose which, when carried out correctly, often provides more safety than compile-time checking alone. Another benefit of statically-typed languages is that the compiler is able to make many optimisations that are otherwise unavailable to the dynamically - typed language, simply because the type (and thus memory requirements) are known at compile-time. In fact, part of the inefficiency of many dynamically-typed languages stems from the fact that certain objects must be type-inspected at run-time and this carries a performance hit. Libraries for dynamic languages, such as NumPySciPy alleviate this issue due to enforcing a type within arrays. Open Source or Proprietary One of the biggest choices available to an algorithmic trading developer is whether to use proprietary (commercial) or open source technologies. There are advantages and disadvantages to both approaches. It is necessary to consider how well a language is supported, the activity of the community surrounding a language, ease of installation and maintenance, quality of the documentation and any licensingmaintenance costs. The Microsoft. NET stack (including Visual C, Visual C) and MathWorks MatLab are two of the larger proprietary choices for developing custom algorithmic trading software. Both tools have had significant battle testing in the financial space, with the former making up the predominant software stack for investment banking trading infrastructure and the latter being heavily used for quantitative trading research within investment funds. Microsoft and MathWorks both provide extensive high quality documentation for their products. Further, the communities surrounding each tool are very large with active web forums for both. The. NET software allows cohesive integration with multiple languages such as C, C and VB, as well as easy linkage to other Microsoft products such as the SQL Server database via LINQ. MatLab also has many pluginslibraries (some free, some commercial) for nearly any quantitative research domain. There are also drawbacks. With either piece of software the costs are not insignificant for a lone trader (although Microsoft does provide entry-level version of Visual Studio for free). Microsoft tools play well with each other, but integrate less well with external code. Visual Studio must also be executed on Microsoft Windows, which is arguably far less performant than an equivalent Linux server which is optimally tuned. MatLab also lacks a few key plugins such as a good wrapper around the Interactive Brokers API, one of the few brokers amenable to high-performance algorithmic trading. The main issue with proprietary products is the lack of availability of the source code. This means that if ultra performance is truly required, both of these tools will be far less attractive. Open source tools have been industry grade for sometime. Much of the alternative asset space makes extensive use of open-source Linux, MySQLPostgreSQL, Python, R, C and Java in high-performance production roles. However, they are far from restricted to this domain. Python and R, in particular, contain a wealth of extensive numerical libraries for performing nearly any type of data analysis imaginable, often at execution speeds comparable to compiled languages, with certain caveats. The main benefit of using interpreted languages is the speed of development time. Python and R require far fewer lines of code (LOC) to achieve similar functionality, principally due to the extensive libraries. Further, they often allow interactive console based development, rapidly reducing the iterative development process. Given that time as a developer is extremely valuable, and execution speed often less so (unless in the HFT space), it is worth giving extensive consideration to an open source technology stack. Python and R possess significant development communities and are extremely well supported, due to their popularity. Documentation is excellent and bugs (at least for core libraries) remain scarce. Open source tools often suffer from a lack of a dedicated commercial support contract and run optimally on systems with less-forgiving user interfaces. A typical Linux server (such as Ubuntu) will often be fully command-line oriented. In addition, Python and R can be slow for certain execution tasks. There are mechanisms for integrating with C in order to improve execution speeds, but it requires some experience in multi-language programming. While proprietary software is not immune from dependencyversioning issues it is far less common to have to deal with incorrect library versions in such environments. Open source operating systems such as Linux can be trickier to administer. I will venture my personal opinion here and state that I build all of my trading tools with open source technologies. In particular I use: Ubuntu, MySQL, Python, C and R. The maturity, community size, ability to dig deep if problems occur and lower total cost ownership (TCO) far outweigh the simplicity of proprietary GUIs and easier installations. Having said that, Microsoft Visual Studio (especially for C) is a fantastic Integrated Development Environment (IDE) which I would also highly recommend. Batteries Included The header of this section refers to the out of the box capabilities of the language - what libraries does it contain and how good are they This is where mature languages have an advantage over newer variants. C, Java and Python all now possess extensive libraries for network programming, HTTP, operating system interaction, GUIs, regular expressions (regex), iteration and basic algorithms. C is famed for its Standard Template Library (STL) which contains a wealth of high performance data structures and algorithms for free. Python is known for being able to communicate with nearly any other type of systemprotocol (especially the web), mostly through its own standard library. R has a wealth of statistical and econometric tools built in, while MatLab is extremely optimised for any numerical linear algebra code (which can be found in portfolio optimisation and derivatives pricing, for instance). Outside of the standard libraries, C makes use of the Boost library, which fills in the missing parts of the standard library. In fact, many parts of Boost made it into the TR1 standard and subsequently are available in the C11 spec, including native support for lambda expressions and concurrency. Python has the high performance NumPySciPyPandas data analysis library combination, which has gained widespread acceptance for algorithmic trading research. Further, high-performance plugins exist for access to the main relational databases, such as MySQL (MySQLC), JDBC (JavaMatLab), MySQLdb (MySQLPython) and psychopg2 (PostgreSQLPython). Python can even communicate with R via the RPy plugin An often overlooked aspect of a trading system while in the initial research and design stage is the connectivity to a broker API. Most APIs natively support C and Java, but some also support C and Python, either directly or with community-provided wrapper code to the C APIs. In particular, Interactive Brokers can be connected to via the IBPy plugin. If high-performance is required, brokerages will support the FIX protocol . Conclusion As is now evident, the choice of programming language(s) for an algorithmic trading system is not straightforward and requires deep thought. The main considerations are performance, ease of development, resiliency and testing, separation of concerns, familiarity, maintenance, source code availability, licensing costs and maturity of libraries. The benefit of a separated architecture is that it allows languages to be plugged in for different aspects of a trading stack, as and when requirements change. A trading system is an evolving tool and it is likely that any language choices will evolve along with it. November 30, 2016, 12:34 pm A few months ago a reader point me out this new way of connecting R and Excel. I don8217t know for how long this has been around, but I never came across it and I8217ve 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, I8217m not related to the company in any way. BERT stands for Basic Excel R Toolkit. It8217s 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, it8217s for writing User-Defined Functions (UDFs) in R. In this post I8217m 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 8220control tower8221 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 etc8230 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 amp 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 . Step by step guide 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 - gt 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 8220Reload Startup File8221 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 you8217re 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 8220New Button8221 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 August 19, 2016, 9:26 am 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 8220A 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.8221 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 . Here8217s 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 inout of sample consistency, a Stock Market case, JP Morgan Cazenove Equity Quantitative Conference, London October 2010 August 15, 2015, 9:03 pm The Asset Management industry is on the verge of a major change. Over the last couple of years Robots Advisors (RA) have emerged as new players. The term itself is hard to define as it encompasses a large variety of services. Some are designed to help traditional advisers to better allocate their clients money and some are real 8220black box8221. The user enter a few criteria (age. income, children etc8230) and the robot proposes a tailor-made allocation. Between those two extremes a full range of offers is available. I found the Wikipedia definition pretty good. 8220They are a class of financial adviser that provides portfolio management online with minimal human intervention8221. More precisely they use algorithm-based portfolio management to offer the full spectrum of services a traditional adviser would offer: dividend reinvesting, compliance reports, portfolio rebalancing, tax loss harvesting etc8230 (well this is what the quantitative investment community is doing for decades). The industry is still in its infancy with most players still managing a small amount of money but I only realised how profound the change was when I was in NYC a few days ago. When RA get their names on TV adds or on the roof of NYC cab you know something big is happening8230 it is getting more and more attention from the media and above all it makes a lot of sense from an investor perspective. There are actually two main advantages in using RA: Significantly lower fees over traditional advisers Investment is made more transparent and simpler which is more appealing to people with limited financial knowledge In this post R is just an excuse to present nicely what is a major trend in the asset management industry. The chart below shows the market shares of most popular RA as of the end of 2014. The code used to generate the chart below can be found at the end of this post and the data is here . Those figures are a bit dated given how fast this industry evolves but are still very informative. Not surprisingly the market is dominated by US providers like Wealthfront and Betterment but RA do emerge all over the world: Asia (8Now ), Switzerland (InvestGlass ), France (Marie Quantier )8230. It is starting to significantly affect the way traditional asset managers are doing business. A prominent example is the partnership between Fidelity and Betterment. Since December 2014 Betterment past the 2 billion AUM mark. Despite all the above, I think the real change is ahead of us. Because they use less intermediaries and low commission products (like ETFs) they charge much lower fees than traditional advisers. RA will certainly gain significant market shares but they will also lowers fees charged by the industry as a whole. Ultimately it will affect the way traditional investment firms do business. Active portfolio management which is having a tough time for some years now will suffer even more. The high fees it charges will be even harder to justify unless it reinvents itself. Another potential impact is the rise of ETFs and low commission financial products in general. Obviously this has started a while ago but I do think the effect will be even more pronounced in the coming years. New generations of ETFs track more complex indices and custom made strategies. This trend will get stronger inevitably. As usual any comments welcome March 23, 2015, 8:55 pm 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 8220Active Portfolio Management8221 by Grinold amp 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. It8217s very well written and lays the foundations of systematic active portfolio management (I have no affiliation to the editor or the authors). 1 8211 Factor Analysis Here we8217re 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). 1.1 8211 Information Coefficient The horizon for the forward return has to be defined by the analyst and it8217s a function of the strategy8217s 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 amp 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. 1.2 8211 Quantiles Return In order to have a more accurate estimate of the factor predictive power it8217s 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 SampP500 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 it8217s good enough for illustration purposes only. The code below downloads individual stock prices in the SampP500 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 etc8230) 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 though8230). 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 it8217s 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. 4 8211 Practical limitations The above framework is excellent for evaluating investments factor8217s quality however there are a number of practical limitations that have to be addressed for real life implementation: Rebalancing . In the description above, it8217s 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 etc8230 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 Grinold8217s model that managers face no constraints which preclude them from translating their investments insights directly into portfolio bets. And finally, I8217m amazed by what can be achieved in less than 80 lines of code with R8230 As usual any comments welcome

No comments:

Post a Comment