Friday 22 December 2017

البناء الآلي-التداول-نظام-ج-نت


بناء أنظمة التداول الآلي. مع مقدمة في فيسوال C 2005 النسخ 2 بناء أنظمة التداول الآلي مع مقدمة إلى فيسوال C 2005 3 سلسلة سوق التكنولوجيا سلسلة التكنولوجيا محرر بن فان فليت سلسلة سوق التكنولوجيا المالية هي شراكة بين إلزيفير، وشركة ومعهد تكنولوجيا السوق (i4mt) لنشر الكتب المتطورة التي تغطي موضوعات تتعلق بتكامل التكنولوجيا مع الأسواق المالية، بما في ذلك: التداول الآلي، وبناء أنظمة التداول والاستثمار، والقضايا التشغيلية في تجهيز المكاتب الخلفية، والمقاصة والتسوية، وقضايا الامتثال والحوكمة من حيث صلتها إلى التكنولوجيا. والهدف من هذه السلسلة هو تعزيز التفاهم والكفاءة مع التكنولوجيا في صناعة التمويل من خلال نشر الكتب عالية الجودة على أحدث مجالات البحث والممارسة للمهنيين العاملين في الأسواق المالية. محرر السلسلة: بن فان فليت محاضر في ومدير مشارك في ماجستير. في برنامج الأسواق المالية في ستيوارت كلية الدراسات العليا في إدارة الأعمال، معهد إلينوي للتكنولوجيا. ضمن هذا البرنامج، وقال انه يعلم دورات الدراسات العليا في التمويل الكمي وتطوير نظام التداول الآلي باستخدام فيسوال باسيك، سكل، شمل، إسو C و C البصرية و أومل. وهو أيضا مخترع مشارك من تراديردنا، في الوقت الحقيقي حزمة أداء تقييم أداء التداول، فضلا عن كونه مدير في تراديردنا ليك. كما أنه يشغل منصب نائب رئيس معهد تكنولوجيا السوق (i4mt)، وهي منظمة غير هادفة للربح تقدم برامج تعليمية في الأسواق المالية والتكنولوجيا، حيث يرأس أيضا لجنة تكنولوجيا السوق لبرنامج مطور نظام التداول المعتمد (كتسد). يرجى الاطلاع على مزيد من المعلومات. كما يتشاور السيد فان فليت على نطاق واسع في القطاع المالي. وهو مؤلف نظم البناء الآلي للتجارة (أكاديميك بريس، 2007) ومؤلف مشارك في نمذجة الأسواق المالية (ماكجرو هيل 2004). ونحن نرحب بمقترحات الكتب لهذه السلسلة. يرجى الذهاب إلى حيث ستجد رابط لترسل لنا اقتراحكم. 4 بناء أنظمة التداول الآلي مع مقدمة في فيسوال C 2005 بنجامين فان فليت أمستردام بوسطن هايدلبرغ لندن نيو يورك أوكسفورد باريس سان ديجو سان فرانسيسكو سنغافورة سيدني طوكيو الصحافة الأكاديمية هي بصمة إلزيفير 5 الصحافة الأكاديمية هي بصمة لشركة إلزيفير 30 محرك الأقراص، جناح 400، برلينغتون، ما 01803، أوسا 525 B ستريت، سويت 1900، سان ديجو، كاليفورنيا. أوسا 84 ثيوبالد s رود، لندن WC1X 8RR، أوك هذا الكتاب مطبوع على ورق خال من الأحماض. حقوق الطبع والنشر 2007، إلزيفير شركة جميع الحقوق محفوظة. ال يجوز نسخ أي جزء من هذا المنشور أو نقله بأي شكل أو بأي وسيلة إلكترونية أو ميكانيكية، بما في ذلك النسخ أو التسجيل أو أي نظام لتخزين المعلومات واسترجاعها دون الحصول على إذن كتابي من الناشر. يمكن الحصول على أذونات مباشرة من قسم العلوم في قسم العلوم والتكنولوجيا في أكسفورد، المملكة المتحدة: الهاتف: (44). فاكس: (44). يمكنك أيضا إكمال طلبك على الخط عن طريق الصفحة الرئيسية إلزيفير (إلسفير)، عن طريق اختيار دعم أمبير الاتصال ثم حقوق التأليف والنشر والإذن ومن ثم الحصول على أذونات. مكتبة الكونغرس بيانات الفهرسة في النشر فان فليت، بنيامين بناء أنظمة التداول الآلي. مع مقدمة إلى فيسوال C 2005 بنيامين فان فليت. ص. سم. تتضمن مراجع ببليوغرافية وفهرس. إيسبن (ألك الورق) 1. التداول الإلكتروني للأوراق المالية. 2. المالية نماذج رياضية. 3. ميكروسوفت فيسوال C ميكروسوفت. I. العنوان. هغ V دس المكتبة البريطانية فهرس المكتبة هذا الكتاب متوفر في المكتبة البريطانية. إيسبن 13: إيسبن 10: للحصول على معلومات حول جميع مطبوعات أكاديميك بريس قم بزيارة موقعنا على الويب في برينتد إن ذي يونيتيد ستيتس أوف أميركا 6 المحتويات شكر وتقدير زيي الفصل 1 مقدمة إسو C هيكل هذا الكتاب 2 القسم الأول: مقدمة في فيسوال C 2005 الفصل الثاني الإطار مس فيسوال ستوديو 2005 هيكل المشروع ما هو كلي لماذا فيسوال C فك كومبيلر ماذا عن السرعة رمز نموذج الإطار: مساجيبوكسيكسامبل رمز العينة: سترينغكونكاتيكسامبل رمز العينة: ديبوغكسامبل إصدار الملخص 14 الفصل 3 تتبع مراجع نموذج التعليمات البرمجية: تراكينغريفيرانسكسامبل رمز العينة: تمبلات فونكتيونامبل ماناجيد هاندل رمز العينة: نوع المرجعإكسامبل الملخص 17 v 7 في المحتويات الفصل 4 الفئات والكائنات التجريد التغليف الميراث تعدد الأشكال إدارة الذاكرة في أنواع الشبكة أنواع غير المدارة جمعيات مختلطة ملخص 23 الفصل 5 أنواع المرجع رمز العينة: نوع المرجعمثال حذف وإزالة وضع الصيغة النهائية رمز العينة: فيناليزكسامبل كومة علم الدلالات لأنواع ريف نولبر المرجع T له ملخص هام 31 الفصل 6 أنواع القيمة رمز العينة: فالويتيبسكسامبل رمز العينة: باسينغ فالويتيبسكسامبل الملخص 36 الفصل 7 الكائنات غير المدارة رمز النموذج: غير مدارأوبجيكتكسكسامبل الملخص 39 الفصل 8 تكوين رمز العينة: كومبوسيتيونيكسامبل نموذج التعليمات البرمجية: غير المدارة كومبوسيتيونكسيمبل نموذج التعليمات البرمجية: ماناجيدكومبوسيتيونكسامبل الملخص 48 الفصل 9 خصائص عينة كود: بروبيرتيزكسامبل الملخص 50 الفصل 10 الهياكل والتعدادات رمز النموذج: فالوستروتوريكسامبل رمز العينة: ريفيرانسستروتوريكسامبل نموذج التعليمات البرمجية: إنومزكسامبل الملخص 53 8 المحتويات في الفصل 11 توصيف الوصول الوراثي فئة الكائن مختصر وفئات مختومة رمز العينة: الميراثعينة واجهات نموذج التعليمات البرمجية: إنتيرفاسكسيمبل وقت التشغيل كالابل ملخص المجمع 60 الفصل 12 التحويل والصب تحويل نموذج الكود: كونفيرتيكسامبل الصب الثابت نموذج العينة: ستاتيكاستيكسامبل الصب الديناميكي رمز العينة: ديناميكاستيكسامبل الصب الآمن رمز العينة: صافيكاستيكسامبل الملخص 65 الفصل 13 المشغل الزائد رمز العينة: أوبوفيرلوادكسامبل الملخص 69 الفصل 14 المندوبون والأحداث المندوبون نموذج الكود: المندوبون نموذج عينة البث المتعدد رمز: متعدد الإرسال أمثلة نموذج التعليمات البرمجية: إيفنتكسامبل المغلفات نموذج التعليمات البرمجية: ورابيركسامبل أسلوب غير متزامن استدعاء نموذج التعليمات البرمجية: أسينشيفنتيكسامبل الملخص 82 الفصل 15 صفائف نموذج التعليمات البرمجية: ماناجيدارايكسامبل عينة كود: باسينغارايسكسامبل الملخص 85 في 9 في المحتويات الفصل 16 توليد أرقام عشوائية رمز العينة: راندوميكسمبل رمز العينة: ستدنورمراندومكسامبل الملخص 89 الفصل 17 الوقت والموقتات نموذج العينة: ميلي ثانية واحدة نموذج ساعة توقيت نموذج العينة: ساعة توقيتمؤقتات تيمرس نموذج التعليمات البرمجية: فورمزتيمريكسامبل نموذج التعليمات البرمجية: ثرادينغتيمريكسامبل رمز العينة: تيمرستيمريكسامبل الملخص 98 الفصل 18 المدخلات والمخرجات تيارات فيلستريم الفئة ستريموريتر فئة الملف وفئات الدليل تطبيق الفئة فليمود نموذج التعداد كود: ستريموريتريكسامبل نموذج التعليمات البرمجية: سترمريديركسامبل الملخص 101 الفصل 19 استثناء هاندل إنجليش رمز العينة: إكسيبتيونسكسامبل الأنواع C غير المتلقاة غير المتلاحقة الملخص 105 الفصل 20 المجموعات كود العينة: هاستابليكسامبل قائمة الفرز الفئة رمز النموذج: سورتيدليستكسامبل جينيريكس سافيتيريكس رمز العينة: لينكدليستكسامبل رمز العينة: جينيريكسكسامبل الملخص 112 الفصل 21 ستلستل رمز العينة: ستليكسامبل رمز العينة: ستليكسامبل الملخص 114 10 المحتويات التاسع الفصل 22 قواعد البيانات نموذج التعليمات البرمجية: داتاسيتيكسامبل الصفوف و داتاروكولكتيونس و داتاروز الملخص 117 الفصل 23 الاتصال بقواعد البيانات اتصال قاعدة البيانات داتادابتر رمز النموذج: أدويكسامبل التعداد من خلال كافة البيانات في داتاسيت باستخدام إكسيل ككتابة مصدر البيانات شمل من داتاسيت تحديث قاعدة بيانات مع تغييرات في مجموعة بيانات استرجاع البيانات مع ملخص داتاريدر 124 الفصل 24 لغة الاستعلام المنظم معالجة البيانات لغة تحديث قاعدة بيانات مع تغييرات في بيانات داتاس تعريف لغة ملخص 140 الفصل شمل شمل بشكل جيد وثائق شمل وثائق شمل صالحة شمل مخطط بارسرز الوثائق رمز العينة: T rader. xsd رمز النموذج: زملوريتيركسامبل رمز العينة: زملريديركسامبل الملخص 146 الفصل 26 بروتوكول تبادل المعلومات المالية بروتوكولات شمل في الأسواق المالية نظرة عامة على فيكس ملخص 151 الفصل 27 التسلسل التسلسل التسلسل إكسامبل 154 الفصل 28 خدمات ويندوز نموذج التعليمات البرمجية: ويندوز سيرفيسكسكسامبل الملخص 159 11 x المحتويات الفصل 29 حزم التثبيت والتركيب نموذج التعليمات البرمجية: إنستالاشيونكسيمبل الملخص 162 القسم إي: التزامن الفصل 30 اسم نطاق خيوط التخييط رمز النموذج: ثريديكسامبل رمز العينة: ثريادابورتكسامبل أولوية الموضوع رمز النموذج: ثريادبريوريتيكسامبل ثريادستاتيت تعداد الموضوع فئة بولد رمز النموذج: ثريادبوليكسامبل تحديث نماذج من مواضيع أخرى رمز نموذجي: فورموبداتيكسامبل ملخص سلامة الموضوع 175 الفصل 31 فئات التزامن رمز النموذج: سينكرونيزيكسامبل فئة موتكس كود المثال: موتكسكسامبل سيمافور كلاس رمز العينة: سيمافوريكسامبل مراقبة فئة رمز العينة: مونيتور سوماري 182 الفصل 32 المقابس نموذج التعليمات البرمجية: سينكرونوسسرفيركسامبل رمز العينة: سينكرونوسكلينتيكسامبل الملخص 189 القسم الثالث: التشغيل البيني والاتصال الفصل 33 مارشال فئة المارشال رمز العينة: سترينغتوشارارايكسامبل الملخص 194 الفصل 34 مؤشرات الداخلية والرؤوس نموذج التعليمات البرمجية: إنتيريوربوانتيركسامبل مؤشرات الترسيم رمز العينة: بينينغكسامبل الملخص 198 12 المحتويات إكسي الفصل 35 الاتصال بإدارة دلز المثال التعليمات البرمجية: دليكسامبل الموجز 201 الفصل 36 ربط دلز نموذج كائن كوم (كوم) دلز مع كوم إنتيروب نموذج التعليمات البرمجية: ميكومليبراري رمز العينة: أوسينغكومدلكسامبل الملخص 207 الفصل 37 الاتصال إلى دلز د مع خدمات استدعاء النظام استدعاء وظائف نمط C نموذج التعليمات البرمجية: MyWin32Library نموذج التعليمات البرمجية: usingWin32DLLExample إنشاء كائنات نموذج التعليمات البرمجية: MyWin32ClassLibrary رمز التعليمات البرمجية: usingWin32ClassExample كالينغكونفنتيونيمنتيراتيون الملخص 216 الفصل 38 الاتصال ب إكسيل نموذج التعليمات البرمجية: كونترولينغ إكسليكسامبل رمز العينة: إكسيلشارتيكسامبل الملخص 221 الفصل 39 الاتصال ب تراد إرابي تراديرابي نظرة عامة فيلوبج إنستروبجكلاس إنسترنوتيفيكلاس أورديروبج أوردربروفي ليكلاس أوردرستاسكلاس نموذج العينة: تراديرابيكونكتيونكسامبل الملخص 230 الفصل 40 الاتصال ب زتابي رمز العينة: زتابيكونكتيون إكسامبل الملخص 233 13 زي المحتويات القسم الرابع: أنظمة التداول الآلي الفصل 41 بناء أنظمة التداول شراء مقابل بناء بيانات رسم الخرائط سرعة التنمية عشرة أشياء تؤثر على سرعة نظام التداول الحصول على التسريبات المنطقية الصحيحة عشرة أشياء تؤثر على استحقاق نظام التداول الملخص 245 الفصل 42 كف طريقة تطوير نظام التداول البحث في وثيقة المال وحسابات المستند باك تيست تنفيذ إدارة ملخص المحفظة والمخاطر 257 الفصل 43 نظام التداول الآلي الصنف الصك الصنف صنف الطلب طلب الكتاب قوس وضع علامة أو شريط مجموعة بار إدارة النظام واجهة المستخدم الرسومية الملخص 265 الفصل 44 نظام التحليل الفني ذو الخيط الواحد رمز العينة: تيشينكالسيستيمكسامبل الملخص 277 الفصل 45 برودوسيركونسوم إر نموذج التصميم رمز العينة: برودوسيركونسوميركسامبل الملخص 287 الفصل 46 نظام المراجحة الإحصائي المرقم، رمز العينة: سبريادريكسامبل الملخص الاستنتاج 304 14 شكر وتقدير بدأ هذا الكتاب كمذكرات دروس لدورة تدرس في معهد إلينوي للتكنولوجيا تسمى البرمجة المتقدمة الموجهة كائن للمالية الأسواق. في هذه الفئة نغطي تصميم نظام التداول الآلي والتنمية باستخدام مايكروسوفت البصرية C. عندما بدأت تدريس هذه الدورة منذ عدة سنوات، لم أتمكن من العثور على الكتاب الذي يغطي جميع الموضوعات اللازمة لبناء في الوقت الحقيقي، وأنظمة التداول الآلي وهكذا، ونتيجة لذلك، يحاول هذا الكتاب أن يفعل فقط أنه يجمع بين البرمجة والموضوعات المتعلقة بالتكنولوجيا لتطوير اختيار التجارة، توجيه النظام، وإدارة النظام، وخوارزميات إدارة الموقف. وآمل أن المزيد من المدارس سوف تقدم دورات على تصميم نظام التداول الآلي في المستقبل، وأن هذا الكتاب سوف تكون مفيدة في تعليمهم. وعلاوة على ذلك، هذا الكتاب هو نص الأساس لبرنامج المطور نظام التجارة معتمد كتسد التي يقدمها معهد لتكنولوجيا السوق (i4mt. org). هذا هو برنامج شهادة جديد يتكون من ثلاثة امتحانات، واحدة في التمويل الكمي، واحد في الأوراق المالية واستراتيجية التداول المشتقات، واحد في إسو سيسي البرمجة وتكنولوجيا السوق. تم تصميم هذا البرنامج دراسة ذاتية صارمة لجمع المهارات في الطلب في الصناعة المالية اليوم. المرشحين الذين يحققون تسمية كتسد سيكون الناس الموهوبين في الواقع. كما يمكن للمرء أن يتصور، يجب إعطاء ائتمان إضافي لإنجاز هذا المشروع لكثير من الأصدقاء والعائلة والزملاء: على وجه الخصوص لزوجتي، جوليا، مارك ماكراكن، الدكتور أندرو كوميجا، أندرو أكوستا، ساجي مينتز، جيسون مالكين، لاريسا J. ميلر، ديريك فالتر، نيراج تشوكشي، جوليان ملا، مايك هيرمانسون، ديفيد نورمان، د. ديبورا سيرنوسكاس، الدكتور جو فوجكوسكي، باميلا رياردون، إدوارد وانغ، أليكس ديتز، أندرو روبنسون، وجميع زملائي في مركز إيت للأسواق المالية راسل ووجسيك، والدكتور مايكل غورهام، وكيث بلاك، والدكتور مايكل أونغ، والدكتور جون بيلسون، والدكتور مايكل كيلي، وجودي هوليهان. كما أود أن أشكر العديد من الطلاب الذين أخذوا دراستي وقدموا جميعا ردود فعل قيمة. دون مساعدتهم ومساعدة العديد من الآخرين هذا الكتاب لم تكن قد اكتملت. زيي 15 زيف شكر وتقدير كتب هذا الكتاب للأشخاص الذين لديهم معرفة إسو C أو ربما جافا ،، أو كوم. بالنسبة للمهندسين الماليين والمهندسين الماليين الطموحين الذين لديهم خلفية برمجة عامة، سيوفر هذا الكتاب مناقشة متعمقة لمفاهيم البرمجة على مستوى عال مثل معالجة الحدث وقابلية التشغيل البيني واتصال تغذية البيانات والتزامن. للمبرمجين من ذوي الخبرة C، قد تجد أن هذا الكتاب يوفر مقدمة جيدة لاستخدام C ضمن الإطار. مهما كانت الحالة، وآمل أن تتعلم منه وأنها مستوحاة من خوض أعمق في موضوع تطوير نظام التداول الآلي. يرجى تقديم لي مع أي ردود فعل لديك. وأتعهد بتحديث موقعي على الويب بانتظام، مع إدخال تصويبات على البيانات الخاطئة وأمثلة إضافية. 16 الفصل 1 مقدمة تتألف أنظمة التداول الآلية (أو الخوارزمية) من أجزاء عديدة، سواء من عملاء الأجهزة والبرامج، أو الخوادم، أو الشبكات، أو قواعد البيانات، أو محركات الحساب، أو واجهات برمجة التطبيقات، أو خلاصات البيانات في الوقت الحقيقي، أو واجهات المستخدم الرسومية. ومع ذلك، فإن منطق الأعمال من أنظمة التداول، والذي يتكون من خوارزميات اختيار التجارة، وإدارة النظام، والمنطق إدارة الموقف، واردة في البرنامج، وهذا الكتاب هو معني بتغليف منطق الأعمال نظام التداول في البرامج التي تسيطر على تدفق السوق البيانات. (لا يوجد كم في هذا الكتاب). نظام التداول الآلي يتكون من قواعد الدخول والخروج من موقف أو مواقف والتكنولوجيا، سواء الأجهزة والبرمجيات، وتستخدم لجعلها تحدث. هذه القواعد هي مجموعة من العمليات المنطقية أو الرياضية التي يمكن أن تقوم على البحث النوعي أو التقني أو الكمي. إذا أردنا بناء نظام آلي ينفذ الصفقات على التبادلات الإلكترونية، نحتاج إلى معرفة كيفية العمل مع البيانات، سواء بيانات السوق في الوقت الحقيقي والبيانات التاريخية، في التعليمات البرمجية. بعد كل شيء، البيانات هي شريان الحياة من الأسواق الإلكترونية، وفقا لديفيد نورمان في كتابه المهنية التجارة الالكترونية. هذا فقط ما هذا الكتاب عن، وذلك باستخدام فيسوال C لإدارة بيانات الأسواق المالية (وهناك الكثير من ذلك) في تطبيقات نظام التداول. بشكل عام، يغطي هذا الكتاب ثلاثة أشياء: 1. إدارة البيانات في الذاكرة. 2. تخزين البيانات في واسترجاعها من قواعد البيانات. 3. نقل البيانات. وترتبط برمجة المكاتب الأمامية في الأسواق المالية إلى حد كبير بالتواصل مع قواعد البيانات وتغذية البيانات في الوقت الفعلي ومنصات تنفيذ الطلبات والمكتبات الكمية ومحركات التحسين وبرامج التخطيط ومحركات توليد التقارير والتقنيات القديمة و إكسيل، على سبيل المثال لا الحصر. من أجل إدارة البيانات في الوقت الحقيقي والتاريخية بنجاح، سوف نحتاج إلى فهم: 1. العمارة يحركها الحدث. 2. التزامن. 3. الاتصال وقابلية التشغيل البيني. 1 17 2 الفصل 1 مقدمة في حين يتناول هذا الكتاب العشرات من القضايا التكنولوجية الهامة التي سوف تواجه عند بناء أنظمة التداول الآلي في العالم الحقيقي في، فإنه لا تظهر لك كيفية بناء نظام التداول مربحة. (من المهم مع ذلك أن ندرك أن التفوق التكنولوجي يمكن أن يكون ميزة تنافسية كبيرة.) هناك أربعة التخصصات التي تذهب إلى نظام التداول الآلي علوم الكمبيوتر تطوير، والتمويل الكمي، واستراتيجية التداول، وإدارة الجودة وهذا هو كتاب علوم الكمبيوتر. تطوير واختبار اختيار التجارة وطرق إدارة المخاطر هي مواضيع للكتب الأخرى. يغطي هذا الكتاب أساسيات ما يجب أن يعرفه مهندس مالي حول البرمجة في الكائنات، سكل، تعدد المواضيع، التشغيل البيني، الرسائل، خوارزميات اختيار النظام، وتقنيات إدارة النظام. في هذا النص، حاولت تضمين المعلومات ذات الصلة بالسوق، ذات الصلة بالوظيفة. أما أصحاب العمل اليوم في الأسواق المالية فيطلبون الاستعداد للعمل. إذا كنت ترغب في الحصول على وظيفة في صناعة التداول وإدارة المال، والتي هي أكثر وأكثر كل يوم مدفوعة من قبل النظم الآلية، سيكون لديك للحصول على مستوى تنافسي من المعرفة من البرمجة. يجب أن ندرك أن هذا الكتاب هو لمحة عامة، ومع ذلك. فإنه لن يعلمك كل شيء. ومن الواضح أن التكنولوجيا كموضوع كبير جدا بحيث لا يمكن تغطيتها في كتاب واحد. حتى تضييقه إلى فك لتطوير نظام التداول لا تزال واسعة جدا. على الصفحات، وسوف أقدم العديد من الأفكار الهامة، في محاولة لتوجيه لكم في الاتجاه الصحيح، ونأمل في النهاية إلهام لك لإجراء بحوث إضافية حول موضوع تطوير نظام التداول الآلي. من هناك، يجب على المهندس المالي الدؤوب أن يحقق أكثر من ذلك على إسو C الخاصة به يغطي هذا الكتاب جوانب البرمجة لتطوير نظام التداول ويفترض أنك على دراية بمفاهيم البرمجة إسو C، بما في ذلك المؤشرات والوظائف والأشياء، والقالب القياسي مكتبة هيكل هذا الكتاب أنظمة التداول الآلي تجد أنقى شكلها في استراتيجيات عالية التردد حيث سرعة الحساب والتنفيذ هي ميزة تنافسية. أما الأنظمة الأخرى، حيث لا تكون بالضرورة ملي ثانية من حيث الجوهر، فقد تكون مؤتمتة بالكامل أو مؤتمتة جزئيا. وسيركز هذا النص على إدخال مفاهيم البرمجة والتصميم لنظم الترددات الأعلى. مناقشة جميع المفاهيم التكنولوجية البديلة لتصميم النظام التجاري وعرض نظام تجاري كامل خارج نطاق كتاب. يتم تبسيط النظم التجارية المعروضة في هذا الكتاب بشكل كبير من أجل توضيح البرمجة المشتركة ومفاهيم التصميم. ينقسم هذا الكتاب إلى أربعة أقسام. يركز القسم الأول فقط على مقدمة لأنواع فيسوال C وتقنيات البرمجة. ويركز القسم الثاني على تعدد الطرق. ويركز الثالث على قابلية التشغيل البيني والتوصيلية والرابع على الأشياء وأنماط التصميم والمفاهيم المعمارية لتطوير نظام التداول الآلي. في النهاية، ببساطة قراءة هذا الكتاب لن تجعلك خبيرا. لتعلم حقا المواد في هذا الكتاب، يجب عليك أيضا العمل من خلال عينات رمز المقدمة. فقط من خلال إشراك نفسك في هذه العملية، وعلاوة على ذلك يذهب أبعد من ذلك، سوف تكسب أنت حسنات الفهم والحدس. انها عمل شاق، لكنها سوف تسدد. 18 القسم الأول مقدمة في فيسوال C 2005 19 تركت هذه الصفحة عمدا فارغة 20 الفصل 2 الإطار 2.1. مس فيسوال ستوديو 2005 بروجيكت ستروكتور في مس فيسوال ستوديو 2005، يسمى تطبيق البرنامج الخاص بك الحل، ويمكن أن يتكون حل واحد أو أكثر من المشاريع، حيث يمكن أن يكون كل مشروع في لغة فيسوال ستوديو مختلفة. على مدى هذا الكتاب، وسوف نقدم الحلول المتقدمة في معظمها في مس فيسوال C لإدارة أو التطبيقات لأسباب سأشرحها قريبا. ومع ذلك، يجب أن تكون على علم بأن فيسوال C ليست لغة برمجة جديدة، وإنما بيئة تطوير كامل يوفر دعما متزايدا لكثير من أنواع المشاريع C، بما في ذلك: مكتبة قالب النشطة (أتل) المشاريع. مس فئات المؤسسة (مفك). أو وحدة التحكم المدارة أو ويندوز أو دل المشاريع. مشاريع وحدة تحكم Win32 لمشاريع إسو C. مشاريع Win32 أبي و دلز. ونتيجة لذلك، فيسوال C أو المشاريع المدارة هي واحدة فقط من عدة لغات C عرضت في فيسوال ستوديو 2005، وهذا هو واحد من الأشياء التي تحدد فك جديد وبصرف النظر عن الآخرين في الأسرة أنه يوفر أساسا خمس لغات C مستقلة في حزمة واحدة. حتى إذا كنت ترغب في الاستمرار في جعل تطبيقات مفك، يمكنك أن تفعل ذلك تماما مثل قبل. في الواقع، تم تحسين دعم مفك و أتل في فس في الإصدارات السابقة من فيسوال ستوديو، تمت إضافة الإضافة إلى الاسم من أجل التمييز بين الإصدارات السابقة مثل فيسوال باسيك 6.0. مع ظهور فس 2005، وعادة ما يتم تمديد تمديد إلى اسم ويمكن أن نشير إليها كما ف و C و فيسوال C ما هو كلي كلي (البنية التحتية اللغة المشتركة) هو اشتقاق C. ووفقا ستانلي ليبمان من ميكروسوفت: 5 21 6 الفصل 2 الإطار كلي يشير إلى البنية التحتية للغة المشتركة، وهي بنية متعددة المستويات تدعم نموذج البرمجة المكون الديناميكي. في العديد من الطرق، وهذا يمثل انعكاسا كاملا من نموذج الكائن C. يتم تشغيل طبقة برامج التشغيل، نظام التنفيذ الظاهري، بين البرنامج ونظام التشغيل الأساسي. الوصول إلى الجهاز الأساسي مقيد إلى حد ما. يتم دعم الوصول إلى أنواع نشطة في برنامج التنفيذ والبنية التحتية للبرنامج المرتبطة كل من الاكتشاف والبناء. ويمثل الشريط المائل () ارتباطا بين C و كلي سو، فإن التقريب الأول للإجابة على ما هو كلي هو أنه ملزم لنموذج الكائن C الثابت بنموذج كائن المكون الديناميكي ل كلي. باختصار، هو كيف يمكنك القيام البرمجة باستخدام C بدلا من C أو فيسوال باسيك. مثل C و كلي نفسها، كلي يخضع لتوحيد في إطار الاتحاد الأوروبي مصنعي الكمبيوتر (إسما)، وفي نهاية المطاف تحت إسو. وقت تشغيل اللغة العامة (كلر) هو إصدار ميكروسوفت من كلي الخاص بنظام التشغيل ويندوز. وبالمثل، فيسوال C هو تنفيذ كلي. كما تقريب الثاني من الجواب، كلي يدمج نموذج البرمجة داخل C بنفس الطريقة، مرة أخرى في مختبرات بيل، قمنا بدمج البرمجة العامة باستخدام قوالب داخل C. الموجودة آنذاك في كل من هذه الحالات الاستثمارات الخاصة بك في C كودباس القائمة ويتم الحفاظ على الخبرات الموجودة لديك C. وكان هذا شرطا أساسيا أساسيا لتصميم اللجنة. على مدار هذا الكتاب، سوف أشير ببساطة إلى تنفيذ ميكروسوفت كلي كما فيسوال C. لمقالة السيد ليبمان الكامل، انتقل إلى msdnmagissues0600purecdefault. aspx لماذا فيسوال C لذلك لماذا فيسوال C ما هي فوائد التطبيقات المدارة أو C ببساطة وضعت وعلى حد تعبير نائب رئيس كبير بائع البرمجيات التجارية هنا في شيكاغو، نيت هو المستقبل. الأهم من ذلك، الإطار يحتوي على العديد، العديد من الطبقات التي تساعد في تطوير أنظمة التداول، كما سنرى. وعلاوة على ذلك، بالنسبة لللغات الأخرى، فك يحتوي على دعم أكبر بكثير للتشغيل البيني بين التعليمات البرمجية المدارة وغير المدارة. وبالإضافة إلى ذلك، في الأسواق المالية، والتشغيل البيني هو المفتاح. في فك، لدينا مراقبة دقيقة على كومة الذاكرة المدارة وغير المدارة وتخزين الذاكرة كومة ورمز المدارة وغير المدارة ويمكن للجميع أن توجد بسلاسة في نفس المشروع. وهذا يسمح لنا لدمج تطبيقات C الموجودة لدينا، وظائف، والكائنات بسرعة وسهولة في تطبيقات جديدة. وهذا ينطبق بشكل خاص على تطبيقات كوم، التي تستخدم بكثافة في الصناعة المالية وغير المدارة. وعلاوة على ذلك، إذا كان لديك مكتبات من الكائنات أو وظائف مالية مكتوبة في C الأصلي، فك مع دعمها إنتيروباند ماناجيد واسعة النطاق سوف تعطيك السيطرة الهائلة. بدلا من ذلك، إذا كان لديك تطبيقات C الموجودة التي ترغب في تحويلها إلى، مرة أخرى سوف فك توفر لك مع الأدوات التي يمكن للغات الأخرى ر و ر. وأخيرا، في حين أن نسخة 2005 من المحكمة الخاصة بلبنان (المعروفة باسم المحكمة الخاصة بلبنان) غير متوفرة حتى الآن، وسوف يكون قريبا، وتحويل رمز ستل تعتمد ستل يكون نسيم. 22 2-6. الإطار فكوم كومبيلر هنا بعض الأشياء التي يجب تذكرها حول مترجم فك. يستخدم مترجم فك C1.exe ملحق the. c ل C فقط تجميع و. كب ل C و C. أيضا، لا تتطلب رؤوس القياسية ملحق. ه، حيث قامت ميكروسوفت بتضمين إصداراتها الخاصة من هذه الملفات في مساحة الاسم ستد. علاوة على ذلك، تعرض نافذة خصائص المشروع كل إعدادات برنامج التحويل البرمجي ل سيسي، بما في ذلك رابط وإنشاء الأحداث. يستخدم ميكروسوفت s Cl. exe مترجم أنسي C ومعايير إسو C و 98 C متوافقة وفقا لمايكروسوفت. يقدم برنامج التحويل البرمجي تكوينات الحل ل ديبوغ يبني وبناء الإصدارات. مع بناء تصحيح الأخطاء، يمكننا التفاعل مع التعليمات البرمجية لدينا أثناء وقت التشغيل. هذا هو مساعدة كبيرة. ومع ذلك، لم يتم إجراء أية تحسينات، ومن أجل ذلك نستخدم بناء الإصدار، والتي سوف تولد رمز أسرع وأفضل. المجمع يسمح لنا لدمج كود C الأصلي في مشاريعنا ويجمع أولا في اللغة المتوسطة مايكروسوفت (مسيل). ثم يتم تحويل مسيل إلى التعليمات البرمجية الأصلية من قبل مترجم فقط في الوقت المناسب (جيت). مع جيت بعض العمليات ستكون أسرع من C المحلي، في حين أن البعض الآخر سيكون أبطأ. ونتيجة لذلك، هناك مقايضات بين سرعة التنمية وسرعة التنفيذ. ومع ذلك، هناك أشياء يمكننا القيام بها للحد من تكلفة بعض العمليات. يمكن ضبط مترجم فك و جيت لتوليد أسرع رمز ممكن باستخدام خيارات مترجم المتاحة. إذا كنت جادا حول السرعة، يستغرق بعض الوقت للتحقيق مزيد من ميكروسوفت فك فك مترجم ما حول سرعة السرعة مهم، بطبيعة الحال. لإجراء مناقشة متعمقة حول اعتبارات السرعة في التعليمات البرمجية المدارة، سأحيلك إلى عدد قليل من المقالات الممتازة في مكتبة مسن (msdn. microsoft. كومليبراري): A بيكر s دزينة: ثلاثة عشر أشياء يجب معرفتها قبل نقل برامج فيسوال C إلى فيسوال ستوديو 2005 من قبل ستانلي ليبمان. أفضل الممارسات لكتابة قانون فعالة وموثوق بها مع كلي من قبل كيني كير. C: اللغة الأكثر قوة للبرمجة الإطارية من قبل كيني كير. كتابة التعليمات البرمجية المدارة بشكل أسرع: معرفة ما الأشياء تكلف من قبل جان رمادي. كتابة التطبيقات المدارة عالية الأداء: التمهيدي من قبل غريغور نوريسكين (يتضمن لمحة عامة عن كلر منشئ). نصائح لتحسين رمز الوقت الحرج. أفضل ممارسات التحسين في المقطع فيسوال C الإطار عندما نقوم بإنشاء تطبيقات فيسوال C المدارة، يتم تطوير برامجنا وتصنيفها وتنفيذها ضمن إطار العمل. يتكون الإطار من ثلاثة أجزاء: 23 8 الفصل 2 الإطار 1. وقت تشغيل اللغة الشائعة (كلر). 2. مكتبات الفئة. 3. أسب. أسب هو مايكروسوفت منصة تطوير الويب على شبكة الإنترنت لبناء تطبيقات المؤسسة على شبكة الإنترنت، والتي تعمل بطيئة جدا في الوقت الحقيقي، وتطبيق الأسواق المالية، ولذا فإننا سوف تنفق أي وقت في فحصه. بدلا من ذلك سوف نقضي وقتنا في التعلم عن وقت تشغيل اللغة المشتركة ومكتبات الفئة وكيف يمكننا استخدامها لبناء التطبيقات المالية التي يحتمل أن تعمل على أنظمة تشغيل متعددة، وليس فقط ويندوز، بما في ذلك أونيكس، لينكس، وماك اللغة المشتركة وقت التشغيل تقوم كلر بتشغيل تنفيذ التعليمات البرمجية ضمن إطار العمل والبرامج المستندة إلى البرامج مع دمج لغة عبر والأمن وإدارة الذاكرة الديناميكية وخدمات تصحيح الأخطاء. وعلاوة على ذلك، فإن كلر تسيطر على ما نسميه التعليمات البرمجية المدارة، والتي يتم تنفيذها داخل كومة المدارة. وهذا يعني أن الكومة المدارة يتم التحكم بها بواسطة الإطار بدلا من نظام التشغيل. ومع ذلك، يتم التحكم في التعليمات البرمجية غير المدارة (أو غير الشفرة) بواسطة نظام التشغيل. كما يوفر كلر لإدارة الذاكرة الديناميكية باستخدام جامع القمامة لإدارة تخصيص و ديالوكاتيون من مساحة الذاكرة، والقضاء على مشاكل تسرب الذاكرة المشتركة التي غالبا ما تحدث في البرنامج. وتخصيص كلر s للذاكرة على كومة الذاكرة المؤقتة هو، في الواقع، أسرع في الواقع من توزيع كومة الذاكرة المؤقتة غير المدارة وتقريبا سرعة تخصيص ذاكرة المكدس لأنه يخصص مواقع الذاكرة المتجاورة ببساطة عن طريق زيادة مؤشر. في، يقوم المجمع بتجميع شفرة المصدر المدارة أولا في مسيل. قبل تشغيل التعليمات البرمجية، يتم تحويل مسيل بواسطة مترجم في الوقت المناسب (جيت) محددة لهندسة الكمبيوتر الخاص بك. جيت تحويل مسيل إلى لغة الآلة، أو التعليمات البرمجية الأصلية، في وقت التشغيل جمع القمامة يحدد جامع القمامة أفضل وقت لأداء مجموعة من الكائنات غير المسترجعة. يقوم جامع القمامة بإطلاق مساحة الذاكرة المخصصة للأجسام التي لم تعد يشار إليها (أو يشار إليها) داخل التطبيق. يحتفظ الإطار بقائمة المراجع النشطة التي يحتفظ بها مترجم جيت و كلر. يستخدم جامع القمامة هذه القائمة لفحص كل مراجع التطبيق. الكائنات التي ليست على القائمة تعتبر غير قابلة للوصول وسيتم تحرير مساحة الذاكرة. ونتيجة لذلك، يقوم جامع القمامة بفحص الكومة المدارة ويجد كتل من المساحة التي تشغلها الأجسام غير المستأجرة. وفي الوقت نفسه، يتم ضغط مواقع الذاكرة المشار إليها ونقلها ويتم إجراء التحديثات الضرورية لمؤشرات المؤشر. من المهم أن نلاحظ بعد ذلك أن جامع القمامة سوف تتحرك الأجسام حولها في الذاكرة دون علمنا. وهذا ينطوي على آثار مهمة في وقت لاحق على الجمعيات تشكل الجمعيات اللبنات الأساسية للإطار وأي تطبيق يتم تطويره داخله. الجمعيات غالبا ما توجد كملفات قابلة للتنفيذ أو ملفات مكتبة الارتباط الحيوي وتحتوي على مجموعات من الفئات التي تشكل وحدة وظيفية منطقية. 24 2-7. نموذج التعليمات البرمجية: مساجيبوكسيكسامبل 9 تحتوي الجمعيات على معلومات حول المحتوى والإصدار والإعتمادية نتيجة التطبيقات التي نقوم بإنشائها مع فيسوال C لا تحتاج إلى الاعتماد على قيم التسجيل للعمل بشكل صحيح. وبما أن التسجيل غير مطلوب، يمكننا عموما تثبيت تطبيقات فيسوال C ببساطة عن طريق نسخ الدليل القابل للتنفيذ s على الكمبيوتر المستهدف نامسباسس تقوم مساحات الأسماء بتنظيم الآلاف من الفئات في المكتبات، ومنع الغموض، وتبسيط المراجع، كما سنرى. (برامج فك التي نكتبها غالبا ما تحتوي على أو تستخدم مساحات أسماء متعددة). في مساحة اسم النظام هو مساحة اسم الجذر ويحتوي على أنواع البيانات البدائية والفئات الأساسية مثل كائن (الذي يتم اشتقاق كافة الكائنات)، سلسلة، استثناء، والقمامة جامع الدرجة، غ. تحتوي وثائق فيسوال ستوديو (ملفات المساعدة) على صفحة مرجعية مكتبة فئة إطار توفر قائمة شاملة لمسافات الأسماء مع الوصف. نظرا لأن كل البرمجة في تعتمد على الكائنات الموجودة في مساحات الأسماء هذه، قد تحتاج إلى قضاء بعض الوقت في التعرف على مساحات الأسماء المختلفة وأنواع الكائنات التي تحتوي على أسماء مؤهلة بالكامل عند استخدام المكتبات، يمكننا إنشاء الكائنات المعرفة في مواقع خارجية، مثل طالما نضيف إشارة إلى التجمع ثم استخدم اسم مؤهل تماما للفئة في التعليمات البرمجية لدينا. اسم مؤهل بالكامل هو مرجع فئة مسبوقة مع اسم مساحة الاسم. Here is an example of how to create an object using the fully qualified class name for a class in another namespace: System::Windows::Forms::MessageBox::Show( Hello, world ) Fully qualified names prevent naming conflicts because the compiler can always determine which class is being used. However, the names themselves can get long and cumbersome. As a way around this, we can use the using namespace statement. The following code uses this shortcut: using namespace System::Windows::Forms MessageBox::Show( Hello, world ) As you will see, within our own user-defined namespaces, we can define modules, interfaces, classes, delegates, enumerations, structures, and even other namespaces Sample Code: MessageBoxExample Let s create a new Visual C program that will illustrate the use of namespaces. Step 1. Start Visual Studio Step 2. In the File menu item, click on New and Project The New Project window will appear (Figure 2-1). Step 3. Highlight Visual C Projects in the Projects Types pane and CLR Console Application in the templates pane. Also, be sure to give your project a name and a location. انقر فوق موافق. 25 10 CHAPTER 2 The Framework When your solution is ready, you should see the Solution Explorer window on the righthand side of your screen. If not, click on the icon as shown. The Solution Explorer will allow you to navigate through the files that comprise your solution (Figure 2-2). Because our Console Application does not by default allow for a user interface, we need to add a reference to the System::Windows::Forms namespace. The Forms namespace contains the class definitions for Windows forms. FIGURE 2-1 FIGURE 2-2 26 2.8. SAMPLE CODE: STRINGCONCATEXAMPLE 11 Step 4. In the Solution Explorer window, right click on the project name and select References The MessageBoxExample Property Pages window will appear. Click on the Add New Reference icon. In the list of components, navigate down to System::Windows::Forms. Click Select and then click OK. The References directory in the Property Pages window should now list System. Windows::Forms. Step 5. In the MessageBoxExample. cpp code window, type the following: MessageBoxExample. cpp. main project file. include stdafx. h using namespace System using namespace System::Windows::Forms int main(arrayltsystem::stringgtargs) Console::WriteLine(L Hello, World ) MessageBox::Show( Hello, World ) return 0 Step 6. Compile the program by clicking the Build menu item and Build MessageBox Example. Run the program by clicking the Debug menu item and Start Without Debugging. Notice again that the MessageBox class definition is located within the System. Windows::Forms namespace. (Using the optional L before a string constant designates the native, wide character type wchart.) 2.8. Sample Code: StringConcatExample Concatenating strings for display can be done in many ways as can formatting numbers for display using the String class or the ToString method as shown. The StringBuilder class also comes in handy. In order to use the StringBuilder class, use the System::Text namespace as shown. include stdafx. h using namespace System using namespace System::Text int main(arrayltsystem::stringgt args) String mlang C int my 2005 27 12 CHAPTER 2 The Framework Console::WriteLine( This is Visual 0 1, mlang, my) Console::WriteLine(String::Concat( This is Visual, mlang. my)) Console::WriteLine( This is Visual mlang my) Notice the formatting possible using the ToString method. Console::WriteLine(Math::PI. ToString( . )) StringBuilder mbuilder gcnew StringBuilder( This is Visual C ) mbuilder-gtappend(my) Console::WriteLine(mBuilder) return 0 2.9. Sample Code: DebugExample Here is another example that illustrates the use of the Debug class and the Output Window. Step 1. Start Visual Studio 2005 as before. This time highlight Visual C Projects in the Projects Types pane and Windows Forms Application in the templates pane. Again, be sure to give your project a name and a location. Step 2. The Form1.h Design Window should appear. Double click on your Form1 and Visual Studio will automatically generate an event handler for the Form1 load event. This function will run when Form1 loads. Add the following code to the method: private: System::Void Form1Load(System::Object sender, System::EventArgs e) Debug::WriteLine( Hello, World ) The output of this program does not show a message box, but rather will print the output through the Debug class, which is defined in the System::Diagnostics namespace, which we will need to add. Step 3. In the Form1.h code window, be sure to add: using namespace System::Diagnostics Here is what the completed, Form1 code window should look like. pragma once namespace DebugExample using namespace System using namespace System::ComponentModel using namespace System::Collections 28 2.9. SAMPLE CODE: DEBUGEXAMPLE 13 using namespace System::Windows::Forms using namespace System::Data using namespace System::Drawing using namespace System::Diagnostics public ref class Form1. public System::Windows::Forms::Form public: Form1(void) InitializeComponent() protected: Form1() if (components) delete components private: System::ComponentModel::Container components Windows Forms Designer generate code private: System::Void Form1Load(System::Object sender, System::EventArgs e) Debug::WriteLine( Hello, World ) Step 4. Build your application and then run it using the blue Start icon on your task bar. To view the output, view the aptly named Output window (Figure 2-3). If you cannot find it, click on the Other Windows icon. We often use the static methods of the Debug class to print program information and to check program logic. Use of the Debug class does not impact the performance of the application. 29 14 CHAPTER 2 The Framework FIGURE Versioning The Framework provides help with project versioning. In a project s AssemblyInfo. cpp file, we can set the version number easily. Version information for an assembly consists of the following four values: Major Version Minor Version Build Number Revision You can specify all the value or you can default the Revision and Build Numbers by using the as shown next: assembly:assemblyversionattribute( 1.0. ) Summary This chapter reviewed the VC solution structure, how assemblies and namespaces are organized, how the CLR controls managed memory, and the garbage collector. Also, we developed some simple solutions to illustrate use of message boxes, the debug window, the console window, and string concatenation. Finally, we looked at some of the reasons why VC is such a great language for developing automated trading systems. 30 CHAPTER 3 Tracking References Because a referenced type may be moved around at runtime by the common language runtime (CLR), the native C amp cannot be used to reference an object on the garbage collected heap. In VC the CLR will update the new tracking reference with the new location. A tracking reference can refer to a managed or native object, a data member, or a storage location, but cannot be a member of a class. Also, by using a tracking reference in a template function, we can ensure that the function can be called with native, value, or reference types Sample Code: TrackingReferenceExample This example shows that the tracking reference replaces the native C amp reference. As you will see, however, we will still use the native amp on occasion. include stdafx. h using namespace System int main(arrayltsystem::string gt args) int x 3 int ampa x int b x Console::WriteLine(x) Console::WriteLine(a) Console::WriteLine(b) return 0 15 31 16 CHAPTER 3 Tracking References 3.2. Sample Code: TemplateFunctionExample For now, do not worry about the distinction between a ref class, a native class, and a value class. This is not a fully working code example as the class definitions are left out. Here, simply note the use of the tracking reference operator in the template function. include stdafx. h include MyRefClass. h include MyNativeClass. h include MyValueClass. h using namespace System templatelttypename Tgt void function1(t) int main(arrayltsystem::string gt args) MyRefClass mrefobj(3) MyNativeClass mnativeobj(4) MyValueClass mvalueobj(5) Managed Heap Stack Stack function1(mrefobj) function1(mnativeobj) function1(mvalueobj) return 0 templatelt typename T gt void function1(t manyobj) Console::WriteLine(mAnyObj. getValue()) VC supports templates and also things called generics, which we will look at in a later chapter Managed Handle Because a referenced object may be moved around at runtime by the common language runtime, the native C cannot be used to point on an object on the garbage collected, or managed, heap. In VC, replaces to declare a handle to an object on the managed heap and then uses gcnew rather than the traditional new keyword to create instances. Object member selection through this handle uses the arrow notation. 32 3.5. SUMMARY Sample Code: RefTypeExample This example will be explained in more detail in a later chapter. For now, just take note of the new notation, which declares a handle to a managed object. A handle, for our purposes, operates in a fashion logically equivalent to a C pointer. include stdafx. h include MyClass. h using namespace System int main(arrayltsystem::string gt args) MyClass mobj gcnew MyClass(2) Console::WriteLine(mObj-gtgetValue()) return 0 3.5. Summary This chapter looked at the new syntax for managed references, , and managed pointers, . We will be using managed references thoughout the book, so be sure you are comfortable with them before you proceed. 33 This page intentionally left blank 34 CHAPTER 4 Classes and Objects This book uses objects and object-oriented programming (OOP) to control program flow. OOP enables us to organize large programs logically and allows us to perform very large and complex tasks with fewer lines of code. Before we begin, let s review classes and objects. An object is an instance of a class and, in addition to our own classes, Microsoft s Framework gives us hundreds of ready-made classes in the namespaces. We can create instances of these classes as reference types and as such they will be managed by the common language runtime (CLR). Visual C is an object-oriented programming language. As such we will make use of classes, which have data and functionality together in their respective definitions. Classes have member variables or data members that store data and functionalities, or behaviors, held in procedures known as methods or member functions. As we will see, classes may also have events associated with them. The button click is an example of an event. In a working program, different objects work together, or talk to each other, through their respective public interfaces the collection of public methods exposed by an individual object. That is to say, private data within an object, which is not accessible from the outside world, is available to the outside programming environment only via the object s public interface. A major benefit of OOP is that because the data and methods encapsulated in classes are so closely tied together, we do not need to pass member variables back and forth as inputs to the member functions. Rather, member functions can access member variables directly within their definitions. If you are not overly familiar with classes, Table 4-1 shows elements that make up a class. In Visual C, we can create our own user-defined classes and create objects based on them. For example, we could create a class called Instrument. In a program, a real-life, tradable instrument would be an object, i. e. an instance of the Instrument class. Let s briefly review the four main concepts of object-oriented programming: abstraction, encapsulation, inheritance, and polymorphism Abstraction Abstraction is the process of creating an abstract model of a real-world object or thing. The process consists of taking the attributes, or properties, and functionalities, or methods, of a thing and turning them into logical pieces of data and functionality. 19 35 20 CHAPTER 4 Classes and Objects TABLE 4-1 Member Variables Variables Objects Properties Property Member Functions Methods Constructor Finalization Events Event Description Simple, primitive data. Other types classes, structures, interfaces, enums, etc. Description Values of member variables can be defined and retrieved through public get and set methods using the sign. Description Member functions that allow the object to do things. Method that runs when an instance of class is created. Method that runs when an object is destroyed. Description Message sent from an event source object to another object(s), called the event receiver(s). Let s look at our Instrument class. To turn a tradable instrument into a class in Visual C, we need to think about the properties of an instrument, i. e. what are the nouns associated with it, such as the symbol and price, as well as the verbs, or functionalities, or behaviours, of an instrument, such as setting and returning the price or entering an order. When we come up with a list of nouns, the what it is of an object, and verbs, the what it does, we say that the object has been abstracted. Let s assume that we have fully abstracted our Instrument class into the nouns and verbs shown in Table 4-2. TABLE 4-2 Nouns Symbol Bid Ask Last Trade Price Last Trade Qty Bid Qty Ask Qty Expiration Verbs Enter Order Cancel Order(s) Description The ticker symbol (unique identifier) of the instrument. The highest bid price. The lowest ask price. The price at which the last trade was executed. The quantity of the last trade. The volume on the bid price in the exchange order book. The volume on the ask price in the exchange order book. The date of the expiration of the instrument, if any. Description Sends an order to the exchange. Sends a request to the exchange to cancel an order or orders. 36 4.5. MEMORY MANAGEMENT IN Encapsulation Encapsulation is the process of containing abstracted data and functionalities into a class, exposing to the outside world only those methods that absolutely must be exposed, which are then known collectively as the class public interface. So, classes hide the implementation of their properties and methods and communicate with the external programming environment through the public interface. In this way, encapsulation protects the object from being tampered with and frees the programmer from having to know the details of the object s implementation. In our Instrument class example, because the outside programming environment does not need to be exposed to the method of retrieving the real-time bid or ask price, this functionality is encapsulated and made invisible to the outside world Inheritance Within an automated trading system, we need to represent tradable instruments in code. A futures contract is a tradable instrument, as is a stock or an option. All of these could become objects in our program so we will need to create classes for these. However, all of these are also instances of the Instrument class as we have abstracted it. The Instrument class contains only those properties and methods that are common to all tradable instruments. In order to represent a futures contract in our program, we could create a new Futures class that inherits from the Instrument class. As such, the Futures class would inherit all the properties and methods from the base, or parent, Instrument class. The Futures class then may have some added properties or functionalities that are unique to futures contracts. Likewise, we could create an Option class that inherits from the Instrument class and has its own specific functionalities added on. A derived class can add functionality beyond that of the base class and it can also override methods of its base class, i. e. a derived class may replace a member function definition of the base class with its own new definition. It is important to note that Visual C provides for three types of classes references types, value types, and unmanged types and the abilities and intricasies of inheritance differ among the three types. As you will see, s common type system dictates that all reference types inherit from the base Object class Polymorphism Briefly, polymorphism allows us to have one method name, or function name, used in different derived classes, but yet have different implementations, or functionalities, associated with that name depending on the class. In a CallOption class and a PutOption class, for example, we may have inherited a BlackScholesPrice() method from the parent Option class, but yet each of the derived classes has their own method for calculation, as the equations for Black Scholes call and put pricing are different Memory Management in In, there are four memory spaces managed and unmanaged stacks and managed and unmanaged heaps. It Doesnt Seem Possible. ولكن هو مع استراتيجيات التداول خوارزمية لدينا لا يبدو ممكنا. نظام التداول الخوارزمية واحد مع الكثير من تحديد الاتجاه، وتحليل الدورة، وتدفق حجم الجانب بيسيل، استراتيجيات التداول متعددة، دخول ديناميكية، والهدف ووقف الأسعار، وتكنولوجيا إشارة فائقة السرعة. و لكنها. في الواقع، ألغوترادس منصة نظام التداول خوارزمية هي الوحيدة من نوعها. لا مزيد من البحث عن الأسهم الساخنة والقطاعات والسلع والمؤشرات، أو قراءة آراء السوق. ألغوترادس يفعل كل البحث والتوقيت والتجارة بالنسبة لك باستخدام نظام التداول الخوارزمية لدينا. ويمكن اتباع استراتيجيات ألغوترادس ثبت يدويا عن طريق تلقي البريد الإلكتروني وتنبيهات النص سمز، أو يمكن أن يكون 100 التداول حر اليدين، متروك لكم يمكنك تشغيل أونوف التداول الآلي في أي وقت حتى كنت دائما في السيطرة على مصيرك. أنظمة التداول الآلي للمستثمرين الوافدين كوبيرايت 2017 - ألغوترادس - نظام التداول الآلي الخوارزمي كفتك القاعدة 4.41 - نتائج الأداء البدني أو المحاكاة لها بعض القيود. لا سجل الأداء الفعلي، النتائج المحاكاة لا تمثل التداول الفعلي. أيضا، وبما أن التجارة لم يتم تنفيذها، فإن النتائج قد تكون قد تم تعويضها أو تعوض عن تأثير، إن وجدت، من بعض عوامل السوق، مثل عدم وجود السيولة. برامج التداول المحاكاة بشكل عام هي أيضا تخضع لحقيقة أنها تم تصميمها مع الاستفادة من الأذهان. لا يتم تمثيل أي حساب أو سيكون من المرجح تحقيق الأرباح أو الخسائر مماثلة لتلك التي تظهر. ولا يتم تقديم أي تمثيل ولا يعني ضمنا أن استخدام نظام التداول الحسابي سيولد دخلا أو يضمن ربحا. هناك خطر كبير من الخسارة المرتبطة بتداول العقود الآجلة وصناديق التداول المتداولة. وتشمل عمليات التداول في العقود الآجلة والصناديق المتداولة في البورصة مخاطر كبيرة من الخسارة، وهي ليست مناسبة للجميع. وتستند هذه النتائج إلى نتائج أداء محاكاة أو افتراضية لها بعض القيود المتأصلة. وخلافا للنتائج المبينة في سجل الأداء الفعلي، فإن هذه النتائج لا تمثل التداول الفعلي. ولأن هذه الصفقات لم يتم تنفيذها فعليا، فإن هذه النتائج قد تكون أقل من أو تعوض عن تأثير بعض عوامل السوق، مثل نقص السيولة. برامج التداول المحاكاة أو الافتراضية بشكل عام تخضع أيضا لحقيقة أنها مصممة مع الاستفادة من بعد. ولا يوجد أي تمثيل بأن أي حساب سيحقق أو يرجح أن يحقق أرباحا أو خسائر مماثلة لتلك التي تظهر. وقد تم إعداد المعلومات على هذا الموقع دون النظر إلى أي أهداف استثمارية معينة للمستثمرين والوضع المالي والاحتياجات، كما ننصح المشتركين بعدم التصرف بأي معلومات دون الحصول على مشورة محددة من مستشاريهم الماليين بعدم الاعتماد على المعلومات من الموقع كأساس أساسي لقراراتهم الاستثمارية والنظر في المخاطر الخاصة بهم، والتسامح المخاطر، وخسائر وقف الخاصة بهم. - powered by Enfold WordPress ThemeBuilding Automated Trading Systems. With an Introduction to Visual C 2005 Transcription 2 Building Automated Trading Systems With an Introduction to Visual C 2005 3 The Financial Market Technology Series Series Editor Ben Van Vliet The Financial Market Technology Series is a partnership between Elsevier, Inc. and the Institute for Market Technology (i4mt) to publish cutting-edge books covering topics concerning the integration of technology with financial markets, including: automated trading, building trading and investment systems, operational issues in back office processing, clearing and settlement, and compliance and governance issues as they relate to technology. The goal of the series is to promote increased understanding and competency with technology in the finance industry through publishing high-quality books on the latest areas of research and practice for professionals working in the financial markets. Series Editor: Ben Van Vliet is a Lecturer in and the Associate Director of the M. Sc. in Financial Markets Program at the Stuart Graduate School of Business, Illinois Institute of Technology. Within this program, he teaches graduate courses in quantitative finance and automated trading system development using Visual Basic, SQL, XML, ISO C and Visual C and UML. He is also a co-inventor of TraderDNA, a real-time trading performance evaluation software package, as well as being a Director at TraderDNA LLC. He also serves as Vice Chairman of the Institute for Market Technology (i4mt), a notfor-profit organization that provides educational programs in financial markets and technology, where he also chairs the Market Technology Committee for the Certified Trading System Developer (CTSD) program. Please see for further information. Mr. Van Vliet also consults extensively in the financial industry. He is the author of Building Automated Trading Systems (Academic Press, 2007) and co-author of Modeling Financial Markets (McGraw-Hill 2004). We welcome proposals for books for the series. Please go to where you will find a link to send us your proposal. 4 Building Automated Trading Systems With an Introduction to Visual C 2005 Benjamin Van Vliet AMSTERDAM BOSTON HEIDELBERG LONDON NEW YORK OXFORD PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO Academic press is an imprint of Elsevier 5 Academic Press is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA 525 B Street, Suite 1900, San Diego, California. USA 84 Theobald s Road, London WC1X 8RR, UK This book is printed on acid-free paper. Copyright 2007, Elsevier Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopy, recording, or any information storage and retrieval system, without permission in writing from the publisher. Permissions may be sought directly from Elsevier s Science amp Technology Rights Department in Oxford, UK: phone: (44). fax: (44). You may also complete your request on-line via the Elsevier homepage (elsevier), by selecting Support amp Contact then Copyright and Permission and then Obtaining Permissions. Library of Congress Cataloging-in-Publication Data Van Vliet, Benjamin Building automated trading systems. with an introduction to Visual C 2005 Benjamin Van Vliet. ص. سم. Includes bibliographical references and index. ISBN (alk. paper) 1. Electronic trading of securities. 2. Finance Mathematical models. 3. Microsoft Visual C Microsoft. I. Title. HG V dc British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN 13: ISBN 10: For information on all Academic Press publications visit our Web site at Printed in the United States of America 6 Contents Acknowledgments xiii CHAPTER 1 Introduction ISO C Structure of This Book 2 Section I: Introduction to Visual C 2005 CHAPTER 2 The Framework MS Visual Studio 2005 Project Structure What is CCLI Why Visual C The VC Compiler What About Speed The Framework Sample Code: MessageBoxExample Sample Code: StringConcatExample Sample Code: DebugExample Versioning Summary 14 CHAPTER 3 Tracking References Sample Code: TrackingReferenceExample Sample Code: TemplateFunctionExample Managed Handle Sample Code: Ref TypeExample Summary 17 v 7 vi Contents CHAPTER 4 Classes and Objects Abstraction Encapsulation Inheritance Polymorphism Memory Management in NET Types Unmanaged Types Mixed Assemblies Summary 23 CHAPTER 5 Reference Types Sample Code: Ref TypeExample Delete and Dispose Finalize Sample Code: FinalizeExample Stack Semantics for Ref Types Nullptr Reference T his is Important Summary 31 CHAPTER 6 Value Types Sample Code: ValueTypesExample Sample Code: PassingValueTypesExample Summary 36 CHAPTER 7 Unmanaged Objects Sample Code: UnmanagedObjectExample Summary 39 CHAPTER 8 Composition Sample Code: CompositionExample Sample Code: UnmanagedCompositionExample Sample Code: ManagedCompositionExample Summary 48 CHAPTER 9 Properties Sample Code: PropertiesExample Summary 50 CHAPTER 10 Structures and Enumerations Sample Code: ValueStructureExample Sample Code: ReferenceStructureExample Sample Code: EnumsExample Summary 53 8 Contents vii CHAPTER 11 Inheritance Access Modifi ers Object Class Abstract and Sealed Classes Sample Code: InheritanceExample Interfaces Sample Code: InterfaceExample Runtime Callable Wrapper Summary 60 CHAPTER 12 Converting and Casting Converting Sample Code: ConvertExample Static Casting Sample Code: StaticCastExample Dynamic Casting Sample Code: DynamicCastExample Safe Casting Sample Code: SafeCastExample Summary 65 CHAPTER 13 Operator Overloading Sample Code: OpOverloadExample Summary 69 CHAPTER 14 Delegates and Events Delegates Sample Code: DelegatesExample Multicasting Sample Code: MulticastExample Events Sample Code: EventExample Wrappers Sample Code: WrapperExample Asynchronous Method Calls Sample Code: AsynchEventExample Summary 82 CHAPTER 15 Arrays Sample Code: ManagedArrayExample Sample Code: PassingArraysExample Summary 85 vii 9 viii Contents CHAPTER 16 Generating Random Numbers Sample Code: RandomExample Sample Code: StdNormRandomExample Summary 89 CHAPTER 17 Time and Timers Sample Code: MillisecondsExample Stopwatch Sample Code: StopwatchExample Timers Sample Code: FormsTimerExample Sample Code: ThreadingTimerExample Sample Code: TimersTimerExample Summary 98 CHAPTER 18 Input and Output Streams FileStream Class StreamWriter Class File and Directory Classes Application Class FileMode Enumeration Sample Code: StreamWriterExample Sample Code: StreamReaderExample Summary 101 CHAPTER 19 Exception Handl ing Sample Code: ExceptionsExample Catching Unmanaged C Types Summary 105 CHAPTER 20 Collections Sample Code: HashtableExample Sorted List Class Sample Code: SortedListExample Thread Safety Generics Sample Code: LinkedListExample Sample Code: GenericsExample Summary 112 CHAPTER 21 STLSTL Sample Code: STLExample Sample Code: STLExample Summary 114 10 Contents ix CHAPTER 22 DataSets Sample Code: DataSetExample Rows, DataRowCollections, and DataRows Summary 117 CHAPTER 23 Connecting to Databases Database Connection DataAdapter Sample Code: ADOExample Enumerating Through All the Data in a DataSet Using Excel as a Data Source Writing XML from a DataSet Updating a Database with Changes in a Dataset Retrieving Data with a DataReader Summary 124 CHAPTER 24 Structured Query Language Data Manipulation Language Updating a Database with Changes in a DataSet Data Defi nition Language Summary 140 CHAPTER 25 XML Well-Formed XML Documents Valid XML Documents XML Schema Documents Parsers Sample Code: T raders. xsd Sample Code: XmlWriterExample Sample Code: XmlReaderExample Summary 146 CHAPTER 26 Financial Information Exchange Protocol XML Protocols in Financial Markets Overview of FIX Summary 151 CHAPTER 27 Serialization SerializationExample Summary 154 CHAPTER 28 Windows Services Sample Code: WindowsServiceExample Summary 159 11 x Contents CHAPTER 29 Setup and Installation Packages Sample Code: InstallationExample Summary 162 Section II: Concurrency CHAPTER 30 Threading Threading Namespace Sample Code: ThreadExample Sample Code: ThreadAbortExample Thread Priority Sample Code: ThreadPriorityExample ThreadState Enumeration ThreadPool Class Sample Code: ThreadPoolExample Updating Forms from Other Threads Sample Code: FormUpdateExample Thread Safety Summary 175 CHAPTER 31 Synchronization Classes Sample Code: SynchronizeExample Mutex Class Example Code: MutexExample Semaphore Class Sample Code: SemaphoreExample Monitor Class Sample Code: Monitor Summary 182 CHAPTER 32 Sockets Sample Code: SynchronousServerExample Sample Code: SynchronousClientExample Summary 189 Section III: Interoperability and Connectivity CHAPTER 33 Marshaling Marshal Class Sample Code: StringToCharArrayExample Summary 194 CHAPTER 34 Interior and Pinning Pointers Sample Code: InteriorPointerExample Pinning Pointers Sample Code: PinningExample Summary 198 12 Contents xi CHAPTER 35 Connecting to Managed DLLs Example Code: DLLExample Summary 201 CHAPTER 36 Connecting to Component Object Model (COM) DLLs with COM Interop Sample Code: MyCOMLibrary Sample Code: UsingCOMDLLExample Summary 207 CHAPTER 37 Connecting to C DLLs with Platform Invocation Services Calling C-Style Functions Sample Code: MyWin32Library Sample Code: UsingWin32DLLExample Creating Objects Sample Code: MyWin32ClassLibrary Sample Code: UsingWin32ClassExample CallingConventionEnumeration Summary 216 CHAPTER 38 Connecting to Excel Sample Code: ControllingExcelExample Sample Code: ExcelChartExample Summary 221 CHAPTER 39 Connecting to Trad erAPI TraderAPI Overview FillObj InstrObjClass InstrNotifyClass OrderObj OrderProfi leclass OrderSetClass Sample Code: TraderAPIConnectionExample Summary 230 CHAPTER 40 Connecting to XTAPI Sample Code: XTAPIConnectionExample Summary 233 13 xii Contents Section IV: Automated Trading Systems CHAPTER 41 Building Trading Systems Buy vs. Build Data Mapping Speed of Development Ten Things that Affect the Speed of a Trading System Getting It Right Logic Leaks Ten Things that Affect the Profi tability of a Trading System Summary 245 CHAPTER 42 K V Trading System Development Methodology The Money Document Research and Document Calculations Back Test Implement Manage Portfolio and Risk Summary 257 CHAPTER 43 Automated Trading System Classes Instrument Class Order Class Order Book Bracket Tick Tick or Bar Collection Bar System Manager Graphical User Interface Summary 265 CHAPTER 44 Single-Threaded, Technical Analysis System Sample Code: TechincalSystemExample Summary 277 CHAPTER 45 ProducerConsum er Design Pattern Sample Code: ProducerConsumerExample Summary 287 CHAPTER 46 Multithreaded, Statistical Arbitrage System Sample Code: SpreaderExample Summary Conclusion 304 14 Acknowledgments This book began as the class notes for a course I teach at the Illinois Institute of Technology called Advanced Object Oriented Programming for Financial Markets. In this class we cover automated trading system design and development using Microsoft Visual C. When I started teaching this course several years ago, I could not find a book that covered all the topics necessary to build real-time, automated trading systems and so, as a result, this book attempts to do just that it brings together programming and technology-related topics for the development of trade selection, order routing, order management, and position management algorithms. I do hope that more schools will offer courses on automated trading system design in the future and that this book will be helpful in their instruction. Furthermore, this book is a foundation text for the CTSD Certified Trading System Developer program offered by the Institute for Market Technology (i4mt. org). This is a new certification program that consists of three examinations, one in quantitative finance, one in securities and derivatives trading strategy, and one in ISO CC programming and market technology. This rigorous self-study program is designed to bring together the skillsets in demand in the financial industry today. Candidates who achieve the CTSD designation will be talented people indeed. As one can imagine, additional credit for the completion of this project must be given to many friends, family, and colleagues: in particular to my wife, Julia, Mark McCracken, Dr. Andrew Kumiega, Andrew Acosta, Sagy Mintz, Jason Malkin, Larissa J. Miller, Derek Walther, Niraj Chokshi, Julian Mulla, Mike Hermanson, David Norman, Dr. Deborah Cernauskas, Dr. Joe Wojkowski, Pamela Reardon, Edward Wang, Alex Deitz, Andrew Robinson, and all my colleagues at the IIT Center for Financial Markets Russell Wojcik, Dr. Michael Gorham, Keith Black, Dr. Michael Ong, Dr. John Bilson, Dr. Michael Kelly, and Jodi Houlihan. Also I would like to thank the many students who have taken my course and have all provided valuable feedback. Without their help and the help of many others this book would never have been completed. xiii 15 xiv Acknowledgments This book is written for people with knowledge of ISO C or possibly Java,, or COM. For financial engineers and aspiring financial engineers with a general programming background, this book will provide an in-depth discussion of higher level programming concepts such as event handling, interoperability, data feed connectivity, and concurrency. For experienced C programmers, you may find that this book provides a good introduction to the use of C within the Framework. Whatever the case, I hope you learn from it and are inspired to delve deeper into the topic of automated trading system development. Please provide me with any feedback you have. I pledge to update my website, regularly with corrections to errata and additional examples. 16 CHAPTER 1 Introduction Automated (or algorithmic) trading systems consist of many parts, both hardware and software clients, servers, networks, databases, calculation engines, application programming interfaces, real-time data feeds, and graphical user interfaces. However, the business logic of trading systems, which consists of trade selection algorithms, order management, and position management logic, is contained within software, and this book is concerned with the encapsulation of trading system business logic in software that controls the flow of market data. (There is no quant in this book.) An automated trading system consists of the rules for entry into and exit from a position or positions and the technology, both hardware and software, used to make them happen. These rules are a set of logical or mathematical operations that can be based on qualitative, technical, or quantitative research. If we want to build an automated system that executes trades on electronic exchanges, we need to learn how to work with data, both real-time market data and historical data, in code. After all, data is the lifeblood of electronic markets, according to David Norman in his book Professional Electronic Trading. That s just what this book is about, using Visual C to manage financial markets data (and there is a lot of it) in trading system applications. Generally speaking, this book covers three things: 1. Managing data in memory. 2. Storing data in and retrieving from databases. 3. Communicating data. Front office programming in financial markets is largely concerned with connecting to databases, real-time data feeds, order execution platforms, quant libraries, optimization engines, charting software, report generation engines, legacy technologies, and Excel, just to name a few. In order to successfully manage real-time and historical data, we will need to understand: 1. Event-driven architecture. 2. Concurrency. 3. Connectivity and interoperability. 1 17 2 CHAPTER 1 Introduction While this book addresses dozens of important technological issues that you will face when building real-world automated trading systems in, it does not show you how to build a profitable trading system. (It is important nevertheless to recognize that technological superiority can be a major competitive advantage.) There are four disciplines that go into automated trading system development computer science, quantitative finance, trading strategy, and quality management and this is a computer science book. Development and testing of trade selection and risk management methods are topics for other books. This book covers the basics of what a financial engineer should know about programming in objects, SQL, multithreading, interoperability, messaging, order selection algorithms, and order management techniques. In this text, I have tried to include market-driven, job-relevant information. Today s employers in the financial markets demand job readiness. If you want to get a job in the trading and money management industry, which more and more every day is driven by automated systems, you will have to have a competitive level of knowledge of programming. You should realize that this book is an overview, however. It will not teach you everything. Technology as a topic is obviously far too vast to cover in one book. Even narrowing it down to VC for trading system development is still far too vast. Over the pages, I will present several important ideas, try to point you in the right direction, and hopefully in the end inspire you to do additional research on the topic of automated trading system development. From there, the diligent financial engineer must investigate further on his or her own ISO C This book covers the programming aspects of trading system development and assumes that you are familiar with ISO C programming concepts, including pointers, functions, objects, and the Standard Template Library Structure of This Book Automated trading systems find their purest form in high-frequency strategies where speed of calculation and execution are the competitive advantage. Other systems, where milliseconds are not necessarily of the essence, may be fully automated or partially automated. This text will focus on introducing programming and design concepts for higher frequency systems. Discussion of all the alternative technological concepts of trading system design and presentation of a complete trading system are beyond the scope of a book. The trading systems presented in this book are drastically simplified in order to illustrate common programming and design concepts. This book is divided into four sections. The first section focuses purely on an introduction to Visual C types and programming techniques. The second section focuses on multithreading. The third focuses on interoperability and connectivity and the fourth on objects, design patterns, and architectural concepts for automated trading system development. In the end, simply reading this book will not make you an expert. To really learn the material in this book, you should also work through the code samples presented. Only by involving yourself in the process, and furthermore going beyond it, will you gain understanding and intuition. It s hard work, but it will pay off. 18 SECTION I Introduction to Visual C 2005 19 This page intentionally left blank 20 CHAPTER 2 The Framework 2.1. MS Visual Studio 2005 Project Structure In MS Visual Studio 2005, your software application is called a solution, and a solution can be made up of one or more projects, where each project could potentially be in a different Visual Studio language. Over the course of this book, I will present solutions developed for the most part in MS Visual C for managed or applications for reasons that I will explain shortly. However, be aware that Visual C is not a new programming language, but rather a full development environment that provides increased support for many C project types, including: Active Template Library (ATL) projects. MS Foundation Classes (MFC) projects. or managed console, Windows or DLL projects. Win32 Console projects for ISO C projects. Win32 API projects and DLLs. As a result, Visual C for or managed projects is just one of several C languages offered within Visual Studio 2005, and this is one of the things that sets the new VC apart from the others in the family it provides essentially five independent C languages in one package. So if you want to continue making MFC applications, you can do that just like before. In fact, support for MFC and ATL has actually been improved in VS In previous versions of Visual Studio, the extension was added to the name in order to differentiate it from even earlier versions, such as Visual Basic 6.0. With the advent of VS 2005, the extension to the name is usually left off and we can refer to them as VB, C, and Visual C What is CCLI CCLI (Common Language Infrastructure) is a derivation of C. According to Stanley Lippman of Microsoft: 5 21 6 CHAPTER 2 The Framework CLI refers to the Common Language Infrastructure, a multitiered architecture supporting a dynamic component programming model. In many ways, this represents a complete reversal of the C object model. A runtime software layer, the virtual execution system, runs between the program and the underlying operating system. Access to the underlying machine is fairly constrained. Access to the types active in the executing program and the associated program infrastructure both as discovery and construction is supported. The slash () represents a binding between C and the CLI So, a first approximation of an answer to what is CCLI is that it is a binding of the static C object model to the dynamic component object model of the CLI. In short, it is how you do programming using C rather than C or Visual Basic. Like C and the CLI itself, CCLI is undergoing standardization under the European Computer Manufacturers Association (ECMA) and eventually under ISO. The common language runtime (CLR) is the Microsoft version of the CLI that is specific to the Windows operating system. Similarly, Visual C is the implementation of CCLI. As a second approximation of an answer, CCLI integrates the programming model within C in the same way as, back at Bell Laboratories, we integrated generic programming using templates within the then existing C. In both of these cases your investments in an existing C codebase and in your existing C expertise are preserved. This was an essential baseline requirement of the design of CCLI. Over the course of this book, I will simply refer to Microsoft implementation of CCLI as Visual C. For Mr. Lippman s full article, go to msdnmagissues0600purecdefault. aspx Why Visual C So why Visual C What are the benefits of managed or C applications Simply put and in the words of a vice president of a major trading software vendor here in Chicago, NET is the future. Most importantly, the Framework contains many, many classes that aid in development of trading systems, as we will see. Furthermore, relative to the other languages, VC contains much greater support for interoperability between managed and unmanaged code. In addition, in financial markets, interoperability is key. In VC, we have precise control over managed and unmanaged heap and stack memory allocation and managed and unmanaged code and all can exist seamlessly in the same project. This permits us to integrate our existing C applications, functionality, and objects quickly and easily into new applications. This is especially true for COM applications, which are used heavily in the financial industry and are unmanaged. Further, if you have libraries of objects or financial functions written in native C, VC with its extensive managedunmanaged interop support will give you tremendous control. Alternatively, if you have existing C applications that you wish to convert to, again VC will provide you with the tools the other languages can t and don t. Finally, while the 2005 version of the STL (known as STL) is not available quite yet, it will be soon and converting native STL-dependent code will be a breeze. 22 2.6. THE FRAMEWORK The VC Compiler Here are a few things to remember about the VC compiler. The VC compiler, C1.exe, uses the. c extension for C-only compiling and. cpp for C and C. Also, the standard headers do not require the. h extension, as Microsoft has included its own versions of these files in the std namespace. Further, a project s properties window displays all of the compiler settings for CC, including the linker and build events. Microsoft s Cl. exe compiler implements ANSI C and ISO C standards and is 98 C compliant according to Microsoft. The compiler offers Solution Configurations for Debug builds and Release builds. With a Debug build, we can interact with our code during runtime. This is a big help. However, no optimizations are made and for that we use the Release build, which will generate faster, optimized code. The compiler allows us to incorporate native C code in our projects and first compiles into Microsoft Intermediate Language (MSIL). Then the MSIL is converted into native code by the Just In Time (JIT) compiler. With JIT some operations will be faster than native C, whereas others will be slower. As a result, there are trade-offs between development speed and execution speed. However, there are things we can do to minimize the cost of certain operations. The VC compiler and JIT can be tuned to generate the fastest possible code using the available compiler options. If you are serious about speed, take some time to investigate further Microsoft s VC compiler What About Speed Speed is important, of course. For an in-depth discussion of speed considerations in managed code, I will refer you to a few excellent articles in the MSDN Library (msdn. microsoft. comlibrary): A Baker s Dozen: Thirteen Things You Should Know Before Porting Your Visual C Programs to Visual Studio 2005 by Stanley Lippman. Best Practices for Writing Efficient and Reliable Code with CCLI by Kenny Kerr. C: The Most Powerful Language for Framework Programming by Kenny Kerr. Writing Faster Managed Code: Know What Things Cost by Jan Gray. Writing High-Performance Managed Applications: A Primer by Gregor Noriskin (includes an overview of the CLR Profiler). Tips for Improving Time-Critical Code. Optimization Best Practices in the Visual C section The Framework When we create managed Visual C applications, our programs are developed, compiled, and executed within the Framework. The Framework consists of three parts: 23 8 CHAPTER 2 The Framework 1. Common Language Runtime (CLR). 2. Class Libraries. 3. ASP. ASP is Microsoft s web development platform for building enterprise web applications, which run too slow for real-time, financial markets application, and so we will spend no time examining it. Rather we will spend our time learning about the common language runtime and the class libraries and how we can use them to build financial applications that can potentially run on multiple operating systems, not just Windows, including Unix, Linux, and Mac Common Language Runtime The CLR drives code execution within the Framework and provides-based programs with cross language integration, security, dynamic memory management, and debugging services. Further, the CLR controls what we call managed code, which is executed within the managed heap. That is to say, the managed heap is controlled by the Framework rather than the operating system. Unmanaged code (or non - code), however, is controlled by the operating system. The CLR also provides for dynamic memory management by using a garbage collector to manage the allocation and deallocation of memory space, eliminating the common memory leak problems that often occur in software. The CLR s allocation of memory on the managed heap is, it turns out, actually faster than unmanaged heap allocation and nearly as fast as stack memory allocation because it allocates contiguous memory locations by simply incrementing a pointer. In, the compiler compiles managed source code first into MSIL. Before code is run, MSIL is converted by a just-in-time (JIT) compiler specific to your computer architecture. JIT converts MSIL into machine language, or native code, at runtime Garbage Collection The garbage collector determines the best time to perform a collection of unreferenced objects. The garbage collector releases the memory space allocated to objects that are no longer being referenced (or, pointed to) within the application. The Framework keeps a list of active references that the JIT compiler and the CLR maintain. The garbage collector uses this list to examine all of an application s references. Objects that are not on the list are considered unreachable and the memory space will be released. As a result, the garbage collector examines the managed heap and finds blocks of space occupied by unreferenced objects. At the same time, referenced memory locations are compacted and moved and the necessary updates to the pointer references are made. It s important to note then that the garbage collector will be moving objects around in memory without our knowledge. This has important implications later on Assemblies Assemblies form the fundamental building blocks for the Framework and any application developed within it. Assemblies most often exist as executable files or dynamic link library files and contain groups of classes that form a logical functional unit. 24 2.7. SAMPLE CODE: MESSAGEBOXEXAMPLE 9 Assemblies contain information about content, versioning, and dependencies as a result the applications we create with Visual C do not need to rely on registry values to work properly. Since registry is not required, we can generally install Visual C applications by simply copying the executable s directory onto the target computer Namespaces Namespaces organize the thousands of classes in the libraries, prevent ambiguity, and simplify references, as we will see. (VC programs that we write will often contain or use multiple namespaces.) In the System namespace is the root namespace and contains primitive data types and fundamental classes such as Object (from which all objects are derived), String, Exception, and the garbage collector class, GC. The Visual Studio Documentation (the Help Files) contains a Framework Class Library Reference page that provides a comprehensive list of the namespaces with descriptions. Since all programming in depends on the objects contained in these namespaces, you may want to spend some time familiarizing yourself with the different namespaces and the types of objects they contain Fully Qualified Names When using libraries, we can instantiate objects defined in external locations, as long as we add a reference to the assembly and then use the fully qualified name for the class in our code. A fully qualified name is a class reference that is prefixed with its namespace name. Here is an example of how to create an object using the fully qualified class name for a class in another namespace: System::Windows::Forms::MessageBox::Show( Hello, world ) Fully qualified names prevent naming conflicts because the compiler can always determine which class is being used. However, the names themselves can get long and cumbersome. As a way around this, we can use the using namespace statement. The following code uses this shortcut: using namespace System::Windows::Forms MessageBox::Show( Hello, world ) As you will see, within our own user-defined namespaces, we can define modules, interfaces, classes, delegates, enumerations, structures, and even other namespaces Sample Code: MessageBoxExample Let s create a new Visual C program that will illustrate the use of namespaces. Step 1. Start Visual Studio Step 2. In the File menu item, click on New and Project The New Project window will appear (Figure 2-1). Step 3. Highlight Visual C Projects in the Projects Types pane and CLR Console Application in the templates pane. Also, be sure to give your project a name and a location. انقر فوق موافق. 25 10 CHAPTER 2 The Framework When your solution is ready, you should see the Solution Explorer window on the righthand side of your screen. If not, click on the icon as shown. The Solution Explorer will allow you to navigate through the files that comprise your solution (Figure 2-2). Because our Console Application does not by default allow for a user interface, we need to add a reference to the System::Windows::Forms namespace. The Forms namespace contains the class definitions for Windows forms. FIGURE 2-1 FIGURE 2-2 26 2.8. SAMPLE CODE: STRINGCONCATEXAMPLE 11 Step 4. In the Solution Explorer window, right click on the project name and select References The MessageBoxExample Property Pages window will appear. Click on the Add New Reference icon. In the list of components, navigate down to System::Windows::Forms. Click Select and then click OK. The References directory in the Property Pages window should now list System. Windows::Forms. Step 5. In the MessageBoxExample. cpp code window, type the following: MessageBoxExample. cpp. main project file. include stdafx. h using namespace System using namespace System::Windows::Forms int main(arrayltsystem::stringgtargs) Console::WriteLine(L Hello, World ) MessageBox::Show( Hello, World ) return 0 Step 6. Compile the program by clicking the Build menu item and Build MessageBox Example. Run the program by clicking the Debug menu item and Start Without Debugging. Notice again that the MessageBox class definition is located within the System. Windows::Forms namespace. (Using the optional L before a string constant designates the native, wide character type wchart.) 2.8. Sample Code: StringConcatExample Concatenating strings for display can be done in many ways as can formatting numbers for display using the String class or the ToString method as shown. The StringBuilder class also comes in handy. In order to use the StringBuilder class, use the System::Text namespace as shown. include stdafx. h using namespace System using namespace System::Text int main(arrayltsystem::stringgt args) String mlang C int my 2005 27 12 CHAPTER 2 The Framework Console::WriteLine( This is Visual 0 1, mlang, my) Console::WriteLine(String::Concat( This is Visual, mlang. my)) Console::WriteLine( This is Visual mlang my) Notice the formatting possible using the ToString method. Console::WriteLine(Math::PI. ToString( . )) StringBuilder mbuilder gcnew StringBuilder( This is Visual C ) mbuilder-gtappend(my) Console::WriteLine(mBuilder) return 0 2.9. Sample Code: DebugExample Here is another example that illustrates the use of the Debug class and the Output Window. Step 1. Start Visual Studio 2005 as before. This time highlight Visual C Projects in the Projects Types pane and Windows Forms Application in the templates pane. Again, be sure to give your project a name and a location. Step 2. The Form1.h Design Window should appear. Double click on your Form1 and Visual Studio will automatically generate an event handler for the Form1 load event. This function will run when Form1 loads. Add the following code to the method: private: System::Void Form1Load(System::Object sender, System::EventArgs e) Debug::WriteLine( Hello, World ) The output of this program does not show a message box, but rather will print the output through the Debug class, which is defined in the System::Diagnostics namespace, which we will need to add. Step 3. In the Form1.h code window, be sure to add: using namespace System::Diagnostics Here is what the completed, Form1 code window should look like. pragma once namespace DebugExample using namespace System using namespace System::ComponentModel using namespace System::Collections 28 2.9. SAMPLE CODE: DEBUGEXAMPLE 13 using namespace System::Windows::Forms using namespace System::Data using namespace System::Drawing using namespace System::Diagnostics public ref class Form1. public System::Windows::Forms::Form public: Form1(void) InitializeComponent() protected: Form1() if (components) delete components private: System::ComponentModel::Container components Windows Forms Designer generate code private: System::Void Form1Load(System::Object sender, System::EventArgs e) Debug::WriteLine( Hello, World ) Step 4. Build your application and then run it using the blue Start icon on your task bar. To view the output, view the aptly named Output window (Figure 2-3). If you cannot find it, click on the Other Windows icon. We often use the static methods of the Debug class to print program information and to check program logic. Use of the Debug class does not impact the performance of the application. 29 14 CHAPTER 2 The Framework FIGURE Versioning The Framework provides help with project versioning. In a project s AssemblyInfo. cpp file, we can set the version number easily. Version information for an assembly consists of the following four values: Major Version Minor Version Build Number Revision You can specify all the value or you can default the Revision and Build Numbers by using the as shown next: assembly:assemblyversionattribute( 1.0. ) Summary This chapter reviewed the VC solution structure, how assemblies and namespaces are organized, how the CLR controls managed memory, and the garbage collector. Also, we developed some simple solutions to illustrate use of message boxes, the debug window, the console window, and string concatenation. Finally, we looked at some of the reasons why VC is such a great language for developing automated trading systems. 30 CHAPTER 3 Tracking References Because a referenced type may be moved around at runtime by the common language runtime (CLR), the native C amp cannot be used to reference an object on the garbage collected heap. In VC the CLR will update the new tracking reference with the new location. A tracking reference can refer to a managed or native object, a data member, or a storage location, but cannot be a member of a class. Also, by using a tracking reference in a template function, we can ensure that the function can be called with native, value, or reference types Sample Code: TrackingReferenceExample This example shows that the tracking reference replaces the native C amp reference. As you will see, however, we will still use the native amp on occasion. include stdafx. h using namespace System int main(arrayltsystem::string gt args) int x 3 int ampa x int b x Console::WriteLine(x) Console::WriteLine(a) Console::WriteLine(b) return 0 15 31 16 CHAPTER 3 Tracking References 3.2. Sample Code: TemplateFunctionExample For now, do not worry about the distinction between a ref class, a native class, and a value class. This is not a fully working code example as the class definitions are left out. Here, simply note the use of the tracking reference operator in the template function. include stdafx. h include MyRefClass. h include MyNativeClass. h include MyValueClass. h using namespace System templatelttypename Tgt void function1(t) int main(arrayltsystem::string gt args) MyRefClass mrefobj(3) MyNativeClass mnativeobj(4) MyValueClass mvalueobj(5) Managed Heap Stack Stack function1(mrefobj) function1(mnativeobj) function1(mvalueobj) return 0 templatelt typename T gt void function1(t manyobj) Console::WriteLine(mAnyObj. getValue()) VC supports templates and also things called generics, which we will look at in a later chapter Managed Handle Because a referenced object may be moved around at runtime by the common language runtime, the native C cannot be used to point on an object on the garbage collected, or managed, heap. In VC, replaces to declare a handle to an object on the managed heap and then uses gcnew rather than the traditional new keyword to create instances. Object member selection through this handle uses the arrow notation. 32 3.5. SUMMARY Sample Code: RefTypeExample This example will be explained in more detail in a later chapter. For now, just take note of the new notation, which declares a handle to a managed object. A handle, for our purposes, operates in a fashion logically equivalent to a C pointer. include stdafx. h include MyClass. h using namespace System int main(arrayltsystem::string gt args) MyClass mobj gcnew MyClass(2) Console::WriteLine(mObj-gtgetValue()) return 0 3.5. Summary This chapter looked at the new syntax for managed references, , and managed pointers, . We will be using managed references thoughout the book, so be sure you are comfortable with them before you proceed. 33 This page intentionally left blank 34 CHAPTER 4 Classes and Objects This book uses objects and object-oriented programming (OOP) to control program flow. OOP enables us to organize large programs logically and allows us to perform very large and complex tasks with fewer lines of code. Before we begin, let s review classes and objects. An object is an instance of a class and, in addition to our own classes, Microsoft s Framework gives us hundreds of ready-made classes in the namespaces. We can create instances of these classes as reference types and as such they will be managed by the common language runtime (CLR). Visual C is an object-oriented programming language. As such we will make use of classes, which have data and functionality together in their respective definitions. Classes have member variables or data members that store data and functionalities, or behaviors, held in procedures known as methods or member functions. As we will see, classes may also have events associated with them. The button click is an example of an event. In a working program, different objects work together, or talk to each other, through their respective public interfaces the collection of public methods exposed by an individual object. That is to say, private data within an object, which is not accessible from the outside world, is available to the outside programming environment only via the object s public interface. A major benefit of OOP is that because the data and methods encapsulated in classes are so closely tied together, we do not need to pass member variables back and forth as inputs to the member functions. Rather, member functions can access member variables directly within their definitions. If you are not overly familiar with classes, Table 4-1 shows elements that make up a class. In Visual C, we can create our own user-defined classes and create objects based on them. For example, we could create a class called Instrument. In a program, a real-life, tradable instrument would be an object, i. e. an instance of the Instrument class. Let s briefly review the four main concepts of object-oriented programming: abstraction, encapsulation, inheritance, and polymorphism Abstraction Abstraction is the process of creating an abstract model of a real-world object or thing. The process consists of taking the attributes, or properties, and functionalities, or methods, of a thing and turning them into logical pieces of data and functionality. 19 35 20 CHAPTER 4 Classes and Objects TABLE 4-1 Member Variables Variables Objects Properties Property Member Functions Methods Constructor Finalization Events Event Description Simple, primitive data. Other types classes, structures, interfaces, enums, etc. Description Values of member variables can be defined and retrieved through public get and set methods using the sign. Description Member functions that allow the object to do things. Method that runs when an instance of class is created. Method that runs when an object is destroyed. Description Message sent from an event source object to another object(s), called the event receiver(s). Let s look at our Instrument class. To turn a tradable instrument into a class in Visual C, we need to think about the properties of an instrument, i. e. what are the nouns associated with it, such as the symbol and price, as well as the verbs, or functionalities, or behaviours, of an instrument, such as setting and returning the price or entering an order. When we come up with a list of nouns, the what it is of an object, and verbs, the what it does, we say that the object has been abstracted. Let s assume that we have fully abstracted our Instrument class into the nouns and verbs shown in Table 4-2. TABLE 4-2 Nouns Symbol Bid Ask Last Trade Price Last Trade Qty Bid Qty Ask Qty Expiration Verbs Enter Order Cancel Order(s) Description The ticker symbol (unique identifier) of the instrument. The highest bid price. The lowest ask price. The price at which the last trade was executed. The quantity of the last trade. The volume on the bid price in the exchange order book. The volume on the ask price in the exchange order book. The date of the expiration of the instrument, if any. Description Sends an order to the exchange. Sends a request to the exchange to cancel an order or orders. 36 4.5. MEMORY MANAGEMENT IN Encapsulation Encapsulation is the process of containing abstracted data and functionalities into a class, exposing to the outside world only those methods that absolutely must be exposed, which are then known collectively as the class public interface. So, classes hide the implementation of their properties and methods and communicate with the external programming environment through the public interface. In this way, encapsulation protects the object from being tampered with and frees the programmer from having to know the details of the object s implementation. In our Instrument class example, because the outside programming environment does not need to be exposed to the method of retrieving the real-time bid or ask price, this functionality is encapsulated and made invisible to the outside world Inheritance Within an automated trading system, we need to represent tradable instruments in code. A futures contract is a tradable instrument, as is a stock or an option. All of these could become objects in our program so we will need to create classes for these. However, all of these are also instances of the Instrument class as we have abstracted it. The Instrument class contains only those properties and methods that are common to all tradable instruments. In order to represent a futures contract in our program, we could create a new Futures class that inherits from the Instrument class. As such, the Futures class would inherit all the properties and methods from the base, or parent, Instrument class. The Futures class then may have some added properties or functionalities that are unique to futures contracts. Likewise, we could create an Option class that inherits from the Instrument class and has its own specific functionalities added on. A derived class can add functionality beyond that of the base class and it can also override methods of its base class, i. e. a derived class may replace a member function definition of the base class with its own new definition. It is important to note that Visual C provides for three types of classes references types, value types, and unmanged types and the abilities and intricasies of inheritance differ among the three types. As you will see, s common type system dictates that all reference types inherit from the base Object class Polymorphism Briefly, polymorphism allows us to have one method name, or function name, used in different derived classes, but yet have different implementations, or functionalities, associated with that name depending on the class. In a CallOption class and a PutOption class, for example, we may have inherited a BlackScholesPrice() method from the parent Option class, but yet each of the derived classes has their own method for calculation, as the equations for Black Scholes call and put pricing are different Memory Management in In, there are four memory spaces managed and unmanaged stacks and managed and unmanaged heaps.

No comments:

Post a Comment