Skip to main content

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


تجارة خوارزمية في R تعليمي.


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


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


خلفية.


في عام 2018، بدأت الاستثمار قليلا في الولاء 3. خدمتهم غير عادية ومكان عظيم لبدء رحلة الاستثمار الخاص. بدلا من توجيه الاتهام للمستثمر في الصفقات، الموالين 3 يتهم الشركات على قائمة على منصة. الفرضية هي أن الناس الذين يحبون خدمة company'Ђ ™ سوف أيضا شراء الأسهم وفي القيام بذلك تصبح قوية المدافعين عن العلامة التجارية. جعل المنصة أكثر إقناعا هو أنه يمكنك شراء أسهم كسور. لذلك، يمكنك الحصول على أن 800 $ الأمازون الأسهم فقط 10 $ وشراء آخر 10 $ الكسور في كل مرة لديك قليلا من النقود الإضافية في نهاية الشهر. بالتأكيد هناك تكاليف الاحتكاك منذ لديك للتداول في ويندوز ومحفظة كامل الخاص بك يقتصر على.


70 أسهم ولكن loyal3 يمثل وسيلة ممتعة ومنخفضة التكلفة لاستكشاف التدريب على الإنصاف. يمكنك وضع الجلد الحقيقي في اللعبة لمدة لا تقل عن 10 $!


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


الأسهم المتاحة في الولاء 3.


إعداد مساحة العمل الخاصة بك.


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


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


بعد ذلك، تر هي الحزمة التي بدأت للتو لاستكشاف. يتم استخدام المكتبة لبناء Ђњ قواعد التداول الفنية Ђќ. على الرغم من أنك سوف تتعلم ألغو التداول بسيطة في هذا المنصب، حزمة تر يمكن أن تؤدي العمليات الحسابية أكثر تطورا ويستحق التعلم.


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


جمع البيانات.


يتم إدراج جميع الأسهم الموالية 3 في صفحة واحدة. قبل أن تتمكن من البحث عن أسعار الأسهم اليومية الفردية لبناء خوارزمية التداول الخاص بك، تحتاج إلى جمع كل ما تبذلونه من المخزون ستوكر المتاحة. أول شيء يجب القيام به هو إعلان stock. list كسلسلة ورل. استخدم التالي read_html () بحيث تقوم جلسة R بإنشاء جلسة إنترنت وجمع كل معلومات هتمل على الصفحة كمجموعة عقدة شمل. تحتوي صفحة كس على معرف يسمى “pany-nameЂќЂќ. استخدم هذا كمعلمة عند استدعاء html_nodes () لتحديد بيانات شمل المرتبطة بهذه العقدة فقط. وأخيرا، استخدم html_text () بحيث يتم جمع قيم النص الفعلية لأسماء الشركة.


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


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


باستخدام html_nodes () على الأسهم، يمكنك سحب كافة العقد ملحوظ مع “a. ” في هتمل & لوت؛ a & غ؛ علامة الارتباط التشعبي الذي يستخدم لربط نموذج صفحة واحدة إلى أخرى. ضمن علامة الارتباط التشعبي، يشير “hrefв to إلى عنوان ورل الدقيق. لذا سوف يستخرج html_attr () عنوان ورل لكل الروابط الموجودة في الصفحة إذا كنت تمر في “href”.


بعد القيام ببعض التفتيش اليدوي، وجدت 54 إلى 123rd الروابط على الصفحة تمثل صفحات الشركة أحتاج من أجل كشط المعلومات شريط. يستخدم السطر الأخير paste0 () لتوصيل سلسلة عنوان ورل الأساسي †™ loyal3` إلى صفحات الشركة المحددة، مثل “ / WALMART”. على سبيل المثال، loyal3 / والمارت:


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


داخل صفحة ويب company' s s هناك جدول يسمى “ticker-price”. ستنتقل الدالة إلى صفحة شركة، وتحدد الجدول المناسب، وتستخرج النص باستخدام html_text (). وأخيرا، باستخدام سوب () جنبا إلى جنب مع التعبير العادي ^ ([[: ألفا:]] *). * و \\ 1 سوف تحتفظ بجميع الأحرف الأبجدية. والنتيجة هي أن أي أحرف خاصة، مثل $، وأية أحرف رقمية، مثل سعر الإغلاق، تتم إزالة. كما يقرأ وظيفة كل من 70 صفحة، فإنه سيتم جمع فقط شريط الأسهم.


صفحة الأسهم 3 ل علي بابا، حيث ترى الجدول الذي يحتوي على شريط الأسهم، ™ بابا، هو أقل من النص عريض.


المسلحة مع وظيفة مخصصة الخاص بك، استخدام بلابلي () لتطبيقه على كل من stock. links التي تحتوي على كل صفحة companyЂЂ ™ ق. الكائن الناتج، stock. tickers، هو قائمة من الأوراق المالية الفردية مع كل عنصر المقابلة لشركة فردية.


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


لكي تكون متسقة في تحليلك، قد ترغب في تحديد مقدار المعلومات التاريخية التي تجمعها على كل سهم. ستقوم الدالة Sys. Data () بتخزين عنصر تاريخ كسنة وشهر ثم يوم. استخدام سنوات مع عدد صحيح هو طريقة واحدة لطرح كمية معينة من الوقت من كائن start. date.


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


الدالة تر () جيتياهوداتا () تقبل رمز الأسهم، وتاريخ البدء والانتهاء. ترجع الدالة إطار بيانات يحتوي على معلومات سلسلة زمنية. كل صف هو تاريخ والأعمدة تحتوي على معلومات مثل سعر “Open”، “High”، “Low” و “Closingв for للأسهم. منذ كنت تبحث عن شركات متعددة، يمكنك استخدام لابلي () أو بلابلي (). تمر في ناقلات رموز الشركة، ثم وظيفة، جيتياهوداتا ()، ومن ثم معلومات التاريخ. يتم إعادة تدوير الكائنات التاريخ المعلمات في كل مرة يتم تطبيق جيتياهوداتا () على رمز السهم.


لجعل اختيار قائمة عاد، stock. ts، وأسهل للتنقل يمكنك إضافة أسماء إلى عناصر القائمة. استخدام أسماء مع الكائن stock. ts تعلن أسماء كمتجه رمز الأصلي $.


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


فحص بيانات المخزون.


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


المؤامرة السابقة هي ثابتة وغير مثيرة جدا للاهتمام.


استخدام مكتبة جافا سكريبت لجعل الرسم البياني يمكنك استكشاف. في مقتطف الشفرة هذا، قد تلاحظ عامل التشغيل Ђњ٪ & غ؛٪ ” أو الأنبوب. مشغل الأنابيب هو وسيلة جيدة لكتابة رمز موجزة. فإنه يحيل كائن إلى الدالة التالية دون إجبارك على إعادة كتابة اسم كائن كما فعلت في وقت سابق في هذا المنصب.


في هذا المثال، يمكنك إنشاء ديغراف يشير إلى الأسهم تويتر، $ توتر، ثم العمود الذي تريد مؤامرة، $ إغلاق. داخل ديغراف، يضيف الرئيسي عنوان الذي تم تحديده بين علامات الاقتباس. باستخدام “٪ & غ؛٪ ” يتم إعادة توجيه هذا الكائن بأكمله إلى الدالة التالية ديرانجيسليكتور (). يمكنك تحديد نطاق تاريخ افتراضي باستخدام c () مع سلسلة تاريخ البدء والنهاية. كائن هتمل الناتج هو سلسلة زمنية ديناميكية لمخزون Twitter†™ مع شريط تمرير التاريخ في الأسفل.


تذكر، لتغيير الأسهم المعروضة، تغيير رمز شريط في قائمة stock. ts ثم عنوان الرسم البياني.


هذا هو ديغراف الأساسية لمخزون Twitter†™ ل.


استراتيجية التداول بسيطة: الاتجاه التالي.


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


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


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


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


تقبل الدالة المخصصة mov. avgs () إطار بيانات مخزون واحد لحساب المتوسطات المتحركة. السطر الأول يختار أسعار الإغلاق لأنه فهرسة [، 4] لإنشاء stock. close. بعد ذلك، تستخدم الدالة إفيلز للتحقق من عدد الصفوف في إطار البيانات. على وجه التحديد إذا كان نرو في إطار البيانات أقل من (2 * 260)، ثم وظيفة إنشاء إطار بيانات من المتوسطات المتحركة مع “NA”.


لقد اخترت هذا الرقم لأن هناك حوالي 250 أيام التداول في السنة لذلك هذا سوف تحقق من أن سلسلة زمنية حوالي 2 سنوات أو أكثر في الطول. يمكن لويال 3 في بعض الأحيان الحصول على الاكتتابات العامة وإذا كان الأسهم العامة الجديدة لن تكون هناك بيانات كافية لمتوسط ​​المتحرك 200 يوم. ومع ذلك، إذا كانت قيمة نرو أكبر من 2 * 260 ثم وظيفة إنشاء إطار بيانات مع البيانات الأصلية جنبا إلى جنب مع 200 و 50 يوم المتوسطات المتحركة كأعمدة جديدة. باستخدام الأسماء، أعلن أسماء الأعمدة. يستخدم الجزء الأخير من الدالة كومبليت. يتم التحقق من القيم في العمود المتوسط ​​المتحرك ل 200 يوم. يتم إسقاط أية صفوف لا تحتوي على قيمة في النتيجة النهائية.


المسلحة مع هذه الوظيفة mov. avgs () يمكنك استخدام بلابلي () لإضافة حسابات المتوسط ​​المتحرك إلى كل من إطارات البيانات 70.


استخدم الرمز أدناه لتصور المتوسطات المتحركة StockЂ s ™ باستخدام ديغراف. مرة أخرى، يستخدم هذا الرمز عامل التشغيل “٪ & غ؛٪ в to لإعادة توجيه الكائنات. و ديغراف () وظيفة يقبل الأسهم. $ فوكس إطار البيانات. على وجه التحديد، يتم فهرسة إطار البيانات حسب اسم العمود مع c ('sma_200'، 'sma_50'). يتم تمرير هذا الكائن إلى ديسريز () في السطرين التاليين. يمكنك الرجوع إلى عمود بالاسم حتى ديسيريز () كل مؤامرة سطر للقيم “sma_50” و “sma_200в in في السطرين 2 و 3. يتم إعادة توجيه هذا الكائن مرة أخرى إلى ديرانجيسليكتور () لضبط ارتفاع المحدد. وأخيرا، أضفت بعض التظليل لتحديد فترات عندما كنت ترغب في شراء أو الاحتفاظ الأسهم وفترة عندما كنت قد باعت أسهمك أو بقي بعيدا اعتمادا على موقفكم.


هنا هي النتيجة النهائية في سلسلة زمنية تفاعلية.


المتوسطات المتحركة فوكس مع المناطق المظللة لشراء / عقد مقابل بيع.


استنتاج.


كما المتداول الخوارزمية الناشئة، لا تحتاج إلى مؤامرة جميع 70 سهم. بدلا من ذلك، كنت ترغب في تشغيل التعليمات البرمجية كل يوم وإضافة طريقة برنامجية لتحديد الأسهم التي تناسب الطريقة القائمة على القاعدة، “buy إذا كان المتوسط ​​المتحرك لمدة 50 يوم فوق المتوسط ​​المتحرك ل 200 يومЂќЂќ. كما كنت مراجعة الرسم البياني السابق، القسم الأخضر هو الوقت الذي كنت شراء الأسهم فوكس. يمثل القسم الأحمر الوقت لبيع أسهمك وعدم إعادة الدخول.


نظرا لأن الرسم البياني تفاعلي، يمكنك استخدام شريط التمرير لتغيير حجم العنصر المرئي. وبناء على هذا النهج التداول ألغو بسيط، والآن قد يكون وقتا طيبا لشراء فوكس! كان 30 ديسمبر 2018 يوم تداول حيث تحرك المتوسط ​​المتحرك ل 50 يوم 0.01 دولار أعلى من المتوسط ​​المتحرك ل 200 يوم!


قسم التكبير من فوكس الأسهم.


وبطبيعة الحال، تذكر جميع الاستثمارات يمكن أن تفقد القيمة. لمعرفة المزيد عن التمويل والتداول ألغو، В تحقق من الدورات DataCamp†™ ل هنا.


و التاجر R.


استخدام R والأدوات ذات الصلة في التمويل الكمي.


أرتشيف فور & # 8216؛ ترادينغ ستراتيجيس & # 8217؛ الفئة.


ربط R إلى إقفيد مع حزمة كوانتولس.


يوفر إقفيد تدفق خدمات البيانات والحلول التجارية التي تغطي السوق الزراعي والطاقة والمالية. بل هو معروف ومعترف به مزود تغذية البيانات الموجهة نحو مستخدمي التجزئة والمؤسسات الصغيرة. يبدأ سعر الاشتراك في حوالي 80 $ / الشهر.


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


كوانتولس يقدم أربع وظائف رئيسية هي: الحصول على بيانات السوق، مخزن / استرداد بيانات السوق، مؤامرة البيانات سلسلة الوقت والاختبار مرة أخرى.


تأكد أولا من أن إقفيد مفتوح. يمكنك إما تحميل البيانات اليومية أو خلال اليوم. أدناه رمز التنزيلات الأسعار اليومية (المفتوحة، عالية، منخفضة، إغلاق) ل سبي من 1 يناير 2017 إلى 1 يونيو 2017.


أدناه رمز التنزيلات البيانات اللحظية من 1 مايو 2017 إلى 3 مايو 2017.


لاحظ معلمة الفترة. يمكن أن تأخذ أي من القيم التالية: القراد، 1min، 5min، 10min، 15min، 30min، ساعة، يوم، أسبوع، شهر، اعتمادا على التردد الذي تحتاجه.


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


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


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


لاحظ أن القراد فقط معتمد في التخزين المحلي لذلك يجب أن تكون الفترة & # 8216؛ علامة & # 8217؛


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


أمران أن نلاحظ: الجاسوس الأول هو كائن data. table وبالتالي بناء الجملة أعلاه. للحصول على لمحة سريعة عن قدرات data. table لها نظرة على هذه الورقة الغش ممتازة من داتاكامب. ثانيا المعلمة المحلية ترو كما يتم استرجاع البيانات من وحدة التخزين الداخلية.


كوانتولس يسمح لكتابة استراتيجية التداول الخاصة بك باستخدام C ++ أبي. أنا & # 8217؛ م لن نتحدث عن هذا لأن هذا هو أساسا C ++ التعليمات البرمجية. يمكنك الرجوع إلى قسم الأمثلة على موقع كوانتولس.


عموما أجد حزمة مفيدة للغاية وموثقة بشكل جيد. الشيء الوحيد المفقود هو تغذية حية بين R و إقفيد والتي سوف تجعل حزمة نهاية حقيقية لإنهاء الحل.


كالمعتاد أي تعليقات موضع ترحيب.


بيرت: الوافد الجديد في اتصال R إكسيل.


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


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


في هذا المنصب أنا & # 8217؛ م لن تظهر لك كيف R و إكسيل التفاعل عبر بيرت. هناك دروس جيدة جدا هنا، هنا وهنا. بدلا من ذلك أريد أن تظهر لك كيف استخدمت بيرت لبناء & # 8220؛ برج التحكم & # 8221؛ لتداول بلدي.


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


استخدم شمل لإنشاء قوائم وأزرار محددة من قبل المستخدم في ملف إكسيل. القوائم المذكورة أعلاه وأزرار هي أساسا يدعو إلى وظائف فبا. تلك الوظائف فبا هي التفاف حول وظائف R المعرفة باستخدام بيرت.


مع هذا النهج يمكنني الحفاظ على تمييز واضح بين جوهر بلدي رمز الاحتفاظ بها في R، سكل وبيثون وكل ما يستخدم لعرض وتنسيق النتائج أبقى في إكسيل، فبا & أمب؛ XML. في الأقسام التالية أقدم الشرط الأساسي لتطوير مثل هذا النهج ودليل خطوة بخطوة يوضح كيف يمكن استخدام بيرت لمجرد تمرير البيانات من R إلى إكسيل مع الحد الأدنى من التعليمات البرمجية فبا.


1 & # 8211؛ تحميل وتثبيت بيرت من هذا الرابط. بمجرد اكتمال التثبيت يجب أن يكون لديك قائمة الوظائف الإضافية الجديدة في إكسيل مع الأزرار كما هو موضح أدناه. هذه هي الطريقة التي تحققت بيرت في إكسيل.


2 & # 8211؛ تنزيل وتثبيت محرر واجهة مستخدم مخصص: يسمح محرر واجهة المستخدم المخصص بإنشاء قوائم وأزرار محددة من قبل المستخدم في شريط إكسيل. يتوفر إجراء خطوة بخطوة هنا.


1 & # 8211؛ R كود: وظيفة R أدناه هي قطعة بسيطة جدا من التعليمات البرمجية لأغراض التوضيح فقط. ويحسب ويعيد البقايا من الانحدار الخطي. هذا هو ما نريد استرداد في إكسيل. حفظ هذا في ملف يسمى myRCode. R (أي اسم آخر على ما يرام) في دليل من اختيارك.


2 & # 8211؛ functions. R في بيرت: من إكسيل حدد الوظائف الإضافية - & غ؛ الصفحة الرئيسية الدليل وفتح الملف يسمى functions. R. في هذا الملف قم بلصق التعليمة البرمجية التالية. تأكد من إدراج المسار الصحيح.


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


3 & # 8211؛ في إكسيل: إنشاء وحفظ ملف يسمى myFile. xslm (أي اسم آخر على ما يرام). هذا هو ملف تمكين ماكرو الذي تقوم بحفظه في الدليل الذي تختاره. مرة واحدة يتم حفظ الملف إغلاقه.


4 & # 8211؛ افتح الملف الذي تم إنشاؤه أعلاه في محرر واجهة المستخدم المخصصة: بعد فتح الملف، الصق الشفرة التالية.


يجب أن يكون لديك شيء من هذا القبيل في محرر شمل:


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


5 & ​​# 8211؛ فتح محرر فبا: في myFile. xlsm إدراج وحدة نمطية جديدة. قم بلصق التعليمة البرمجية أدناه في الوحدة النمطية التي تم إنشاؤها حديثا.


يؤدي ذلك إلى محو النتائج السابقة في ورقة العمل قبل التعامل مع نتائج جديدة.


6 & # 8211؛ انقر فوق زر جديد: الآن عد إلى جدول البيانات وفي القائمة رترادر ​​انقر فوق & # 8220؛ زر جديد & # 8221؛ زر. يجب أن تشاهد شيئا مثل ما يظهر أدناه.


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


استراتيجية التداول: الاستفادة القصوى من البيانات من العينة.


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


في الرسم البياني أدناه تمثل المنطقة الزرقاء خارج أداء العينة لأحد استراتيجياتي.


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


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


هنا الرمز المستخدم لإنشاء الرسم البياني أعلاه والتحليل:


في المثال أعلاه في فترة العينة أطول من خارج الفترة عينة ولذلك أنا عشوائيا إنشاء 1000 مجموعات فرعية من البيانات في العينة كل واحد لها نفس طول البيانات خارج العينة. ثم اختبرت كل عينة فرعية في مقابل عينة من البيانات وسجلت قيم p. هذه العملية لا تخلق قيمة P واحدة لاختبار كروسكال واليس ولكن التوزيع يجعل التحليل أكثر قوة. في هذا المثال يكون متوسط ​​قيم p أعلى بكثير من الصفر (0.478) مما يشير إلى أنه يجب قبول الفرضية الصفرية: فهناك أدلة قوية على أن البيانات داخل وخارج العينة تأتي من نفس التوزيع.


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


هذه المقالة مستوحاة من الورقتين التاليتين:


فيجيل ألكسندر، شميل سوان (2007)، "آثار وظائف التحسين المختلفة على الخروج من عينة أداء استراتيجيات التداول المتطورة وراثيا"، التنبؤ مؤتمر الأسواق المالية.


فيجيه أليكساندر، شميل سوان (2018)، "عملية التحسين لتحسين / الخروج من عينة الاتساق، حالة سوق الأسهم»، مؤتمر مورغان كازينوف الأسهم الكمية الكمية، لندن أكتوبر 2018.


تقديم فيدلر: فينانسيال داتا لوادير.


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


كيفية تثبيت واستخدام فيدلر؟


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


يتم التعامل مع رسائل الخطأ والتحذيرات من قبل الحزم الأساسية (كوانتمود و لامعة) ويمكن قراءتها من وحدة التحكم.


هذه هي النسخة الأولى جدا من المشروع لذلك لا نتوقع الكمال ولكن نأمل أنه سوف تتحسن مع مرور الوقت. يرجى الإبلاغ عن أي تعليق، اقتراح، علة الخ & # 8230؛ تو: ثيرترادر ​​@ غميل.


الحفاظ على قاعدة بيانات لملفات الأسعار في R.


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


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


1 & # 8211؛ تحميل البيانات الأولية (listOfInstruments. R & historyData. R)


ملف listOfInstruments. R هو ملف يحتوي فقط على قائمة بجميع الصكوك.


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


2 & # 8211؛ تحديث البيانات الموجودة (updateData. R)


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


3 & # 8211؛ إنشاء ملف دفعي (updateDailyPrices. bat)


جزء مهم آخر من المهمة هو إنشاء ملف دفعي يقوم بأتمتة عملية التحديث أعلاه (I & # 8217؛ م مستخدم ويندوز). هذا يتجنب فتح R / رستوديو وتشغيل التعليمات البرمجية من هناك. يتم وضع التعليمات البرمجية أدناه على ملف بت. (يجب تعديل المسار مع إعداد القارئ & # 8217؛ s). لاحظ أنني أضفت ملف الإخراج (updateLog. txt) لتتبع التنفيذ.


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


كالمعتاد أي تعليقات موضع ترحيب.


تقييم العوامل في إدارة الحافظة الكمية.


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


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


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


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


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


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


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


جميع الأسهم في مؤشر S & أمب؛ P500 (في وقت كتابة هذا التقرير). ومن الواضح أن هناك تحيز سفينة البقاء على قيد الحياة: قائمة الأسهم في المؤشر قد تغيرت بشكل ملحوظ بين بداية ونهاية الفترة العينة، ومع ذلك انها جيدة بما فيه الكفاية لأغراض التوضيح فقط.


ينزل الرمز أدناه أسعار الأسهم الفردية في مؤشر S & أمب؛ P500 بين يناير / كانون الثاني 2005 واليوم (يستغرق الأمر بعض الوقت) ويتحول إلى أسعار الخام خلال الأشهر ال 12 الماضية والشهر الماضي. الأول هو عاملنا، وسيتم استخدام هذا الأخير كمقياس العودة إلى الأمام.


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


وأخيرا رمز لإنتاج الرسم البياني كوانتيز ريتورن.


3 & # 8211؛ كيفية استغلال المعلومات أعلاه؟


في الرسم البياني أعلاه Q1 هو أدنى 12 شهرا الماضية عودة و Q5 أعلى. هناك زيادة رتيبة تقريبا في العائد الكمي بين Q1 و Q5 مما يشير بوضوح إلى أن الأسهم التي تندرج في Q5 تفوق تلك التي تندرج في الربع الأول بنحو 1٪ شهريا. هذا مهم جدا وقوي لمثل هذا عامل بسيط (ليس حقا مفاجأة على الرغم من & # 8230؛). لذلك هناك فرص أكبر للتغلب على المؤشر من خلال زيادة الوزن للأسهم المتساقطة في Q5 وتخفيض الوزن لتلك التي تقع في الربع الأول بالنسبة إلى المؤشر المعياري.


إيك من 0.0206 قد لا يعني الكثير في حد ذاته لكنه يختلف كثيرا عن 0 ويشير إلى قوة تنبؤية جيدة من الأشهر ال 12 الماضية يعود عموما. يمكن تقييم اختبارات الأهمية الرسمية ولكن هذا خارج نطاق هذه المقالة.


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


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


وأخيرا، أنا & # 8217؛ م دهشتها ما يمكن تحقيقه في أقل من 80 سطر من التعليمات البرمجية مع R & # 8230؛


كالمعتاد أي تعليقات موضع ترحيب.


المخاطر ك & # 8220؛ بقاء متغير & # 8221؛


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


اسمحوا أولا & # 8217؛ ق أقول لديك بداية سيئة وتخسر ​​المال في البداية. مع سحب 10٪ كنت & # 8217؛ بالتأكيد بالتأكيد ولكن حتى مع انخفاض 5٪ فرص رؤية تخصيصك مخفضة مرتفعة جدا. هذا له آثار كبيرة على استراتيجياتك. دعنا نفترض أنه إذا فقدت 5٪ يتم تقسيم التخصيص إلى 2 وتعود إلى التخصيص الأولي فقط عند اجتياز علامة المياه المرتفعة مرة أخرى (على سبيل المثال، يعود السحب إلى 0). في الرسم البياني أدناه أنا محاكاة التجربة مع واحدة من استراتيجيات بلدي.


يمكنك البدء في التداول في 1 يونيو 2003 وكل يسير على ما يرام حتى 23 يوليو 2003 حيث يصل منحنى السحب الخاص بك -5٪ عتبة (** 1 **). يتم تخفيض تخصيصك بنسبة 50٪ وأنت لا تعبر ارتفاع مستوى علامة المياه حتى 05 ديسمبر 2003 (** 3 **). إذا كنت قد أبقت على التخصيص دون تغيير، فإن مستوى علامة المياه العالية كان قد عبرت في 28 أكتوبر 2003 (** ** **) وبحلول نهاية العام كنت قد كسبت المزيد من المال.


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


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


كالمعتاد أي تعليقات موضع ترحيب.


والتطبيق بسيط لامعة لرصد استراتيجيات التداول & # 8211؛ الجزء الثاني.


هذا هو متابعة لبلدي وظيفة السابقة & # 8220؛ بسيطة لامعة التطبيق لرصد استراتيجيات التداول & # 8220؛. لقد أضفت بعض التحسينات التي تجعل التطبيق أفضل قليلا (على الأقل بالنسبة لي!). وفيما يلي قائمة الميزات الجديدة:


نموذج ملف كسف. (الملف الذي يحتوي على البيانات الأولية) A & # 8220؛ إنديت & # 8221؛ مربع المنسدلة السماح لتحديد نهاية الفترة. A & # 8220؛ ريسك & # 8221؛ صفحة تحتوي على تحليل فار ورسم بياني لأسوأ أداء على آفاق مختلفة A & # 8220؛ هاو تو & # 8221؛ صفحة شرح كيفية استخدام وتخصيص التطبيق للاحتياجات الفردية.


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


1 & # 8211؛ كيفية تثبيت & أمب؛ تشغيل التطبيق على جهاز الكمبيوتر الخاص بك.


إنشاء مجلد معين بفك ضغط ملف. zip على هذا المجلد الجديد. تغيير مسارات في ملف رونشينياب لمطابقة الإعدادات الخاصة بك لتشغيل التطبيق، لديك فقط تشغيل الملف run. vbs. أنا أيضا شملت رمز (RTraderTradingApp. ico) إذا كنت ترغب في إنشاء اختصار على سطح المكتب الخاص بك.


ui. R: يتحكم في تخطيط ومظهر من server. R التطبيق: يحتوي على التعليمات اللازمة لبناء التطبيق. يمكنك تحميل استراتيجيات بقدر ما تريد طالما ملف كسف المقابلة لديه الشكل الصحيح (انظر أدناه). shinyStrategyGeneral. R: تحميل حزم المطلوبة ويطلق التطبيق.


3 & # 8211؛ كيفية إضافة استراتيجية التداول؟


إنشاء ملف. csv المقابل في الدليل الصحيح إنشاء إدخال جديد في وظيفة رد الفعل البيانات (داخل ملف server. R) إضافة عنصر إضافي إلى معلمة الاختيار في أول سيليتينبوت في الشريط الجانبي بانيل (داخل ملف ui. R) . يجب أن يتطابق اسم العنصر مع اسم الإدخال الجديد أعلاه.


إزالة الإدخال في وظيفة رد الفعل البيانات المقابلة للاستراتيجية التي تريد إزالتها (داخل ملف server. R) إزالة العنصر في المعلمة الاختيار في أول سيليتينبوت في الشريط الجانبي بانيل المقابلة للاستراتيجية التي تريد إزالتها (داخل واجهة المستخدم. R).


لا تتردد في الحصول على اتصال يجب أن يكون لديك أي اقتراح.


والتطبيق لامعة بسيطة لرصد استراتيجيات التداول.


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


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


الرمز المستخدم في هذا المنصب متوفر على مستودع جيست / جيثوب. هناك أساسا 3 ملفات.


ui. R: يتحكم في تخطيط ومظهر التطبيق. server. R: يحتوي على التعليمات اللازمة لبناء التطبيق. فإنه يقوم بتحميل البيانات وتنسيقه. هناك ملف كسف واحد لكل إستراتيجية تحتوي كل منها على عمودين على الأقل: التاريخ والعودة بالتنسيق التالي: (& # 8220؛ 2018-12-22 & # 8243؛، & # 8221؛ 0.04٪ & # 8221؛). يمكنك تحميل استراتيجيات بقدر ما تريد طالما لديهم التنسيق الصحيح. shinyStrategyG Eneral. R: تحميل حزم المطلوبة ويطلق التطبيق.


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


شكرا جزيلا لفريق رستوديو / لامعة لمثل هذه الأداة العظيمة.


استخدام الخوارزميات الجينية في التداول الكمي.


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


ما هي الخوارزميات الجينية؟


أفضل وصف غا أنا جاء عبر يأتي من سايبرناتيك تجارة كتاب من قبل موراي A. روجيرو. & غ؛ خوارزميات جينية تم اختراعها من قبل جون هولاند في منتصف 1970 لحل مشاكل التحسين الصعب. يستخدم هذا الأسلوب الانتقاء الطبيعي، والبقاء للأصلح & # 8221؛. وتتبع العملية العامة الخطوات التالية:


ترميز المشكلة في الكروموسومات باستخدام الترميز، تطوير وظيفة اللياقة البدنية لاستخدامها في تقييم كل قيمة كروموسوم & # 8217؛ s في حل مشكلة معينة تهيئة السكان من الكروموسومات تقييم كل كروموسوم في السكان إنشاء كروموسومات جديدة عن طريق التزاوج اثنين من الكروموسومات. ويتم ذلك عن طريق كتم وإعادة ربط اثنين من الآباء والأمهات لتشكيل طفلين (يتم اختيار الآباء عشوائيا ولكن منحازة من قبل لياقتهم) تقييم الكروموسوم الجديد حذف عضو من السكان الذي هو أقل ملاءمة من الكروموسوم الجديد وإدراج كروموسوم جديد في السكان . If the stop criteria is reached (maximum number of generations, fitness criteria is good enough…) then return the best chromosome alternatively go to step 4.


From a trading perspective GA are very useful because they are good at dealing with highly nonlinear problems. However they exhibit some nasty features that are worth mentioning:


Over fitting: This is the main problem and it’s down to the analyst to set up the problem in a way that minimises this risk. Computing time : If the problem isn’t properly defined, it can be extremely long to reach a decent solution and the complexity increases exponentially with the number of variables. Hence the necessity to carefully select the parameters.


There are several R packages dealing with GA, I chose to use the most common one: rgenoud.


Daily closing prices for most liquid ETFs from Yahoo finance going back to January 2000. The in sample period goes from January 2000 to December 2018. The Out of sample period starts on January 2018.


The logic is as following: the fitness function is optimised over the in sample period to obtain a set of optimal parameters for the selected technical indicators. The performance of those indicators is then evaluated in the out of sample period. But before doing so the technical indicators have to be selected.


The equity market exhibits two main characteristics that are familiar to anyone with some trading experience. Long term momentum and short term reversal. Those features can be translated in term of technical indicators by: moving averages cross over and RSI. This represents a set of 4 parameters: Look-back periods for long and short term moving averages, look-back period for RSI and RSI threshold. The sets of parameters are the chromosomes . The other key element is the fitness function . We might want to use something like: maximum return or Sharpe ratio or minimum average Drawdown. In what follows, I chose to maximise the Sharpe ratio.


The R implementation is a set of 3 functions:


fitnessFunction : defines the fitness function (e. g., maximum Sharpe ratio) to be used within the GA engine tradingStatistics : summary of trading statistics for the in and out of sample periods for comparison purposes genoud : the GA engine from the rgenoud package.


The genoud function is rather complex but I’m not going to explain what each parameter means as I want to keep this post short (and the documentation is really good).


In the table below I present for each instrument the optimal parameters (RSI look-back period, RSI threshold, Short Term Moving Average, and Long Term Moving Average) along with the in and out of sample trading statistics.


Before commenting the above results, I want to explain a few important points. To match the logic defined above, I bounded the parameters to make sure the look-back period for the long term moving average is always longer that the shorter moving average. I also constrained the optimiser to choose only the solutions with more than 50 trades in the in sample period (e. g;, statistical significance).


Overall the out of sample results are far from impressive. The returns are low even if the number of trades is small to make the outcome really significant. However there’s a significant loss of efficiency between in and out of sample period for Japan (EWJ) which very likely means over fitting.


This post is intended to give the reader the tools to properly use GA in a quantitative trading framework. Once again, It’s just an example that needs to be further refined. A few potential improvement to explore would be:


fitness function : maximising the Sharpe ratio is very simplistic. A “smarter” function would certainly improve the out of sample trading statistics pattern : we try to capture a very straightforward pattern. A more in depth pattern research is definitely needed. optimisation : there are many ways to improve the way the optimisation is conducted. This would improve both the computation speed and the rationality of the results.


The code used in this post is available on a Gist repository.


جيكو كوانت - التداول الكمي.


التداول الكمي، التحكيم الإحصائي، تعلم الآلة والخيارات الثنائية.


Category Archives: R Code.


آخر الملاحة.


RNeat – Square Root Neural Net trained using Augmenting Topologies – Simple Example.


A simple tutorial demonstrating how to train a neural network to square root numbers using a genetic algorithm that searches through the topological structure space. The algorithm is called NEAT (Neuro Evolution of Augmenting Topologies) available in the RNeat package (not yet on CRAN).


The training is very similar to other machine learning / regression packages in R. The training function takes a data frame and a formula. The formula is used to specify what columns in the data frame are the dependent variables and which are the explanatory variable. The code is commented and should be simple enough for new R users.


The performance of the network can be seen in the bottom left chart of the image above, there is considerable differences between the expected output and the actual output. It is likely that with more training the magnitude of these errors will reduce, it can be seen in the bottom right chart that the maximum, mean and median fitness are generally increasing with each generation.


Inverted Pendulum Simulation in R.


This post will derive the equations of motion and simulate the classic inverted pendulum control problem. Subsequent posts will apply machine learning to figure out how to control the pendulum and keep it up in the air.


A video of the simulation can be found at:


The derivation of the maths follows the approach outlined in the following video, however I have decided to model the friction between the cart and track.


Free body diagram of cart.


Free body diagram of pendulum.


Resolve the forces on the free body diagrams and set equal to their acceleration.


Definition of e co-ordinate system.


The acceleration of the pendulum is the acceleration of the cart plus the acceleration of the pendulum relative to the cart.


Convert the co-ordinate system back into the and components.


Substitute the accelerations into equation (1) and (2)


It is undesirable to have an unknown tension T so eliminate using a trick.


Substitute equation (1) into equation (0)


Rearranging equation (6) and (5) gives the system equations in known measurable variables.


Both the acceleration terms and depend on each other which is undesirable, substitute the equation for into the equation for to remove the dependency.


The system can then be simulated using Euler update equations:


Animation in R – Bouncing Ball Simulation.


This post fill focus on how to create an animation to visualise the simulation of a physical system, in this case a bouncing ball. Whilst this post is unrelated to trading it will form the basis of future articles. In my next post I will show how to simulate the classic pole balancing / inverted pendulum problem. Machine learning will then be applied to develop a control system for the dynamic systems.


A video of the simulation is below:


The R package “animation” has been used to create videos of the simulated process. This package requires that FFMpeg is installed on your machine and added to your environmental path. To learn how to add items to your path follow this tutorial at Geeks With Blogs.


The code below demonstrated how to generate a video:


ani. width is the width of the video ani. height is the height of the video other. opts are command line arguments that are passed to ffmpeg and can be used to control the bitrate and other quality settings interval specifies in seconds how long to wait between frames runSimulationFunc() is a function that should run your simulation, and charts plotted during the simulation will be added to the video.


I have written some functions to make drawing basic graphics easy.


createSceneFunc(bottomLeftX, bottomLeftY, width, height) creates a brand new scene to draw objects on, bottomLeftX and bottomLeftY are Cartesian co-ordinates to specify the bottom left corner of the canvas. The width and height variables are used to specify the canvas dimensions. createBoxFunc(topLeftX, topLeftY, width, height, fillColour) draws a box to the current canvas, topLeftX and topLeftY specify the Cartesian co-ordinate of the top left of the box, width and height specify the dimensions and fillColour specifies the colour that fills in the box. createCircleFunc(centerX, centerY, radius, fillColour) draws a circle to the current canvas, centerX and centerY specify the Cartesian co-ordinate of the center on the circle, the radius specifies the radius of the circle and fillColour specifies the colour that fills in the circle.


The following single period update equations are used:


When a collision is made between the ball and the platform the following update is used:


High Probability Credit Spreads – Using Linear Regression Curves.


I came across this video series over the weekend, an option trader discusses how he trades credit spreads (mainly looks for mean reversion). Most of you will be familiar with bollinger bands as a common mean reversion strategy, essentially you take the moving average and moving standard deviation of the stock. You then plot on to your chart the moving average and an upper and lower band(moving average +/- n*standard deviations).


It is assumed that the price will revert to the moving average hence any price move to the bands is a good entry point. A common problem with this strategy is that the moving average is a LAGGING indicator and is often very slow to track the price moves if a long lookback period is used.


Video 1 presents a technique called “linear regression curves” about 10mins in. Linear regression curves aim to solve the problem of the moving average being slow to track the price.


Linear Regression Curve vs Simple Moving Average.


See how tightly the blue linear regression curve follows the close price, it’s significantly quicker to identify turns in the market where as the simple moving average has considerable tracking error. The MSE could be taken to quantify the tightness.


How to calculate the linear regression curve:


In this example you have 100 closing prices for your given stock. Bar 1 is the oldest price, bar 100 is the most recent price. We will use a 20day regression.


1. Take prices 1-20 and draw the line of best fit through them.


2. At the end of your best fit line (so bar 20), draw a little circle.


3. Take prices 2-21 and draw the line of best fit through them.


4. At the end of your best fit line (so bar 21) draw a little circle.


5. Repeat upto bar 100.


6. Join all of your little circles, this is your ‘linear regression curve’


So in a nutshell you just join the ends of a rolling linear regression.


Parameter Optimisation & Backtesting – الجزء 2.


The code presented here will aim to optimise a strategy based upon the simple moving average indicator. The strategy will go Long when moving average A > moving average B. The optimisation is to determine what period to make each of the moving averages A & ب.


Please note that this isn’t intended to be a good strategy, it is merely here to give an example of how to optimise a parameter.


TradingStrategy this function implements the trading logic and calculates the returns RunIterativeStrategy this function iterates through possible parameter combinations and calls TradingStrategy for each new parameter set CalculatePerformanceMetric takes in a table of returns (from RunIterativeStrategy) and runs a function/metric over each set of returns. PerformanceTable calls CalculatePerformanceMetric for lots of different metric and compiles the results into a table OrderPerformanceTable lets us order the performance table by a given metric, ie order by highest sharpe ratio SelectTopNStrategies selects the best N strategies for a specified performance metric (charts. PerformanceSummary can only plot.


20 strategies, hence this function to select a sample) FindOptimumStrategy does what it says on the tin.


QuantStrat TradeR.


Trading, QuantStrat, R, and more.


Which Implied Volatility Ratio Is Best?


This post will be about comparing a volatility signal using three different variations of implied volatility indices to predict when to enter a short volatility position.


In volatility trading, there are three separate implied volatility indices that have a somewhat long history for trading–the VIX (everyone knows this one), the VXV (more recently changed to be called the VIX3M), which is like the VIX, except for a three-month period), and the VXMT, which is the implied six-month volatility period.


This relationship gives investigation into three separate implied volatility ratios: VIX/VIX3M (aka VXV), VIX/VXMT, and VIX3M/VXMT, as predictors for entering a short (or long) volatility position.


So, let’s get the data.


One quick strategy to investigate is simple–the idea that the ratio should be below 1 (I. E. contango in implied volatility term structure) and decreasing (below a moving average). So when the ratio will be below 1 (that is, with longer-term implied volatility greater than shorter-term), and the ratio will be below its 60-day moving average, the strategy will take a position in XIV.


Here’s the code to do that.


With the following performance:


In other words, the VIX3M/VXMT sports the lowest drawdowns (by a large margin) with higher returns.


So, when people talk about which implied volatility ratio to use, I think this offers some strong evidence for the longer-out horizon as a predictor for which implied vol term structure to use. It’s also why it forms the basis of my subscription strategy.


شكرا للقراءة.


NOTE: I am currently seeking a full-time position (remote or in the northeast U. S.) related to my skill set demonstrated on this blog. Please message me on LinkedIn if you know of any opportunities which may benefit from my skill set.


Replicating Volatility ETN Returns From CBOE Futures.


This post will demonstrate how to replicate the volatility ETNs (XIV, VXX, ZIV, VXZ) from CBOE futures, thereby allowing any individual to create synthetic ETF returns from before their inception, free of cost.


So, before I get to the actual algorithm, it depends on an update to the term structure algorithm I shared some months back.


In that algorithm, mistakenly (or for the purpose of simplicity), I used calendar days as the time to expiry, when it should have been business days, which also accounts for weekends, and holidays, which are an irritating artifact to keep track of.


So here’s the salient change, in the loop that calculates times to expiry:


The one salient line in particular, is this:


What is this bizdays function? It comes from the bizdays package in R.


There’s also the tradingHolidays. R script, which makes further use of the bizdays package. Here’s what goes on under the hood in tradingHolidays. R, for those that wish to replicate the code:


There are two CSVs that I manually compiled, but will share screenshots of–they are the easter holidays (because they have to be adjusted for turning Sunday to Friday because of Easter Fridays), and the rest of the national holidays.


Here is what the easters csv looks like:


And the nonEasterHolidays, which contains New Year’s Day, MLK Jr. Day, President’s Day, Memorial Day, Independence Day, Labor Day, Thanksgiving Day, and Christmas Day (along with their observed dates) CSV:


Furthermore, we need to adjust for the two days that equities were not trading due to Hurricane Sandy.


So then, the list of holidays looks like this:


So once we have a list of holidays, we use the bizdays package to set the holidays and weekends (Saturday and Sunday) as our non-business days, and use that function to calculate the correct times to expiry.


So, now that we have the updated expiry structure, we can write a function that will correctly replicate the four main volatility ETNs–XIV, VXX, ZIV, and VXZ.


Here’s the English explanation:


VXX is made up of two contracts–the front month, and the back month, and has a certain number of trading days (AKA business days) that it trades until expiry, say, 17. During that timeframe, the front month (let’s call it M1) goes from being the entire allocation of funds, to being none of the allocation of funds, as the front month contract approaches expiry. That is, as a contract approaches expiry, the second contract gradually receives more and more weight, until, at expiry of the front month contract, the second month contract contains all of the funds–just as it *becomes* the front month contract. So, say you have 17 days to expiry on the front month. At the expiry of the previous contract, the second month will have a weight of 17/17–100%, as it becomes the front month. Then, the next day, that contract, now the front month, will have a weight of 16/17 at settle, then 15/17, and so on. That numerator is called dr, and the denominator is called dt.


However, beyond this, there’s a second mechanism that’s responsible for the VXX looking like it does as compared to a basic futures contract (that is, the decay responsible for short volatility’s profits), and that is the “instantaneous” rebalancing. That is, the returns for a given day are today’s settles multiplied by yesterday’s weights, over yesterday’s settles multiplied by yesterday’s weights, minus one. That is, (S_1_t * dr/dt_t-1 + S_2_t * 1-dr/dt_t-1) / (S_1_t-1 * dr/dt_t-1 + S_2_t-1 * 1-dr/dt_t-1) – 1 (I could use a tutorial on LaTeX). So, when you move forward a day, well, tomorrow, today’s weights become t-1. Yet, when were the assets able to be rebalanced? Well, in the ETNs such as VXX and VXZ, the “hand-waving” is that it happens instantaneously. That is, the weight for the front month was 93%, the return was realized at settlement (that is, from settle to settle), and immediately after that return was realized, the front month’s weight shifts from 93%, to, say, 88%. So, say Credit Suisse (that issues these ETNs ), has $10,000 (just to keep the arithmetic and number of zeroes tolerable, obviously there are a lot more in reality) worth of XIV outstanding after immediately realizing returns, it will sell $500 of its $9300 in the front month, and immediately move them to the second month, so it will immediately go from $9300 in M1 and $700 in M2 to $8800 in M1 and $1200 in M2. When did those $500 move? Immediately, instantaneously, and if you like, you can apply Clarke’s Third Law and call it “magically”.


The only exception is the day after roll day, in which the second month simply becomes the front month as the previous front month expires, so what was a 100% weight on the second month will now be a 100% weight on the front month, so there’s some extra code that needs to be written to make that distinction.


That’s the way it works for VXX and XIV. What’s the difference for VXZ and ZIV? It’s really simple–instead of M1 and M2, VXZ uses the exact same weightings (that is, the time remaining on front month vs. how many days exist for that contract to be the front month), uses M4, M5, M6, and M7, with M4 taking dr/dt, M5 and M6 always being 1, and M7 being 1-dr/dt.


In any case, here’s the code.


So, a big thank you goes out to Michael Kapler of Systematic Investor Toolbox for originally doing the replication and providing his code. My code essentially does the same thing, in, hopefully a more commented way.


So, ultimately, does it work? Well, using my updated term structure code, I can test that.


While I’m not going to paste my entire term structure code (again, available here, just update the script with my updates from this post), here’s how you’d run the new function:


And since it returns both the vxx returns and the vxz returns, we can compare them both.


With the result:


Basically, a perfect match.


Let’s do the same thing, with ZIV.


So, rebuilding from the futures does a tiny bit better than the ETN. But the trajectory is largely identical.


That concludes this post. I hope it has shed some light on how these volatility ETNs work, and how to obtain them directly from the futures data published by the CBOE, which are the inputs to my term structure algorithm.


This also means that for institutions interested in trading my strategy, that they can obtain leverage to trade the futures-composite replicated variants of these ETNs, at greater volume.


شكرا للقراءة.


NOTES: For those interested in a retail subscription strategy to trading volatility, do not hesitate to subscribe to my volatility-trading strategy. For those interested in employing me full-time or for long-term consulting projects, I can be reached on my LinkedIn, or my email: ilya. kipnis@gmail.


(Don’t Get) Contangled Up In Noise.


This post will be about investigating the efficacy of contango as a volatility trading signal.


For those that trade volatility (like me), a term you may see that’s somewhat ubiquitous is the term “contango”. What does this term mean?


Well, simple: it just means the ratio of the second month of VIX futures over the first. The idea being is that when the second month of futures is more than the first, that people’s outlook for volatility is greater in the future than it is for the present, and therefore, the futures are “in contango”, which is most of the time.


Furthermore, those that try to find decent volatility trading ideas may have often seen that futures in contango implies that holding a short volatility position will be profitable.


Is this the case?


Well, there’s an easy way to answer that.


First off, refer back to my post on obtaining free futures data from the CBOE.


Using this data, we can obtain our signal (that is, in order to run the code in this post, run the code in that post).


Now, let’s get our XIV data (again, big thanks to Mr. Helmuth Vollmeier for so kindly providing it.


Now, here’s how this works: as the CBOE doesn’t update its settles until around 9:45 AM EST on the day after (EG a Tuesday’s settle data won’t release until Wednesday at 9:45 AM EST), we have to enter at close of the day after the signal fires. (For those wondering, my subscription strategy uses this mechanism, giving subscribers ample time to execute throughout the day.)


So, let’s calculate our backtest returns. Here’s a stratStats function to compute some summary statistics.


With the following results:


So, this is obviously a disaster. Visual inspection will show devastating, multi-year drawdowns. Using the table. Drawdowns command, we can view the worst ones.


So, the top 3 are horrendous, and then anything above 30% is still pretty awful. A couple of those drawdowns lasted multiple years as well, with a massive length to the trough. 458 trading days is nearly two years, and 364 is about one and a half years. Imagine seeing a strategy be consistently on the wrong side of the trade for nearly two years, and when all is said and done, you’ve lost three-fourths of everything in that strategy.


There’s no sugar-coating this: such a strategy can only be called utter trash.


Let’s try one modification: we’ll require both contango (C2 > C1), and that contango be above its 60-day simple moving average, similar to my VXV/VXMT strategy.


With the results:


So, a Calmar still safely below 1, an Ulcer Performance Index still in the basement, a maximum drawdown that’s long past the point that people will have abandoned the strategy, and so on.


So, even though it was improved, it’s still safe to say this strategy doesn’t perform too well. Even after the large 2007-2008 drawdown, it still gets some things pretty badly wrong, like being exposed to all of August 2017.


While I think there are applications to contango in volatility investing, I don’t think its use is in generating the long/short volatility signal on its own. Rather, I think other indices and sources of data do a better job of that. Such as the VXV/VXMT, which has since been iterated on to form my subscription strategy.


شكرا للقراءة.


NOTE: I am currently seeking networking opportunities, long-term projects, and full-time positions related to my skill set. My linkedIn profile can be found here.


Comparing Some Strategies from Easy Volatility Investing, and the Table. Drawdowns Command.


This post will be about comparing strategies from the paper “Easy Volatility Investing”, along with a demonstration of R’s table. Drawdowns command.


First off, before going further, while I think the execution assumptions found in EVI don’t lend the strategies well to actual live trading (although their risk/reward tradeoffs also leave a lot of room for improvement), I think these strategies are great as benchmarks.


So, some time ago, I did an out-of-sample test for one of the strategies found in EVI, which can be found here.


Using the same source of data, I also obtained data for SPY (though, again, AlphaVantage can also provide this service for free for those that don’t use Quandl).


Here’s the new code.


So, an explanation: there are four return streams here–buy and hold XIV, the DDN momentum from a previous post, and two other strategies.


The simpler one, called the VRatio is simply the ratio of the VIX over the VXV. Near the close, check this quantity. If this is less than one, buy XIV, otherwise, buy VXX.


The other one, called the Volatility Risk Premium strategy (or VRP for short), compares the 10 day historical volatility (that is, the annualized running ten day standard deviation) of the S&P 500, subtracts it from the VIX, and takes a 5 day moving average of that. Near the close, when that’s above zero (that is, VIX is higher than historical volatility), go long XIV, otherwise, go long VXX.


Again, all of these strategies are effectively “observe near/at the close, buy at the close”, so are useful for demonstration purposes, though not for implementation purposes on any large account without incurring market impact.


Here are the results, since 2018 (that is, around the time of XIV’s actual inception):


To note, both the momentum and the VRP strategy underperform buying and holding XIV since 2018. The VRatio strategy, on the other hand, does outperform.


Here’s a summary statistics function that compiles some top-level performance metrics.


To note, all of the benchmark strategies suffered very large drawdowns since XIV’s inception, which we can examine using the table. Drawdowns command, as seen below:


Note that the table. Drawdowns command only examines one return stream at a time. Furthermore, the top argument specifies how many drawdowns to look at, sorted by greatest drawdown first.


One reason I think that these strategies seem to suffer the drawdowns they do is that they’re either all-in on one asset, or its exact opposite, with no room for error.


One last thing, for the curious, here is the comparison with my strategy since 2018 (essentially XIV inception) benchmarked against the strategies in EVI (which I have been trading with live capital since September, and have recently opened a subscription service for):


شكرا للقراءة.


NOTE: I am currently looking for networking and full-time opportunities related to my skill set. My LinkedIn profile can be found here.


Launching My Subscription Service.


After gauging interest from my readers, I’ve decided to open up a subscription service. I’ll copy and paste the FAQs, or my best attempt at trying to answer as many questions as possible ahead of time, and may answer more in the future.


I’m choosing to use Patreon just to outsource all of the technicalities of handling subscriptions and creating a centralized source to post subscription-based content.


FAQs (copied from the subscription page):


Thank you for visiting. After gauging interest from my readership on my main site (quantstrattrader. wordpress), I created this as a subscription page for quantitative investment strategies, with the goal of having subscribers turn their cash into more cash, net of subscription fees (hopefully). The systems I develop come from a background of learning from experienced quantitative trading professionals, and senior researchers at large firms. The current system I initially published a prototype for several years back and watched it being tracked, before finally starting to deploy my own capital earlier this year, and making the most recent modifications even more recently.


And while past performance doesn’t guarantee future results and the past doesn’t repeat itself, it often rhymes, so let’s turn money into more money.


Some FAQs about the strategy:


​What is the subscription price for this strategy?


​Currently, after gauging interest from readers and doing research based on other sites, the tentative pricing is $50/month. As this strategy builds a track record, that may be subject to change in the future, and notifications will be made in such an event.


What is the description of the strategy?


The strategy is mainly a short volatility system that trades XIV, ZIV, and VXX. As far as volatility strategies go, it’s fairly conservative in that it uses several different checks in order to ensure a position.


What is the strategy’s edge?


In two words: risk management. Essentially, there are a few separate criteria to select an investment, and the system spends a not-insignificant time with no exposure when some of these criteria provide contradictory signals. Furthermore, the system uses disciplined methodologies in its construction in order to avoid unnecessary free parameters, and to keep the strategy as parsimonious as possible.


Do you trade your own capital with this strategy?


When was the in-sample training period for this system?


A site that no longer updates its blog (volatility made simple) once tracked a more rudimentary strategy that I wrote about several years ago. I was particularly pleased with the results of that vetting, and recently have received input to improve my system to a much greater degree, as well as gained the confidence to invest live capital into it.


How many trades per year does the system make?


In the backtest from April 20, 2008 through the end of 2018, the system made 187 transactions in XIV (both buy and sell), 160 in ZIV, and 52 in VXX. Meaning over the course of approximately 9 years, there was on average 43 transactions per year. In some cases, this may simply be switching from XIV to ZIV or vice versa. In other words, trades last approximately a week (some may be longer, some shorter).


When will signals be posted?


Signals will be posted sometime between 12 PM and market close (4 PM EST). In backtesting, they are tested as market on close orders, so individuals assume any risk/reward by executing earlier.


How often is this system in the market?


About 56%. However, over the course of backtesting (and live trading), only about 9% of months have zero return.


What are the distribution of winning, losing, and zero return months?


As of late October 2017, there have been about 65% winning months (with an average gain of 12.8%), 26% losing months (with an average loss of 4.9%), and 9% zero months.


What are some other statistics about the strategy?


Since 2018 (around the time that XIV officially came into inception as opposed to using synthetic data), the strategy has boasted an 82% annualized return, with a 24.8% maximum drawdown and an annualized standard deviation of 35%. This means a Sharpe ratio (return to standard deviation) higher than 2, and a Calmar ratio higher than 3. It also has an Ulcer Performance Index of 10.


What are the strategy’s worst drawdowns?


Since 2018 (again, around the time of XIV’s inception), the largest drawdown was 24.8%, starting on October 31, 2018, and making a new equity high on January 12, 2018. The longest drawdown started on August 21, 2018 and recovered on April 10, 2018, and lasted for 160 trading days.


Will the subscription price change in the future?


If the strategy continues to deliver strong returns, then there may be reason to increase the price so long as the returns bear it out.


Can a conservative risk signal be provided for those who might not be able to tolerate a 25% drawdown?


A variant of the strategy that targets about half of the annualized standard deviation of the strategy boasts a 40% annualized return for about 12% drawdown since 2018. Overall, this has slightly higher reward to risk statistics, but at the cost of cutting aggregate returns in half.


Can’t XIV have a termination event?


This refers to the idea of the XIV ETN terminating if it loses 80% of its value in a single day. To give an idea of the likelihood of this event, using synthetic data, the XIV ETN had a massive drawdown of 92% over the course of the 2008 financial crisis. For the history of that synthetic (pre-inception) and realized (post-inception) data, the absolute worst day was a down day of 26.8%. To note, the strategy was not in XIV during that day.


What was the strategy’s worst day?


On September 16, 2018, the strategy lost 16% in one day. This was at the tail end of a stretch of positive days that made about 40%.


What are the strategy’s risks?


The first risk is that given that this strategy is naturally biased towards short volatility, that it can have potential for some sharp drawdowns due to the nature of volatility spikes. The other risk is that given that this strategy sometimes spends its time in ZIV, that it will underperform XIV on some good days. This second risk is a consequence of additional layers of risk management in the strategy.


How complex is this strategy?


Not overly. It’s only slightly more complex than a basic momentum strategy when counting free parameters, and can be explained in a couple of minutes.


Does this strategy use any complex machine learning methodologies?


No. The data requirements for such algorithms and the noise in the financial world make it very risky to apply these methodologies, and research as of yet did not bear fruit to justify incorporating them.


Will instrument volume ever be a concern (particularly ZIV)?


According to one individual who worked on the creation of the original VXX ETN (and by extension, its inverse, XIV), new shares of ETNs can be created by the issuer (in ZIV’s case, Credit Suisse) on demand. In short, the concern of volume is more of a concern of the reputability of the person making the request. In other words, it depends on how well the strategy does.


Can the strategy be held liable/accountable/responsible for a subscriber’s loss/drawdown?


​Let this serve as a disclaimer: by subscribing, you agree to waive any legal claim against the strategy, or its creator(s) in the event of drawdowns, losses, etc. The subscription is for viewing the output of a program, and this service does not actively manage a penny of subscribers’ actual assets. Subscribers can choose to ignore the strategy’s signals at a moment’s notice at their discretion. The program’s output should not be thought of as the investment advice coming from a CFP, CFA, RIA, etc.


Why should these signals be trusted?


Because my work on other topics has been on full, public display for several years. Unlike other websites, I have shown “bad backtests”, thus breaking the adage of “you’ll never see a bad backtest”. I have shown thoroughness in my research, and the same thoroughness has been applied towards this system as well. Until there is a longer track record such that the system can stand on its own, the trust in the system is the trust in the system’s creator.


Who is the intended audience for these signals?


The intended audience is individual, retail investors with a certain risk tolerance, and is priced accordingly.


​Isn’t volatility investing very risky?


​It’s risky from the perspective of the underlying instrument having the capacity to realize very large drawdowns (greater than 60%, and even greater than 90%). However, from a purely numerical standpoint, the company taking over so much of shopping, Amazon, since inception has had a 37.1% annualized rate of return, a standard deviation of 61.5%, a worst drawdown of 94%, and an Ulcer Performance Index of 0.9. By comparison, XIV, from 2008 (using synthetic data), has had a 35.5% annualized rate of return, a standard deviation of 57.7%, a worst drawdown of 92%, and an Ulcer Performance Index of 0.6. If Amazon is considered a top-notch asset, then from a quantitative comparison, a system looking to capitalize on volatility bets should be viewed from a similar perspective. To be sure, the strategy’s performance vastly outperforms that of buying and holding XIV (which nobody should do). However, the philosophy of volatility products being much riskier than household tech names just does not hold true unless the future wildly differs from the past.


​Is there a possibility for collaborating with other strategy creators?


​Feel free to contact me at my email ilya. kipnis@gmail to discuss that possibility. I request a daily stream of returns before starting any discussion.


Because past all the artsy-craftsy window dressing and interesting choice of vocabulary, Patreon is simply a platform that processes payments and creates a centralized platform from which to post subscription-based content, as opposed to maintaining mailing lists and other technical headaches. Essentially, it’s simply a way to outsource the technical end of running a business, even if the window dressing is a bit unorthodox.


شكرا للقراءة.


NOTE: I am currently interested in networking and full-time roles based on my skills. My LinkedIn profile can be found here.


The Return of Free Data and Possible Volatility Trading Subscription.


This post will be about pulling free data from AlphaVantage, and gauging interest for a volatility trading subscription service.


So first off, ever since the yahoos at Yahoo decided to turn off their free data, the world of free daily data has been in somewhat of a dark age. Well, thanks to blog. fosstrading/2017/10/getsymbols-and-alpha-vantage. html#gpluscommentsJosh Ulrich, Paul Teetor, and other R/Finance individuals, the latest edition of quantmod (which can be installed from CRAN) now contains a way to get free financial data from AlphaVantage since the year 2000, which is usually enough for most backtests, as that date predates the inception of most ETFs.


Here’s how to do it.


Once you do that, downloading data is simple, if not slightly slow. Here’s how to do it.


And the results:


Which means if any one of my old posts on asset allocation has been somewhat defunct thanks to bad yahoo data, it will now work again with a slight modification to the data input algorithms.


Beyond demonstrating this routine, one other thing I’d like to do is to gauge interest for a volatility signal subscription service, for a system I have personally started trading a couple of months ago.


Simply, I have seen other websites with subscription services with worse risk/reward than the strategy I currently trade, which switches between XIV, ZIV, and VXX. Currently, the equity curve, in log 10, looks like this:


That is, $1000 in 2008 would have become approximately $1,000,000 today, if one was able to trade this strategy since then.


Since 2018 (around the time of inception for XIV), the performance has been:


Considering that some websites out there charge upwards of $50 a month for either a single tactical asset rotation strategy (and a lot more for a combination) with inferior risk/return profiles, or a volatility strategy that may have had a massive and historically record-breaking drawdown, I was hoping to gauge a price point for what readers would consider paying for signals from a better strategy than those.


شكرا للقراءة.


NOTE: I am currently interested in networking and am seeking full-time opportunities related to my skill set. My LinkedIn profile can be found here.


The Kelly Criterion — Does It Work?


This post will be about implementing and investigating the running Kelly Criterion — that is, a constantly adjusted Kelly Criterion that changes as a strategy realizes returns.


For those not familiar with the Kelly Criterion, it’s the idea of adjusting a bet size to maximize a strategy’s long term growth rate. Both https://en. wikipedia/wiki/Kelly_criterionWikipedia and Investopedia have entries on the Kelly Criterion. Essentially, it’s about maximizing your long-run expectation of a betting system, by sizing bets higher when the edge is higher, and vice versa.


There are two formulations for the Kelly criterion: the Wikipedia result presents it as mean over sigma squared. The Investopedia definition is P-[(1-P)/winLossRatio], where P is the probability of a winning bet, and the winLossRatio is the average win over the average loss.


In any case, here are the two implementations.


Let’s try this with some data. At this point in time, I’m going to show a non-replicable volatility strategy that I currently trade.


For the record, here are its statistics:


Now, let’s see what the Wikipedia version does:


The results are simply ridiculous. And here would be why: say you have a mean return of .0005 per day (5 bps/day), and a standard deviation equal to that (that is, a Sharpe ratio of 1). You would have 1/.0005 = 2000. In other words, a leverage of 2000 times. This clearly makes no sense.


The other variant is the more particular Investopedia definition.


Looks a bit more reasonable. However, how does it stack up against not using it at all?


Turns out, the fabled Kelly Criterion doesn’t really change things all that much.


For the record, here are the statistical comparisons:


شكرا للقراءة.


NOTE: I am currently looking for my next full-time opportunity, preferably in New York City or Philadelphia relating to the skills I have demonstrated on this blog. My LinkedIn profile can be found here. If you know of such opportunities, do not hesitate to reach out to me.


Leverage Up When You’re Down?


This post will investigate the idea of reducing leverage when drawdowns are small, and increasing leverage as losses accumulate. It’s based on the idea that whatever goes up must come down, and whatever comes down generally goes back up.


I originally came across this idea from this blog post.


So, first off, let’s write an easy function that allows replication of this idea. Essentially, we have several arguments:


One: the default leverage (that is, when your drawdown is zero, what’s your exposure)? For reference, in the original post, it’s 10%.


Next: the various leverage levels. In the original post, the leverage levels are 25%, 50%, and 100%.


And lastly, we need the corresponding thresholds at which to apply those leverage levels. In the original post, those levels are 20%, 40%, and 55%.


So, now we can create a function to implement that in R. The idea being that we have R compute the drawdowns, and then use that information to determine leverage levels as precisely and frequently as possible.


Here’s a quick piece of code to do so:


So, let’s replicate some results.


And our results look something like this:


That said, what would happen if one were to extend the data for all available XIV data?


A different story.


In this case, I think the takeaway is that such a mechanism does well when the drawdowns for the benchmark in question occur sharply, so that the lower exposure protects from those sharp drawdowns, and then the benchmark spends much of the time in a recovery mode, so that the increased exposure has time to earn outsized returns, and then draws down again. When the benchmark continues to see drawdowns after maximum leverage is reached, or continues to perform well when not in drawdown, such a mechanism falls behind quickly.


As always, there is no free lunch when it comes to drawdowns, as trying to lower exposure in preparation for a correction will necessarily mean forfeiting a painful amount of upside in the good times, at least as presented in the original post.


شكرا للقراءة.


NOTE: I am currently looking for my next full-time opportunity, preferably in New York City or Philadelphia relating to the skills I have demonstrated on this blog. My LinkedIn profile can be found here. If you know of such opportunities, do not hesitate to reach out to me.


Let’s Talk Drawdowns (And Affiliates)


This post will be directed towards those newer in investing, with an explanation of drawdowns–in my opinion, a simple and highly important risk statistic.


Would you invest in this?


As it turns out, millions of people do, and did. That is the S&P 500, from 2000 through 2018, more colloquially referred to as “the stock market”. Plenty of people around the world invest in it, and for a risk to reward payoff that is very bad, in my opinion. This is an investment that, in ten years, lost half of its value–twice!


At its simplest, an investment–placing your money in an asset like a stock, a savings account, and so on, instead of spending it, has two things you need to look at.


First, what’s your reward? If you open up a bank CD, you might be fortunate to get 3%. If you invest it in the stock market, you might get 8% per year (on average) if you held it for 20 years. In other words, you stow away $100 on January 1st, and you might come back and find $108 in your account on December 31st. This is often called the compound annualized growth rate (CAGR)–meaning that if you have $100 one year, earn 8%, you have 108, and then earn 8% on that, and so on.


The second thing to look at is the risk. What can you lose? The simplest answer to this is “the maximum drawdown”. If this sounds complicated, it simply means “the biggest loss”. So, if you had $100 one month, $120 next month, and $90 the month after that, your maximum drawdown (that is, your maximum loss) would be 1 – 90/120 = 25%.


When you put the reward and risk together, you can create a ratio, to see how your rewards and risks line up. This is called a Calmar ratio, and you get it by dividing your CAGR by your maximum drawdown. The Calmar Ratio is a ratio that I interpret as “for every dollar you lose in your investment’s worst performance, how many dollars can you make back in a year?” For my own investments, I prefer this number to be at least 1, and know of a strategy for which that number is above 2 since 2018, or higher than 3 if simulated back to 2008.


Most stocks don’t even have a Calmar ratio of 1, which means that on average, an investment makes more than it can possibly lose in a year. Even Amazon, the company whose stock made Jeff Bezos now the richest man in the world, only has a Calmar Ratio of less than 2/5, with a maximum loss of more than 90% in the dot-com crash. The S&P 500, again, “the stock market”, since 1993, has a Calmar Ratio of around 1/6. That is, the worst losses can take *years* to make back.


A lot of wealth advisers like to say that they recommend a large holding of stocks for young people. In my opinion, whether you’re young or old, losing half of everything hurts, and there are much better ways to make money than to simply buy and hold a collection of stocks.


For those with coding skills, one way to gauge just how good or bad an investment is, is this:


An investment has a history–that is, in January, it made 3%, in February, it lost 2%, in March, it made 5%, and so on. By shuffling that history around, so that say, January loses 2%, February makes 5%, and March makes 3%, you can create an alternate history of the investment. It will start and end in the same place, but the journey will be different. For investments that have existed for a few years, it is possible to create many different histories, and compare the Calmar ratio of the original investment to its shuffled “alternate histories”. Ideally, you want the investment to be ranked among the highest possible ways to have made the money it did.


To put it simply: would you rather fall one inch a thousand times, or fall a thousand inches once? Well, the first one is no different than jumping rope. The second one will kill you.


Here is some code I wrote in R (if you don’t code in R, don’t worry) to see just how the S&P 500 (the stock market) did compared to how it could have done.


This is the resulting plot:


That red line is the actual performance of the S&P 500 compared to what could have been. And of the 1000 different simulations, only 91 did worse than what happened in reality.


This means that the stock market isn’t a particularly good investment, and that you can do much better using tactical asset allocation strategies.


One site I’m affiliated with, is AllocateSmartly. It is a cheap investment subscription service ($30 a month) that compiles a collection of asset allocation strategies that perform better than many wealth advisers. When you combine some of those strategies, the performance is better still. To put it into perspective, one model strategy I’ve come up with has this performance:


In this case, the compound annualized growth rate is nearly double that of the maximum loss. For those interested in something a bit more aggressive, this strategy ensemble uses some fairly conservative strategies in its approach.


In conclusion, when considering how to invest your money, keep in mind both the reward, and the risk. One very simple and important way to understand risk is how much an investment can possibly lose, from its highest, to its lowest value following that peak. When you combine the reward and the risk, you can get a ratio that tells you about how much you can stand to make for every dollar lost in an investment’s worst performance.


شكرا للقراءة.


NOTE: I am interested in networking opportunities, projects, and full-time positions related to my skill set. If you are looking to collaborate, please contact me on my LinkedIn here.


An Out of Sample Update on DDN’s Volatility Momentum Trading Strategy and Beta Convexity.


The first part of this post is a quick update on Tony Cooper’s of Double Digit Numerics’s volatility ETN momentum strategy from the volatility made simple blog (which has stopped updating as of a year and a half ago). The second part will cover Dr. Jonathan Kinlay’s Beta Convexity concept.


So, now that I have the ability to generate a term structure and constant expiry contracts, I decided to revisit some of the strategies on Volatility Made Simple and see if any of them are any good (long story short: all of the publicly detailed ones aren’t so hot besides mine–they either have a massive drawdown in-sample around the time of the crisis, or a massive drawdown out-of-sample).


Why this strategy? Because it seemed different from most of the usual term structure ratio trades (of which mine is an example), so I thought I’d check out how it did since its first publishing date, and because it’s rather easy to understand.


Here’s the strategy:


Take XIV, VXX, ZIV, VXZ, and SHY (this last one as the “risk free” asset), and at the close, invest in whichever has had the highest 83 day momentum (this was the result of optimization done on volatilityMadeSimple).


Here’s the code to do this in R, using the Quandl EOD database. There are two variants tested–observe the close, buy the close (AKA magical thinking), and observe the close, buy tomorrow’s close.


إليك النتائج.


Looks like this strategy didn’t pan out too well. Just a daily reminder that if you’re using fine grid-search to select a particularly good parameter (EG n = 83 days? Maybe 4 21-day trading months, but even that would have been n = 82), you’re asking for a visit from, in the words of Mr. Tony Cooper, a visit from the grim reaper.


Moving onto another topic, whenever Dr. Jonathan Kinlay posts something that I think I can replicate that I’d be very wise to do so, as he is a very skilled and experienced practitioner (and also includes me on his blogroll).


A topic that Dr. Kinlay covered is the idea of beta convexity–namely, that an asset’s beta to a benchmark may be different when the benchmark is up as compared to when it’s down. Essentially, it’s the idea that we want to weed out firms that are what I’d deem as “losers in disguise”–I. E. those that act fine when times are good (which is when we really don’t care about diversification, since everything is going up anyway), but do nothing during bad times.


The beta convexity is calculated quite simply: it’s the beta of an asset to a benchmark when the benchmark has a positive return, minus the beta of an asset to a benchmark when the benchmark has a negative return, then squaring the difference. That is, (beta_bench_positive – beta_bench_negative) ^ 2.


Here’s some R code to demonstrate this, using IBM vs. the S&P 500 since 1995.


شكرا للقراءة.


NOTE: I am always looking to network, and am currently actively looking for full-time opportunities which may benefit from my skill set. If you have a position which may benefit from my skills, do not hesitate to reach out to me. My LinkedIn profile can be found here.


مثال لاستراتيجية تداول مشفرة باستخدام حزمة كوانتمود في R.


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


الحصول على البيانات التاريخية صياغة استراتيجية التداول وتحديد القواعد تنفيذ الاستراتيجية على البيانات التاريخية تقييم مقاييس الأداء.


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


يوفر كوانتمود ميزات مختلفة لتصور البيانات. الأمر أدناه يخلق الرسم البياني للبيانات نس.


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


الأمر أدناه يحسب ماسد لسعر الإغلاق.


يمكن للمرء أن يختار المعلمات المتغيرة لمعدلات سريعة وبطيئة والإشارة اعتمادا على متطلبات التداول. هنا نحن التمسك المعايير القياسية. ماسد هو الدالة في كوانتمود التي تحسب تباعد التقارب المتوسط ​​المتحرك، البيانات هي سعر إغلاق نس، نفاست هو المتوسط ​​المتحرك السريع، نسلو هو المتوسط ​​المتحرك البطيء، ماتب = سما يشير إلى أننا اخترنا المتوسط ​​المتحرك البسيط، النسبة المئوية = فالس يعني أننا نحسب الفرق بين المتوسط ​​المتحرك السريع والمتوسط ​​البطيء للحركة. سيؤدي تعيين ترو إلى إعادة الفرق بين المتوسط ​​المتحرك السريع والمتوسط ​​المتحرك البطيء.


يقوم الأمر التالي بتخطيط المخطط لسعر إغلاق نس مع معلمات ماسد.


كما نوقش قبل أن نحدد إشارة التداول لدينا على النحو التالي: -


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


يؤدي الأمر التالي إلى إنشاء إشارة التداول وفقا لذلك. نحن نستخدم عامل التأخر للقضاء على نظرة التحيز قدما.


سيغنال = لاغ (إفيلز (ماسد $ ماسد & لوت؛ ماسد $ سيغنال، -1، 1))


سنطبق هذه الاستراتيجية على البيانات التاريخية لل نس من 2007-09-17 إلى 2018-09-22. يتم تطبيق إشارة التداول على سعر الإغلاق للحصول على عوائد إستراتيجيتنا.


وتوفر وظيفة روك النسبة المئوية للفرق بين سعري الإقفال. يمكننا اختيار المدة التي نريد أن نرى العوائد. يختار الأمر التالي العوائد بين 2008-06-02 و 2018-09-22.


يمكن حساب العوائد التراكمية ورسمها باستخدام الأوامر التالية: -


والخطوة الرابعة من الاختبار الخلفي هي تقييم مقاييس الأداء. توفر حزمة تحليلات الأداء في R منصة موحدة لمراقبة المعلمات المتعلقة بالأداء. ويمكن ملاحظة العديد من المقاييس مثل السحب، والمخاطر الهبوطية في R.


يوفر الأمر التالي ملخص المعلمات المذكورة أعلاه وأكثر من ذلك بكثير!


هنا هو نسخة موجزة من التعليمات البرمجية.


ماسد = ماسد (داتا، نفاست = 12، نسلو = 26، نسيغ = 9، ماتيب = سما، بيرسنت = فالس)


سيغنال = لاغ (إفيلز (ماسد $ ماسد & لوت؛ ماسد $ سيغنال، -1، 1))


بعد الذهاب على الرغم من هذا المثال، كنت & # 8217؛ تعلمت أساسيات كيفية تصميم استراتيجية التداول الكمي باستخدام R. الآن يمكنك البدء في تعلم كيفية البدء مع حزمة كوانتمود في R. مرة واحدة كنت & # 8217؛ لقد تعلمت بنجاح هذه الأساسيات يمكنك اختبار المهارات الخاصة بك في لدينا التفاعلية 10 ساعة طويلة داتاكامب بالطبع "نموذج استراتيجية التداول الكمي في R '


الوظائف ذات الصلة:


فكر واحد على "مثال لاستراتيجية التداول مشفرة باستخدام حزمة كوانتمود في R"


20 ديسمبر 2018.


لقد نفذت R النصي أعلاه وأنها مؤامرة لي الرسوم البيانية 3 ولكن كيفية تفسيرها.

Comments

Popular posts from this blog

أعلى 10 وسطاء الفوركس المملكة المتحدة

العثور على أفضل وسيط فوركس بالنسبة لك. قارن 36 حسابات تداول العملات الأجنبية والعروض في مكان واحد. أحدث عروض الفوركس: أحدث ندوات الفوركس: أدلة الفوركس الشائعة: وسطاء متميزون. يناير '18. حساب إتورو. تداول 50 زوج من العملات، الأسهم الشعبية، المؤشرات، الذهب والفضة مع إتورو. الحصول على حرية وغير محدود إلى دورات التداول الفوركس وندوات عبر الإنترنت. الحساب القياسي. تداول الفوركس والعقود مقابل الفروقات على المعادن والسلع والمؤشرات على فروق ثابتة ثابتة من انخفاض $ 100 وديعة على MT4. سلخ فروة الرأس والتحوط ومستشاري الخبراء (إي). فكسرو كترادر. التجارة 69 أزواج العملات والمؤشرات الفورية، والطاقات والمعادن على انتشار الحلاقة رقيقة مع تنفيذ السوق. يتم دعم الروبوتات كترادر ​​على الرغم من كالغو. الحساب الإسلامي. الحساب الإسلامي مع عدم وجود رسوم مبادلة أو التمديد. تداول الفوركس والعقود مقابل الفروقات على المؤشرات والسلع والأسهم على MT4 من نقطة واحدة. قارن وسطاء. أفضل وسطاء MT5. ميتاتريدر 5 هو خلف ميتاتريدر 4، الأكثر شعبية في العالم منصة تداول العملات الأجنبية. قارن وسطاء MT5 الآن. وسطاء الفوركس مع...

استراتيجية التداول بسيطة باستخدام القوة النسبية

استراتيجية التداول بسيطة باستخدام القوة النسبية. استراتيجية التداول بسيطة باستخدام القوة النسبية. استراتيجية التداول بسيطة باستخدام القوة النسبية. كيفية التجارة إشاريس إتف - تداول الأسهم بسيطة. Оцените эффективность рекомендаций на демо-счете без малейшего риска! Надежные стратегии инвестиций. ارتفاع احتمال القوة النسبية التداول 140 صفحة، اكتشاف كيفية إجراء تحليل القطاع سريعة وبسيطة من أجل تحديد ما إذا كان الأسهم يستحق الشراء. ترادينغماركيتس | كيفية استخدام مؤشر القوة النسبية لمدة 2. مؤشر القوة النسبية لفترة 2 (رسي): يتم حساب النسبية كمتوسط ​​بسيط ل "مؤشر القوة النسبية الأعلى (رسي) | استراتيجية التداول. فوركس فاكتوري - نظام التداول باستخدام القوة النسبية. استخدام القوة النسبية لخلق استراتيجية تداول الأسهم مربحة. كيفية استخدام القوة النسبية لتحليل سوق الأسهم التقنية. إستراتيجية تداول بسيطة باستخدام القوة النسبية - يوتوب. إتف ترادينغ ستراتيجيس من قبل بوب • تشير الدلائل إلى أن استراتيجية الزخم فئة الأصول إتف بسيطة يدق على قدم المساواة "باستخدام تحليل القوة النسبية ل. مؤشر القوة ...

تكنيك أعلى قمة النقد الاجنبى

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