استراتيجيات التداول حسابي في r
تجارة خوارزمية مع دورة R.
R هو قوية جدا تعلم الآلة ولغة البرمجة لغة البرمجة.
وقد حصلت على R أكثر من 7000 الإحصائي، تعلم الآلة وحزم العلوم البيانات.
R مناسبة بشكل مثالي للقيام بالتعلم الآلي على مجموعة بيانات سلسلة زمنية مالية وجعل التنبؤات.
يتم تداول الخوارزميات اليوم ضد الخوارزميات.
هل تتذكر تحطم فلاش الجنيه البريطاني الذي حدث في العام الماضي؟
في أقل من دقيقة سقط غبوسد أكثر من 1000 نقطة محو العديد من حسابات التداول.
هل تعرف السبب؟ وكان سبب تحطم فلاش من خوارزمية المارقة.
أيام من التداول اليدوي تقترب من نهايتها.
إذا كنت تريد تريد يمكنك بسهولة معرفة R ومن ثم استخدامها في التداول الخاص بك.
منصات MT4 و MT5 تفتقر أي التعلم الآلي ومكتبات الذكاء الاصطناعي.
فمن مهمة شاقة لتطوير التعلم الآلي والذكاء الاصطناعي ل MT4 و MT5.
الحل يكمن في استخدام R وبيثون. كلاهما على قدم المساواة جيدة.
أعتقد R هو أفضل. بيثون تحاول استبدال R ولكن سوف لا تزال تأخذ بعض الوقت.
في هذه الدورة على التداول حسابي مع R، وأظهر لك كيف أنت ذاهب إلى استخدام واجهات برمجة التطبيقات المقدمة من قبل وسطاء مختلفة واستخدام R.
لقد جعلت كل شيء سهلا. نذهب خطوة خطوة وحتى لو كنت قد ترميز أبدا قبل أن تواجه أي مشكلة.
الميكانيكية الفوركس.
التداول في سوق الفوركس باستخدام استراتيجيات التداول الميكانيكية.
استخدام R في التداول الخوارزمي: إعادة اختبار استراتيجية التعلم الآلي التي يعيد التدريب كل يوم.
على آخر مشاركة بو لدينا ذهبنا إلى عالم التعلم الآلي مع بناء نموذج بسيط آلة التعلم باستخدام جهاز ناقل الدعم لمحاولة التنبؤ العوائد اليومية لل أوب في R. В ومع ذلك فشل أو القدرة على التنبؤ بالعودة من سلسلة لا يدل على نجاح التداول الفعلي أو الفشل منذ عوائد التداول هي بوضوح ليست متجانسة (ليست كل أيام سيئة هي نفسها وليس كل أيام جيدة هي نفسها). وهذا يعني أنه يمكن أن يكون لديك تقنية التعلم الآلي التي لديها دقة منخفضة جدا (أقل من فرصة عشوائية) ولكن لا يزال يمكن أن يكون ناجحا إذا كان يميل إلى التنبؤ بشكل إيجابي الأيام التي لديها أعلى العوائد. عند استخدام استراتيجيات التعلم آلة للتداول أنها ليست مجرد مسألة ما هي النسبة المئوية من الوقت كنت & # 8217؛ الحق في / خطأ ولكن كم من المال تقوم به أو تفقد عند التجارة. وبسبب هذه الحقيقة يصبح من المهم جدا لاختبار نماذج لدينا ضمن الاختبار الفعلي الفعلي، حتى نتمكن من معرفة ما إذا كان لدينا آلة التعلم الآلي يعمل خوارزمية، في الممارسة العملية، عند التداول (على الأقل من منظور تاريخي). في اليوم & # 8217؛ s البرنامج التعليمي نحن & # 8217؛ الذهاب لمعرفة بالضبط كيفية القيام بذلك.
للقيام بما سبق سنكون بحاجة إلى حزم R التالية: e1071، كوانتمود و بيرفورمانساناليتيكش. لاحظ أنه يجب تحميل الحزم بالترتيب المحدد أعلاه، لأننا سنستخدم بعض الوظائف التي تم تعريفها على e1071 و بيرفورمانساناليتيكش ولكننا نريد وظائف بيرفورمانساناليتيكش (لذلك ستحصل على أخطاء إذا كنت تحميل بيرفورمانساناليتيكش أولا والروابط إلى أسماء وظيفة الحصول فوق الكتابة داخليا). اليوم نحن & # 8217؛ إعادة تشغيل اختبار الظهر على الذهب إتف (غلد)، في محاولة للتنبؤ به باستخدام سفم. سوف نموذج سفم لدينا إعادة التدريب على كل شريط باستخدام أشرطة X الماضية. أولا وقبل كل شيء، نقوم بتحميل المكتبات ثم نحصل على البيانات ل إتف غلد باستخدام الدالة كوزمود جيتسيمبولس. وبمجرد الانتهاء من ذلك سوف يتم استخدام وظيفة بسيطة تم إنشاؤها بواسطة هذا غيوي الذي يسمح لنا لإنشاء إطار البيانات التي تحتوي على جميع التنبؤات بطريقة منظمة جدا (أوصي تماما وظيفة مرتبطة من قبل، مما يدل على كيفية إنشاء / اختبار تصنيف نموذج باستخدام سفم على سبي). كما غيرت هذه الوظيفة أيضا لإرجاع عودة عادي من السلسلة حتى أستطيع تعيينه إلى مجموعة أخرى واستخدامها لاحقا للحصول على الربح / الخسارة للاستراتيجية. تحديد الوظيفة الأولى في R كما هو مفصل أدناه:
لاحظ أن الدالة تحدد 17 متنبؤا مختلفا نستخدمها كمدخلات للتنبؤ بمصنف ثنائي (1 صاعد، -1 هابط) سنستخدم عندئذ لتدريب سفم. لاحظ أيضا كيف تستفيد الدالة من الدالة روك ووظائف أخرى متجهة على أساس النواقل التي هي ترتيب حجم أكثر كفاءة من الحلقة التي شاركتها معك على آخر مشاركة. مرة واحدة يتم تعريف وظيفة يمكننا بعد ذلك ببساطة نسميها إلى بوبولاتك إطار بيانات تسمى & # 8220؛ البيانات & # 8221؛ . سنقوم بعد ذلك بإنشاء إطار بيانات يسمى & # 8220؛ يوميا & # 8221؛ وتعيينها العوائد اليومية، وبعد ذلك سوف نقوم بحذفها من مجموعة البيانات الرئيسية (لأن وجود العودة في صفيف التنبؤ يؤدي إلى التطفل).
بعد ذلك يمكننا الآن تشغيل الاختبار الخلفي لنظامنا. ما سنفعله أولا هو اختيار فترة التعلم (سيتم تدريب الخوارزمية مع عدد ليارنينغبيريود الماضي من الحانات)، ثم نقوم بإنشاء إطار بيانات فارغ يسمى & # 8220؛ النتائج & # 8221؛ حيث سنقوم بحفظ العائدات اليومية لاستراتيجية التداول لدينا. في الحالة أدناه لقد اخترت فترة التعلم من 200. وبعد ذلك نحن حلقة من خلال جميع النقاط من إطار البيانات لدينا من ليرنينغبيريود + 1 إلى طول المصفوفة وعلى كل نقطة نحن & # 8217؛ إعادة إنشاء مجموعة فرعية التدريب باستخدام عدد ليارنينغبيريود من الحانات قبل بوينت البيانات الحالية ونحن ثم الذهاب لاستخدامه لتدريب سفم لدينا. بعد ذلك نحن & # 8217؛ ثم ثم الذهاب العثور على التنبؤ لنموذج سفم بنيت حديثا للعودة القادمة ونحن & # 8217؛ إعادة لإضافة عودة إيجابية أو سلبية إلى مجموعة نتائجنا اعتمادا على ما إذا كانت نتيجة لدينا مباريات أو عدم تطابق الفعلي فئة الانتاج الحقيقي. لاحظ أنه في أي حال (سواء كنا على حق أو خطأ) طرحت 0.0001 من العائد، وهو عبء العمولة الذي اخترته لوضعه على جميع الصفقات (0.01٪ من حجم التجارة). В I ثم استخدام وظيفة الرسم البياني لمكتبة تحليلات الأداء لعرض رسم بياني للتداول التقدم كل 200 القضبان.
. ، داتا = إفترين، كوست = 100، غاما = 0.1)
بعد الانتهاء من هذا سيكون لدينا رسم بياني يظهر نتائج النظام في شكل معين من قبل حزمة بيرفورمانساناليتيكش. بما أن لديك مجموعة من العوائد بتنسيق شتس ستتمكن أيضا من استدعاء أي من الوظائف ضمن هذه الحزمة لمزيد من التحليل لإحصاءات نظام التداول الخاص بك. تظهر الصورة أدناه العائد الذي حصلنا عليه لهذه الاستراتيجية على إتف غلد، يمكننا أن نرى أن تقنية التعلم الآلي المستخدمة لم تكن قادرة على التنبؤ بشكل صحيح الاتجاه في مجموعة كبيرة ومتنوعة من الحالات. وهذا يظهر، كما رأينا أيضا في منصتنا السابقة، أن تحقيق عوائد مربحة باستخدام إجراءات التعلم الآلي ليست سهلة جدا (حتى عند استخدام العديد من المدخلات كما استخدمنا هنا).
ومع ذلك عن طريق اختيار المدخلات أفضل قليلا، والقيام ببعض البيانات قبل المعالجة وتعديل خصائص جاما و ج من سفم يمكننا فعلا الحصول على بعض النتائج المربحة ل سفم إعادة التدريب اليومي على غلد كما هو مبين أدناه (لاحظ أن المحور ص هو لوغاريتمي) . باستخدام تقنيات المجموعات، بما في ذلك العديد من خوارزميات التعلم الآلي المختلفة واختيار أفضل للمدخلات يمكننا تحسين النتائج أدناه أكثر من ذلك، ومع ذلك نحن سوف تترك هذه المناقشة للوظائف المستقبلية.
إذا كنت ترغب في معرفة المزيد عن تقنيات التعلم الآلي وكيف يمكنك أيضا أن تخلق النظم الخاصة بك التي إعادة تدريب على كل شريط وإعطاء النتائج مربحة تاريخيا يرجى النظر في الانضمام إلى أسيريكوي، موقع على شبكة الانترنت مليئة أشرطة الفيديو التعليمية ونظم التداول والتنمية و والصوت، ونهج صريح وشفاف نحو التداول الآلي بشكل عام. آمل أن يحظى هذا المقال بإعجابكم ! : س)
4 الردود على & # 8220؛ استخدام R في التداول الخوارزمي: إعادة اختبار استراتيجية التعلم الآلي التي تعيد التدريب كل يوم & # 8221؛
أنا حيرة قليلا. من المشاركات السابقة كنت يبدو أن خطوات قليلة أبعد من هذا المنصب. ماذا حدث للإطار الخاص بك لخلق استراتيجية التعلم الآلي وكيف هي رفاق مع نهج غبو على الأطر الزمنية أقل. وأذكر أنكم استنتجتم أن هناك إمكانيات أكبر في استراتيجيات اليوم الواحد (أي تخفيضات أقل بكثير). وأود أن يكون من الغريب أن نرى تحديث هناك :-) لذلك بالنسبة لي وظيفة الخاص بك على بناء استراتيجية R على دتف يبدو وكأنه نتيجة من بعض السلبيات على المسار السابق الخاص بك؟ أنا أعبر الأصابع التي ليست كذلك ..
تحية و لا تزال شكرا لهذا & # 8220؛ هوتو & # 8221؛
راجع للشغل، في حالة يو أبدا تعثرت على هذه المقالة:
بالتأكيد، قرأت ذلك تماما منذ بعض الوقت. مثير جدا.
شكرا على مشاركتك: o) لا داعي للقلق، فنحن نواصل البحث في التعلم الآلي على الأطر الزمنية المنخفضة وإنشاء أنظمة باستخدام استخراج البيانات ووحدات معالجة الرسومات. نحن نجعل بعض التقدم الجيد في كل من هذه المجالات وتعدين البيانات السحابية لدينا بالفعل توليد العديد من النظم واعدة (وكثير منهم بالفعل تحت الاختبار المباشر). وتهدف هذه المواد كما الدروس لأولئك الذين لا & # 8217؛ ر الحصول على أدواتنا ولكن ترغب في تنفيذ بعض التجارب التعلم الآلي باستخدام R مع البيانات المتاحة بحرية والبرمجيات. يرجى عدم & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ & نبسب؛ من ما نقوم به، وكثيرا ما المقصود كأدوات تعليمية لأولئك الذين يرغبون في بدء رحلتهم إلى مسارات البحث لدينا. شكرا مرة أخرى لنشرها،
كوانسترات ترادر.
التداول، كوانتسترات، R، وأكثر من ذلك.
تكرار التذبذب إتن إرجاع من كبو الآجلة.
هذه الوظيفة سوف تظهر كيفية تكرار إتنس التقلبات (زيف، فس، زيف، فسز) من كبو الآجلة، مما يسمح لأي فرد لخلق عوائد إتف الاصطناعية من قبل إنشائها، خالية من التكلفة.
لذلك، قبل أن أحصل على الخوارزمية الفعلية، فإنه يعتمد على تحديث لخوارزمية بنية المصطلح لقد شاركت بعض الأشهر مرة أخرى.
في تلك الخوارزمية، عن طريق الخطأ (أو لغرض البساطة)، استخدمت أيام التقويم كما الوقت لانتهاء، عندما كان ينبغي أن يكون أيام عمل، والذي يمثل أيضا عطلة نهاية الأسبوع، والأعياد، والتي هي قطعة أثرية مزعجة لتتبع .
حتى هنا & # 8217؛ s تغيير واضح، في حلقة أن يحسب مرات لانتهاء الصلاحية:
الخط البارز على وجه الخصوص هو:
ما هي هذه الوظيفة بيزدايس؟ ويأتي من حزمة بيزديس في R.
هناك & # 8217؛ s أيضا التداولHholidays. R النصي، الأمر الذي يجعل استخدام مزيد من حزمة بيزديس. هنا & # 8217؛ ق ما يجري تحت غطاء محرك السيارة في TradingHolidays. R، لأولئك الذين يرغبون في تكرار رمز:
هناك نوعان من ملفات كسف التي تم تجميعها يدويا، لكنهما سيشاركان لقطات من & # 8211؛ وهما عطلة عيد الفصح (لأنهما يجب تعديلهما لتحويلهما من يوم الأحد إلى يوم الجمعة بسبب عطلة عيد الفصح) وبقية أيام العطل الوطنية.
هنا هو ما يشبه كسف يسير:
و نونيسترهوليدايس، الذي يحتوي على رأس السنة الجديدة & # 8217؛ ق يوم، ملك يوم الابن، الرئيس & # 8217؛ يوم، يوم الذكرى، يوم الاستقلال، يوم العمل، عيد الشكر، ويوم عيد الميلاد (جنبا إلى جنب مع التواريخ التي لوحظت) كسف:
وعلاوة على ذلك، نحن بحاجة إلى تعديل لمدة يومين أن الأسهم لم تتداول بسبب إعصار ساندي.
لذلك، فإن قائمة الأعياد تبدو كما يلي:
حتى مرة واحدة لدينا قائمة من الأعياد، ونحن نستخدم حزمة بيزديس لضبط العطلات وعطلات نهاية الأسبوع (السبت والأحد) كما لدينا أيام غير تجارية، واستخدام هذه الوظيفة لحساب الأوقات الصحيحة لانتهاء الصلاحية.
لذلك، والآن بعد أن لدينا بنية انتهاء الصلاحية المحدثة، يمكننا كتابة وظيفة من شأنها أن تكرر بشكل صحيح الأربعة الرئيسية إتنس و # 8211؛ زيف، فس، زيف، و فسز.
هنا & # 8217؛ s تفسير اللغة الإنجليزية:
فس تتكون من عقدين & # 8211؛ الشهر الأول، والشهر الخلفي، ولها عدد معين من أيام التداول (أيام عمل أكا) أنه يتداول حتى انتهاء، ويقول 17. خلال هذا الإطار الزمني، والشهر الامامي ( واسمحوا & # 8217؛ ق يطلق عليه M1) يذهب من كونه تخصيص كامل للأموال، لأنه لا شيء من تخصيص الأموال، كما يقترب عقد الشهر الأمامي انتهاء. بمعنى أن العقد الثاني ينتهي، فإن العقد الثاني يتلقى تدريجيا المزيد والمزيد من الوزن، حتى عند انتهاء عقد الشهر الأول، فإن عقد الشهر الثاني يحتوي على جميع الأموال & # 8211؛ تماما كما * يصبح * الشهر الأول عقد. لذلك، يقول لديك 17 يوما لانتهاء في الشهر الأمامي. عند انتهاء العقد السابق، سيكون الشهر الثاني وزن 17/17 & # 8211؛ 100٪، حيث يصبح الشهر الامامي. ثم، في اليوم التالي، هذا العقد، والآن في الشهر الأمامي، وسوف يكون وزن 16/17 عند تسوية، ثم 15/17، وهلم جرا. ويسمى هذا البسط الدكتور، ويسمى القاسم دت.
ومع ذلك، أبعد من ذلك، هناك & # 8217؛ والآلية الثانية التي هي المسؤولة عن فس يشبه أنه بالمقارنة مع العقد الآجلة الأساسية (وهذا هو، الاضمحلال المسؤول عن تقلبات قصيرة & # 8217؛ s الأرباح)، و وهذا هو & # 8220؛ لحظية & # 8221؛ إعادة التوازن. وهذا يعني أن عوائد يوم معين هي اليوم التي تستقر مضروبا بأوزان الأمس، على مدى يوم أمس ستستقر مضروبا بأوزان الأمس، ناقص واحد. (S_1_t * در / dt_t-1 + S_2_t * 1-در / dt_t-1) / (S_1_t-1 * در / dt_t-1 + S_2_t-1 * 1-در / dt_t-1) & # 8211؛ 1 (يمكنني استخدام البرنامج التعليمي على اللثي). لذلك، عندما تتحرك إلى الأمام يوم، حسنا، غدا، اليوم & # 8217؛ s الأوزان تصبح t-1. ومع ذلك، متى كانت الأصول قادرة على إعادة التوازن؟ حسنا، في إتنس مثل فس و فسز، و & # 8220؛ باليد التلويح & # 8221؛ هو أنه يحدث على الفور. وهذا يعني أن وزن الشهر الأول كان 93٪، وتحقق العائد عند التسوية (أي من تسوية إلى تسوية)، وبعد أن تحققت هذه العودة مباشرة، يتحرك وزن الشهر الأمامي من 93٪ على سبيل المثال، 88٪. لذلك، يقول كريدي سويس (الذي يصدر هذه إتنس)، لديه 10،000 $ (فقط للحفاظ على الحساب وعدد الأصفار يمكن تحملها، ومن الواضح أن هناك الكثير في الواقع) يستحق الرابع عشر المعلقة بعد تحقيق عوائد على الفور، وسوف تبيع 500 $ من $ 9300 في الشهر الأمامي، وعلى الفور نقلها إلى الشهر الثاني، لذلك سوف تذهب على الفور من 9300 $ في M1 و 700 $ في M2 إلى 8800 $ في M1 و 1200 $ في M2. متى تحركت تلك $ 500؟ على الفور، وعلى الفور، وإذا أردت، يمكنك تطبيق القانون الثالث كلارك & # 8217؛ وندعوه & # 8220؛ سحرية & # 8221 ؛.
والاستثناء الوحيد هو يوم بعد يوم لفة، حيث يصبح الشهر الثاني ببساطة الشهر الأمامي كما تنتهي الشهر السابق، لذلك ما كان وزن 100٪ في الشهر الثاني سيكون الآن وزن 100٪ في الشهر الأمامي، لذلك هناك & # 8217؛ ق بعض التعليمات البرمجية الإضافية التي تحتاج إلى أن تكون مكتوبة لجعل هذا التمييز.
هذا هو الطريقة التي يعمل بها ل فس و زيف. ما الفرق بين فكس و زيف؟ انها بسيطة حقا & # 8211؛ بدلا من M1 و M2، فسز يستخدم نفس الأوزان بالضبط (وهذا هو، الوقت المتبقي في الشهر الأمامي مقابل عدد الأيام الموجودة لهذا العقد ليكون الشهر الأمامي)، يستخدم M4 ، M5، M6، و M7، مع M4 أخذ الدكتور / دت، M5 و M6 يجري دائما 1، و M7 يجري 1-د / دت.
على أية حال، هنا الرمز.
لذلك، شكرا جزيلا يخرج إلى مايكل كابلر من أدوات منظم المستثمر للقيام في الأصل النسخ المتماثل وتوفير التعليمات البرمجية له. بلدي التعليمات البرمجية أساسا يفعل الشيء نفسه، في، نأمل طريقة أكثر علق.
لذا، في نهاية المطاف، هل يعمل؟ حسنا، باستخدام رمز بنية المصطلح المحدثة، يمكنني اختبار ذلك.
بينما لا أعمل على لصق شفرة بنية المصطلح بأكملها (مرة أخرى، تتوفر هنا، فقط قم بتحديث البرنامج النصي مع تحديثاتي من هذه المشاركة)، وهنا & # 8217؛ كيف تقوم بتشغيل الوظيفة الجديدة:
وبما أنه يعود كل من فس يعود وعودة فسز، يمكننا مقارنتها على حد سواء.
ونتيجة ل:
في الأساس، مباراة مثالية.
دعونا نفعل الشيء نفسه، مع زيف.
لذلك، إعادة البناء من العقود الآجلة لا أفضل قليلا من إتن. ولكن المسار متطابق إلى حد كبير.
وبذلك يختتم هذا المنصب. آمل أن تسلط بعض الضوء على كيفية عمل هذه التقلبات إتنس، وكيفية الحصول عليها مباشرة من البيانات الآجلة التي نشرتها كبوي، والتي هي المدخلات لخوارزمي هيكل المدى الخاص بي.
وهذا يعني أيضا أنه بالنسبة للمؤسسات المهتمة بتداول إستراتيجيتي، يمكنهم الحصول على نفوذ لتداول المتغيرات المتراكبة الآجلة المركبة من إتنس، في حجم أكبر.
شكرا للقراءة.
ملاحظات: بالنسبة للراغبين في استراتيجية الاشتراك بالتجزئة للتداول التقلب، لا تترددوا في الاشتراك في بلدي التقلبات في استراتيجية التداول. للراغبين في توظيف لي بدوام كامل أو لمشاريع استشارية طويلة الأجل، ويمكن الوصول إلى بلدي ينكدين، أو بريدي الإلكتروني: ilya. kipnis@gmail.
(دون & # 8217؛ ر الحصول على) متشابكة في الضوضاء.
سيكون هذا المنصب حول التحقيق في كفاءة كونتانغو كإشارة تجارية تقلب.
بالنسبة لأولئك الذين يتاجرون بالتقلب (مثلي)، وهو مصطلح قد ترى أن & # 8217؛ في كل مكان إلى حد ما هو مصطلح & # 8220؛ كونتانغو & # 8221 ؛. ماذا يعني هذا المصطلح؟
حسنا، بسيط: يعني فقط نسبة الشهر الثاني من العقود الآجلة فيكس على الأول. والفكرة هي أنه عندما يكون الشهر الثاني من العقود الآجلة أكثر من الأول، أن توقعات الناس للتذبذب أكبر في المستقبل مما هي عليه في الوقت الحاضر، وبالتالي فإن العقود الآجلة هي & # 8220؛ في كونتانغو & # 8221؛، وهو أكثر من مرة.
وعلاوة على ذلك، فإن تلك التي تحاول العثور على أفكار تجارية تقلب لائق قد تكون غالبا ما رأت أن العقود الآجلة في كونتانغو يعني أن عقد موقف تقلب قصيرة ستكون مربحة.
هل هذا هو الحال؟
حسنا، هناك & # 8217؛ s طريقة سهلة للرد على ذلك.
أولا، ارجع إلى منصبي للحصول على بيانات مستقبلية مجانية من كبوي.
باستخدام هذه البيانات، يمكننا الحصول على إشارة لدينا (أي، لتشغيل التعليمات البرمجية في هذا المنصب، تشغيل التعليمات البرمجية في هذا المنصب).
الآن، اسمحوا & # 8217؛ s الحصول على بياناتنا الرابع عشر (مرة أخرى، شكرا جزيلا للسيد هلموث فولمير لذلك يرجى تقديم ذلك.
الآن، هنا & # 8217؛ s كيف يعمل هذا: كما كبوي دوسن & # 8217؛ t تحديث يستقر حتى حوالي الساعة 9:45 صباحا بتوقيت شرق الولايات المتحدة في اليوم التالي (إغ يوم الثلاثاء & # 8217؛ s تسوية البيانات فاز & # 8217؛ ر الافراج حتى الأربعاء في 9:45 صباحا إست)، علينا أن ندخل في وقت قريب من اليوم بعد اشعال النار. (بالنسبة إلى أولئك الذين يتساءلون، تستخدم إستراتيجيتي الاشتراكية هذه الآلية، مما يتيح للمشتركين وقتا كافيا للتنفيذ على مدار اليوم.)
لذلك، اسمحوا & # 8217؛ s حساب لدينا باكتست العوائد. هنا & # 8217؛ s ستراتستاتس وظيفة لحساب بعض الإحصاءات ملخص.
مع النتائج التالية:
لذلك، من الواضح أن هذه كارثة. الفحص البصري سوف تظهر مدمرة، سحب متعددة السنوات. باستخدام الأمر table. Drawdowns، يمكننا عرض أسوأ منها.
لذا، فإن أعلى 3 هي رهيبة، ثم أي شيء فوق 30٪ لا تزال مروعة جدا. واستمرت بضع عمليات السحب هذه سنوات عديدة أيضا، مع طول هائل إلى الحوض الصغير. 458 يوما تداول ما يقرب من عامين، و 364 حوالي سنة ونصف السنة. تخيل رؤية استراتيجية تكون على الدوام على الجانب الخطأ للتجارة لمدة ما يقرب من عامين، وعندما يقال كل شيء وفعلت، أنت & # 8217؛ فقدت ثلاثة أرباع كل شيء في تلك الاستراتيجية.
هناك & # 8217؛ s لا السكر-- طلاء هذا: لا يمكن إلا أن يسمى هذه الاستراتيجية القمامة المطلقة.
فلنحاول إجراء تعديل واحد: نحن بحاجة إلى كل من كونتانغو (C2 & غ؛ C1)، وأن يكون كونتانغو أعلى من المتوسط المتحرك البسيط لمدة 60 يوما، على غرار استراتيجيتي فسف / فسمت.
مع النتائج:
لذلك، فإن كالمار لا يزال بأمان أقل من 1، ومؤشر أداء قرحة لا يزال في الطابق السفلي، وهو الحد الأقصى للتخطي التي & # 8217؛ s طويلة الماضي نقطة أن الناس سوف تتخلى عن الاستراتيجية، وهلم جرا.
لذلك، على الرغم من أنه تم تحسينه، فإنه لا يزال من الآمن القول أن هذه الاستراتيجية لا تعمل جيدا. حتى بعد الانسحاب الكبير 2007-2008، فإنه لا يزال يحصل على بعض الأشياء سيئة للغاية، مثل التعرض لجميع أغسطس 2017.
في حين أعتقد أن هناك تطبيقات ل كونتانغو في الاستثمار التقلبات، وأنا لا أعتقد أن استخدامه في توليد إشارة تقلب طويلة / قصيرة من تلقاء نفسها. وبدلا من ذلك، أعتقد أن المؤشرات الأخرى ومصادر البيانات تؤدي عملا أفضل من ذلك. مثل فكسف / فسمت، الذي تم تكراره منذ ذلك الحين لتشكيل استراتيجية اشتراكي.
شكرا للقراءة.
ملاحظة: أنا حاليا تسعى فرص التواصل والمشاريع طويلة الأجل، والمواقف بدوام كامل المتعلقة بمهنتي مجموعة. يمكن العثور على ملفي الشخصي هنا.
مقارنة بعض الاستراتيجيات من سهولة التقلب الاستثمار، و Table. Drawdowns الأمر.
وستكون هذه المشاركة حول مقارنة الاستراتيجيات من الورقة & # 8220؛ سهولة التقلب الاستثمار & # 8221؛، جنبا إلى جنب مع مظاهرة من R & # 8217 الصورة s. Drawdowns الأمر.
أولا، قبل أن أبعد من ذلك، في حين أعتقد أن افتراضات التنفيذ وجدت في مؤشر الضعف الاقتصادي لا تقدم استراتيجيات جيدة للتداول الفعلي الفعلي (على الرغم من أن المخاطر / المكافآت مكافأة أيضا ترك الكثير من مجال للتحسين)، وأعتقد أن هذه الاستراتيجيات كبيرة كمعايير.
لذلك، منذ بعض الوقت، لقد فعلت اختبار خارج العينة لأحد الاستراتيجيات الموجودة في مؤشر الضعف الاقتصادي، والتي يمكن العثور عليها هنا.
باستخدام نفس مصدر البيانات، كما أنني حصلت على البيانات ل سبي (على الرغم من مرة أخرى، ألفافانتيج يمكن أيضا توفير هذه الخدمة مجانا لأولئك الذين لا تستخدم كواندل).
هنا & # 8217؛ s الرمز الجديد.
لذلك، شرح: هناك أربعة تيارات عودة هنا & # 8211؛ شراء وعقد زيف، زخم دن من وظيفة سابقة، واستراتيجيتين أخرى.
أبسط واحد، ودعا فراتيو هو ببساطة نسبة فيكس على فكسف. بالقرب من الإغلاق، تحقق من هذه الكمية. إذا كان هذا هو أقل من واحد، وشراء الرابع عشر، وإلا، وشراء فس.
والآخر، ودعا استراتيجية تقلب المخاطر قسط (أو فرب قصيرة)، ويقارن التقلب التاريخي لمدة 10 يوما (أي انحراف معياري سنوي عشرة أيام) من S & P 500، يطرحه من فيكس، ويأخذ وهو المتوسط المتحرك لمدة 5 أيام لذلك. بالقرب من الإغلاق، عندما يكون الرقم أعلى من الصفر (أي، فيكس أعلى من التقلب التاريخي)، انتقل إلى الرابع عشر، وإلا، فانتقل طويلا.
مرة أخرى، كل هذه الاستراتيجيات هي على نحو فعال & # 8220؛ مراقبة بالقرب / في الإغلاق، وشراء في نهاية & # 8221؛، لذلك هي مفيدة لأغراض العرض التوضيحي، وإن لم يكن لأغراض التنفيذ على أي حساب كبير دون تكبد تأثير السوق.
في ما يلي النتائج، منذ عام 2018 (أي وقت الإنشاء الفعلي الرابع عشر والرابع):
تجدر الإشارة إلى أن كلا من الزخم واستراتيجية "فرب" لا تحققان أداء أفضل من الشراء والعقد الرابع عشر منذ عام 2018. ومن ناحية أخرى، فإن استراتيجية فراتيو تتفوق على الأداء.
إليك وظيفة الإحصاءات الموجزة التي تجمع بعض مقاييس الأداء الأعلى مستوى.
تجدر الإشارة إلى أن جميع الاستراتيجيات المعيارية قد عانت من عمليات سحب كبيرة جدا منذ تأسيس زيف & # 8217؛ حيث يمكننا فحصها باستخدام الأمر table. Drawdowns كما هو موضح أدناه:
لاحظ أن الأمر table. Drawdowns يقوم بفحص تدفق عودة واحد فقط في المرة الواحدة. وعلاوة على ذلك، تحدد الحجة العليا عدد عمليات السحب التي يجب النظر إليها، مرتبة حسب أكبر سحب أولا.
أحد الأسباب التي أعتقد أن هذه الاستراتيجيات يبدو أنها تعاني من عمليات السحب التي تقوم بها هي أنها '' إما أن كل شيء في الأصول واحد، أو العكس تماما، مع عدم وجود مجال للخطأ.
آخر شيء، للفضول، وهنا هي المقارنة مع استراتيجيتي منذ عام 2018 (أساسا الرابع عشر التأسيس) قياسا على الاستراتيجيات في مؤشر الضعف الاقتصادي (الذي كنت تتداول مع رأس المال الحي منذ سبتمبر، وفتحت مؤخرا خدمة الاشتراك ل):
شكرا للقراءة.
ملاحظة: أبحث حاليا عن الشبكات والفرص بدوام كامل المتعلقة بمهارة مجموعة. ملفي الشخصي ينكدين يمكن العثور عليها هنا.
إطلاق خدمة الاشتراك.
بعد قياس الاهتمام من قرائي، قررت & # 8217؛ فتح خدمة اشتراك. أنا & # 8217؛ ليرة لبنانية نسخ ولصق الأسئلة الشائعة، أو أفضل محاولة لي في محاولة للرد على العديد من الأسئلة ممكن في وقت مبكر، ويمكن أن يجيب أكثر في المستقبل.
أنا اختيار لاستخدام باترون فقط للاستعانة بمصادر خارجية كل من التقنية من التعامل مع الاشتراكات وخلق مصدر مركزي لنشر المحتوى القائم على الاشتراك.
الأسئلة الشائعة (التي تم نسخها من صفحة الاشتراك):
شكرا لزيارتك. بعد قياس الفائدة من قراءي على موقعي الرئيسي (quantstrattrader. wordpress)، قمت بإنشاء هذا كصفحة اشتراك لاستراتيجيات الاستثمار الكمية، بهدف تحويل المشتركين إلى نقدهم إلى المزيد من النقود، صافي رسوم الاشتراك (نأمل). إن الأنظمة التي أطورها تأتي من خلفية التعلم من المهنيين ذوي الخبرة في التداول الكمي، وكبار الباحثين في الشركات الكبيرة. النظام الحالي نشرت في البداية نموذجا أوليا لعدة سنوات مرة أخرى وشاهدت يتم تعقبها، قبل أن تبدأ أخيرا لنشر رأسمالي الخاص في وقت سابق من هذا العام، وإجراء أحدث التعديلات حتى الآن.
وفي حين أن الأداء السابق لا يضمن النتائج المستقبلية والماضي لا يعيد نفسه، فإنه غالبا ما القوافي، لذلك دعونا تحويل الأموال إلى المزيد من المال.
بعض الأسئلة الشائعة حول الاستراتيجية:
ما هو سعر الاشتراك لهذه الاستراتيجية؟
حاليا، بعد قياس الاهتمام من القراء وإجراء البحوث استنادا إلى مواقع أخرى، التسعير المؤقت هو 50 $ / الشهر. وبما أن هذه الاستراتيجية تبني سجلا حافلا، قد يكون ذلك عرضة للتغيير في المستقبل، وسيتم إجراء الإخطارات في مثل هذه الحالة.
ما هو وصف الاستراتيجية؟
الاستراتيجية هي أساسا نظام التقلب القصير الذي يتداول الرابع عشر، زيف، و فس. وبقدر ما تذهب استراتيجيات التقلب، فإنه متحفظ إلى حد ما في أنه يستخدم العديد من الشيكات المختلفة من أجل ضمان الموقف.
ما هي إستراتيجية & # 8217؛ s حافة؟
في کلمتین: إدارة المخاطر. أساسا، هناك عدد قليل من المعايير المنفصلة لاختيار الاستثمار، والنظام يقضي وقتا غير هام مع عدم التعرض عندما توفر بعض هذه المعايير إشارات متناقضة. وعلاوة على ذلك، يستخدم النظام منهجيات منضبطة في بنائه من أجل تجنب المعلمات الحرة غير الضرورية، والحفاظ على استراتيجية كما شاذة قدر الإمكان.
هل تتداول رأس المال الخاص بك مع هذه الاستراتيجية؟
متى كانت فترة التدريب داخل العينة لهذا النظام؟
الموقع الذي لم يعد يقوم بتحديث مدونته (تقلب بسيط) مرة واحدة تتبع استراتيجية أكثر بدائية التي كتبت قبل عدة سنوات. وقد سرت بشكل خاص بنتائج هذا الفحص، وقد تلقيت مؤخرا مدخلات لتحسين نظامي بدرجة أكبر بكثير، وكذلك اكتسبت الثقة لاستثمار رأس المال المباشر في ذلك.
كم عدد الصفقات التي يقوم بها النظام سنويا؟
في الاختبار الخلفي من 20 أبريل 2008 حتى نهاية 2018، قام النظام بإجراء 187 معاملة في الرابع عشر (شراء وبيع)، 160 في زيف، و 52 في فس. وهذا يعني على مدى 9 سنوات تقريبا، كان هناك في المتوسط 43 معاملة في السنة. في بعض الحالات، قد يكون هذا ببساطة التحول من الرابع عشر إلى زيف أو العكس بالعكس. وبعبارة أخرى، تقترب الصفقات من أسبوع تقريبا (قد يكون بعضها أطول، وبعضها أقصر).
متى سيتم نشر الإشارات؟
سيتم نشر الإشارات في وقت ما بين الساعة 12 ظهرا و إغلاق السوق (4 مساء بتوقيت شرق الولايات المتحدة). في باكتستينغ، يتم اختبارها كما السوق على أوامر وثيقة، حتى الأفراد تحمل أي خطر / مكافأة من قبل التنفيذ في وقت سابق.
كم مرة يكون هذا النظام في السوق؟
حوالي 56٪. ومع ذلك، على مدى باكتستينغ (والتداول الحي)، فقط حوالي 9٪ من أشهر لديها صفر العودة.
ما هي توزيع الأرباح الفائتة والخاسرة والصفر؟
وفي أواخر أكتوبر 2017، كان هناك نحو 65٪ من أشهر الفوز (بمتوسط ربح 12.8٪)، وخسارة 26٪ أشهر (بمتوسط خسارة 4.9٪)، و 9٪ صفر شهر.
ما هي بعض الإحصاءات الأخرى حول الاستراتيجية؟
منذ عام 2018 (في الوقت الذي جاء فيه رسميا الرابع عشر في البداية بدلا من استخدام البيانات الاصطناعية)، وقد تفاخر استراتيجية العائد السنوي 82٪، مع سحب 24.8٪ كحد أقصى والانحراف المعياري السنوي 35٪. وهذا يعني أن نسبة شارب (العودة إلى الانحراف المعياري) أعلى من 2، ونسبة كالمار أعلى من 3. كما أن لديها مؤشر أداء قرحة من 10.
ما هي اسوأ اساليب السحب؟
منذ عام 2018 (مرة أخرى، في وقت قريب من الرابع عشر و # 8217 ق)، كان أكبر سحب 24.8٪، ابتداء من 31 أكتوبر 2018، وجعل الأسهم الجديدة عالية في 12 يناير 2018. بدأ أطول سحب يوم 21 أغسطس ، 2018 واستردت في 10 أبريل 2018، واستمرت لمدة 160 يوما تداول.
هل سيتغير سعر الاشتراك في المستقبل؟
إذا استمرت الاستراتيجية في تحقيق عوائد قوية، فقد يكون هناك سبب لزيادة السعر طالما أن العائدات تحمله.
ھل یمکن تقدیم إشارة خطر متحفظة لأولئك الذین قد لا یکونون قادرین علی تحمل انخفاض بنسبة 25٪؟
وهناك استمارة مختلفة للاستراتيجية التي تستهدف نحو نصف الانحراف المعياري السنوي للاستراتيجية تفتخر بعائد سنوي بنسبة 40٪ لنحو 12٪ من الانخفاض منذ عام 2018. وبوجه عام، فإن هذه المكافأة أعلى قليلا في إحصاءات المخاطر، ولكن على حساب خفض العائدات الإجمالية في النصف.
هل يمكن أن يكون ل زيف حدثا لإنهاء الخدمة؟
هذا يشير إلى فكرة إيفن إتن تنتهي إذا كان يفقد 80٪ من قيمته في يوم واحد. لإعطاء فكرة عن احتمال هذا الحدث، باستخدام البيانات الاصطناعية، و 14 إتن كان سحب هائل من 92٪ على مدى الأزمة المالية عام 2008. ولتاريخ تلك البيانات التركيبية (قبل التأسيس) والمعطيات المحققة (ما بعد الإنشاء)، كان اليوم الأسوأ المطلق يوم انخفاض بنسبة 26.8٪. وتجدر الإشارة إلى أن الاستراتيجية لم تكن في الرابع عشر خلال ذلك اليوم.
ما هي الاستراتيجية وأسوأ يوم؟
في 16 سبتمبر 2018، فقدت الاستراتيجية 16٪ في يوم واحد. وكان هذا في نهاية الذيل من امتداد الأيام الإيجابية التي جعلت حوالي 40٪.
ما هي مخاطر الإستراتيجية؟
والمخاطرة الأولى هي أنه بالنظر إلى أن هذه الاستراتيجية منحازة بشكل طبيعي نحو التقلبات القصيرة، فإنها يمكن أن تكون لها بعض التخفيضات الحادة بسبب طبيعة ارتفاع التقلب. والمخاطر الأخرى هي أنه بالنظر إلى أن هذه الاستراتيجية تنفق أحيانا وقتها في زيف، فإنها ستضعف أداءها الرابع عشر في بعض الأيام الجيدة. وهذا الخطر الثاني هو نتيجة لطبقات إضافية من إدارة المخاطر في الاستراتيجية.
ما مدى تعقيد هذه الاستراتيجية؟
ليس بشكل مفرط. انها & # 8217؛ ق فقط أكثر تعقيدا قليلا من استراتيجية الزخم الأساسية عند عد المعلمات الحرة، ويمكن تفسيرها في بضع دقائق.
هل تستخدم هذه الإستراتيجية أي منهجيات معقدة للتعلم الآلي؟
لا. متطلبات البيانات لهذه الخوارزميات والضجيج في العالم المالي تجعل من الخطورة جدا لتطبيق هذه المنهجيات، والبحوث حتى الآن لم تؤتي ثمارها لتبرير دمجها.
هل سيكون حجم الأداة مصدر قلق (خاصة زيف)؟
وفقا لشخص واحد الذي عمل على إنشاء الأصلي فس إتن (وبالتالي، عكسها، الرابع عشر)، يمكن إنشاء مصدر جديد من إتنس من قبل المصدر (في زيف & # 8217؛ ق القضية، كريدي سويس) عند الطلب. وباختصار، فإن القلق من الحجم هو أكثر من مصدر قلق سمعة الشخص الذي يقدم الطلب. وبعبارة أخرى، يعتمد ذلك على مدى نجاح الاستراتيجية.
هل يمكن أن تكون الاستراتيجية مسؤولة / مسؤولة / مسؤولة عن خسارة المشترك / سحبه؟
اسمحوا هذا بمثابة إخلاء المسؤولية: عن طريق الاشتراك، فإنك توافق على التنازل عن أي مطالبة قانونية ضد الاستراتيجية، أو منشئها (ق) في حالة السحب، والخسائر، وما إلى ذلك الاشتراك هو لعرض إخراج البرنامج، و هذه الخدمة لا تدير بنشاط فلسا واحدا من المشتركين & # 8217؛ الأصول الفعلية. يمكن للمشتركين اختيار تجاهل إشارات الاستراتيجية في لحظة إشعار وفقا لتقديرهم. لا ينبغي التفكير في مخرجات البرنامج على أنه النصائح الاستثمارية الواردة من سفب و كفا و ريا وما إلى ذلك.
لماذا يجب الوثوق بهذه الإشارات؟
لأن عملي على مواضيع أخرى كان على كامل، العرض العام لعدة سنوات. خلافا لمواقع الويب الأخرى، لقد أظهرت & # 8220؛ باكستس سيئة & # 8221؛، وبالتالي كسر القول المأثور من & # 8220؛ أنت & # 8217؛ لن نرى سيئة باكتست & # 8221 ؛. لقد أظهرت دقة في بحثي، وقد تم تطبيق نفس الدقة تجاه هذا النظام أيضا. 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.
Testing the Hierarchical Risk Parity algorithm.
This post will be a modified backtest of the Adaptive Asset Allocation backtest from AllocateSmartly, using the Hierarchical Risk Parity algorithm from last post, because Adam Butler was eager to see my results. On a whole, as Adam Butler had told me he had seen, HRP does not generate outperformance when applied to a small, carefully-constructed, diversified-by-selection universe of asset classes, as opposed to a universe of hundreds or even several thousand assets, where its theoretically superior properties result in it being a superior algorithm.
First off, I would like to thank one Matthew Barry, for helping me modify my HRP algorithm so as to not use the global environment for recursion. You can find his github here.
Here is the modified HRP code.
With covMat and corMat being from the last post. In fact, this function can be further modified by encapsulating the clustering order within the getRecBipart function, but in the interest of keeping the code as similar to Marcos Lopez de Prado’s code as I could, I’ll leave this here.
Anyhow, the backtest will follow. One thing I will mention is that I’m using Quandl’s EOD database, as Yahoo has really screwed up their financial database (I. E. some sector SPDRs have broken data, dividends not adjusted, etc.). While this database is a $50/month subscription, I believe free users can access it up to 150 times in 60 days, so that should be enough to run backtests from this blog, so long as you save your downloaded time series for later use by using write. zoo.
This code needs the tseries library for the portfolio. optim function for the minimum variance portfolio (Dr. Kris Boudt has a course on this at datacamp), and the other standard packages.
A helper function for this backtest (and really, any other momentum rotation backtest) is the appendMissingAssets function, which simply adds on assets not selected to the final weighting and re-orders the weights by the original ordering.
Next, we make the call to Quandl to get our data.
While Josh Ulrich fixed quantmod to actually get Yahoo data after Yahoo broke the API, the problem is that the Yahoo data is now garbage as well, and I’m not sure how much Josh Ulrich can do about that. I really hope some other provider can step up and provide free, usable EOD data so that I don’t have to worry about readers not being able to replicate the backtest, as my policy for this blog is that readers should be able to replicate the backtests so they don’t just nod and take my word for it. If you are or know of such a provider, please leave a comment so that I can let the blog readers know all about you.
Next, we initialize the settings for the backtest.
While the AAA backtest actually uses a 126 day lookback instead of a 6 month lookback, as it trades at the end of every month, that’s effectively a 6 month lookback, give or take a few days out of 126, but the code is less complex this way.
Next, we have our actual backtest.
In a few sentences, this is what happens:
The algorithm takes a subset of the returns (the past six months at every month), and computes absolute momentum. It then ranks the ten absolute momentum calculations, and selects the intersection of the top 5, and those with a return greater than zero (so, a dual momentum calculation).
If no assets qualify, the algorithm invests in nothing. If there’s only one asset that qualifies, the algorithm invests in that one asset. If there are two or more qualifying assets, the algorithm computes a covariance matrix using 20 day volatility multiplied with a 126 day correlation matrix (that is, sd_20′ %*% sd_20 * (elementwise) cor_126. It then computes normalized inverse volatility weights using the volatility from the past 20 days, a minimum variance portfolio with the portfolio. optim function, and lastly, the hierarchical risk parity weights using the HRP code above from Marcos Lopez de Prado’s paper.
Lastly, the program puts together all of the weights, and adds a cash investment for any period without any investments.
في ما يلي النتائج:
In short, in the context of a small, carefully-selected and allegedly diversified (I’ll let Adam Butler speak for that one) universe dominated by the process of which assets to invest in as opposed to how much, the theoretical upsides of an algorithm which simultaneously exploits a covariance structure without needing to invert a covariance matrix can be lost.
However, this test (albeit from 2007 onwards, thanks to ETF inception dates combined with lookback burn-in) confirms what Adam Butler himself told me, which is that HRP hasn’t impressed him, and from this backtest, I can see why. However, in the context of dual momentum rank selection, I’m not convinced that any weighting scheme will realize much better performance than any other.
شكرا للقراءة.
NOTE: I am always interested in networking and hearing about full-time opportunities related to my skill set. My linkedIn profile can be found here.
algotrading.
77 пользователей находятся здесь.
МОДЕРАТОРЫ.
مرحبا بكم في رديت،
الصفحة الأولى للإنترنت.
والاشتراك في واحدة من الآلاف من المجتمعات المحلية.
отправлено & # 32؛ 9 месяцев назад автор ModwithABod [M] - announcement.
отправлено & # 32؛ 1 день назад автор AwfulNoob Student.
отправлено & # 32؛ 5 дней назад автор jvrssc.
отправлено & # 32؛ 5 дней назад автор Hauch.
помощь правила сайта центр поддержки вики реддикет مود غدلينس связаться с нами.
приложенияи инструменты رديت لأيفون رديت لالروبوت موقع الجوال кнопки.
Использование данного сайта означает، что вы принимаете & # 32؛ пользовательского соглашения & # 32؛ и & # 32؛ Политика конфиденциальности. &نسخ؛ 2018 ريديت инкорпорейтед. Все права защищены.
يتم تسجيل ريديت وشعار ألين علامات تجارية مسجلة لشركة رديت إنك.
وبي. Rendered by PID 61321 on app-250 at 2018-01-16 09:23:01.731892+00:00 running b995ef9 country code: UA.
The R Trader.
Using R and related tools in Quantitative Finance.
Visualizing Time Series Data in R.
I’m very pleased to announce my DataCamp course on Visualizing Time Series Data in R. This course is also part of the Time Series with R skills track. Feel free to have a look, the first chapter is free!
Course Description.
As the saying goes, “A chart is worth a thousand words”. This is why visualization is the most used and powerful way to get a better understanding of your data. After this course you will have a very good overview of R time series visualization capabilities and you will be able to better decide which model to choose for subsequent analysis. You will be able to also convey the message you want to deliver in an efficient and beautiful way.
Course Outline.
Chapter 1: R Time Series Visualization Tools.
This chapter will introduce you to basic R time series visualization tools.
Chapter 2: Univariate Time Series.
Univariate plots are designed to learn as much as possible about the distribution, central tendency and spread of the data at hand. In this chapter you will be presented with some visual tools used to diagnose univariate times series.
Chapter 3: Multivariate Time Series.
What to do if you have to deal with multivariate time series? In this chapter, you will learn how to identify patterns in the distribution, central tendency and spread over pairs or groups of data.
Chapter 4: Case study: Visually selecting a stock that improves your existing portfolio.
Let’s put everything you learned so far in practice! Imagine you already own a portfolio of stocks and you have some spare cash to invest, how can you wisely select a new stock to invest your additional cash? Analyzing the statistical properties of individual stocks vs. an existing portfolio is a good way of approaching the problem.
Linking R to IQFeed with the QuantTools package.
IQFeed provides streaming data services and trading solutions that cover the Agricultural, Energy and Financial marketplace. It is a well known and recognized data feed provider geared toward retail users and small institutions. The subscription price starts at around $80/month.
Stanislav Kovalevsky has developed a package called QuantTools. It is an all in one package designed to enhance quantitative trading modelling. It allows to download and organize historical market data from multiple sources like Yahoo, Google, Finam, MOEX and IQFeed. The feature that interests me the most is the ability to link IQFeed to R. I’ve been using IQFeed for a few years and I’m happy with it (I’m not affiliated to the company in any way). ويمكن الاطلاع على مزيد من المعلومات هنا. I’ve been looking for an integration within R for a while and here it is. As a result, after I ran a few tests, I moved my code that was still in Python into R. Just for completeness, here’s a link that explains how to download historical data from IQFeed using Python.
QuantTools offers four main functionalities: Get market data, Store/Retrieve market data, Plot time series data and Back testing.
First make sure that IQfeed is open. You can either download daily or intraday data. The below code downloads daily prices (Open, High, Low, Close) for SPY from 1st Jan 2017 to 1st June 2017.
The below code downloads intraday data from 1st May 2017 to 3rd May 2017.
Note the period parameter. It can take any of the following values: tick, 1min, 5min, 10min, 15min, 30min, hour, day, week, month, depending on the frequency you need.
QuantTools makes the process of managing and storing tick market data easy. You just setup storage parameters and you are ready to go. The parameters are where, since what date and which symbols you would like to be stored. Any time you can add more symbols and if they are not present in a storage, QuantTools tries to get the data from specified start date. The code below will save the data in the following directory: “C:/Users/Arnaud/Documents/Market Data/iqfeed”. There is one sub folder by instrument and the data is aved in. rds files.
You can also store data between specific dates. Replace the last line of code above with one of the below.
Now should you want to get back some of the data you stored, just run something like:
Note that only ticks are supported in local storage so period must be ‘tick’
QuantTools provides plot_ts function to plot time series data without weekend, holidays and overnight gaps. In the example below, I first retrieve the data stored above, then select the first 100 price observations and finally draw the chart.
Two things to notice: First spy is a data. table object hence the syntax above. To get a quick overview of data. table capabilities have a look at this excellent cheat sheet from DataCamp. Second the local parameter is TRUE as the data is retrieved from internal storage.
QuantTools allows to write your own trading strategy using its C++ API. I’m not going to elaborate on this as this is basically C++ code. You can refer to the Examples section on QuantTools website.
Overall I find the package extremely useful and well documented. The only missing bit is the live feed between R and IQFeed which will make the package a real end to end solution.
As usual any comments welcome.
BERT: a newcomer in the R Excel connection.
A few months ago a reader point me out this new way of connecting R and Excel. I don’t know for how long this has been around, but I never came across it and I’ve never seen any blog post or article about it. So I decided to write a post as the tool is really worth it and before anyone asks, I’m not related to the company in any way.
يقف بيرت لمجموعة أدوات إكسيل R الأساسية. It’s free (licensed under the GPL v2) and it has been developed by Structured Data LLC. في وقت كتابة النسخة الحالية من بيرت هو 1.07. ويمكن الاطلاع على مزيد من المعلومات هنا. من منظور أكثر تقنية، تم تصميم بيرت لدعم تشغيل وظائف R من خلايا جداول البيانات إكسل. In Excel terms, it’s for writing User-Defined Functions (UDFs) in R.
In this post I’m not going to show you how R and Excel interact via BERT. There are very good tutorials here, here and here. Instead I want to show you how I used BERT to build a “control tower” for my trading.
يتم إنشاء إشارات التداول الخاصة بي باستخدام قائمة طويلة من الملفات R ولكن أنا بحاجة إلى مرونة إكسيل لعرض النتائج بسرعة وكفاءة. كما هو مبين أعلاه بيرت يمكن أن تفعل هذا بالنسبة لي ولكن أريد أيضا أن خياط التطبيق لاحتياجاتي. من خلال الجمع بين قوة شمل، فبا، R و بيرت يمكنني إنشاء تطبيق جيد حتى الآن قوية في شكل ملف إكسيل مع الحد الأدنى من التعليمات البرمجية فبا. Ultimately I have a single Excel file gathering all the necessary tasks to manage my portfolio: database update, signal generation, orders submission etc… My approach could be broken down in the 3 steps below:
Use XML to build user defined menus and buttons in an Excel file. القوائم المذكورة أعلاه وأزرار هي أساسا يدعو إلى وظائف فبا. تلك الوظائف فبا هي التفاف حول وظائف R المعرفة باستخدام بيرت.
With this approach I can keep a clear distinction between the core of my code kept in R, SQL and Python and everything used to display and format results kept in Excel, VBA & XML. في الأقسام التالية أقدم الشرط الأساسي لتطوير مثل هذا النهج ودليل خطوة بخطوة يوضح كيف يمكن استخدام بيرت لمجرد تمرير البيانات من R إلى إكسيل مع الحد الأدنى من التعليمات البرمجية فبا.
1 & # 8211؛ Download and install BERT from this link . بمجرد اكتمال التثبيت يجب أن يكون لديك قائمة الوظائف الإضافية الجديدة في إكسيل مع الأزرار كما هو موضح أدناه. هذه هي الطريقة التي تحققت بيرت في إكسيل.
2 & # 8211؛ Download and install Custom UI editor : The Custom UI Editor allows to create user defined menus and buttons in Excel ribbon. A step by step procedure is available here.
1 & # 8211؛ R Code: The below R function is a very simple piece of code for illustration purposes only. ويحسب ويعيد البقايا من الانحدار الخطي. هذا هو ما نريد استرداد في إكسيل. حفظ هذا في ملف يسمى myRCode. R (أي اسم آخر على ما يرام) في دليل من اختيارك.
2 & # 8211؛ functions. R in BERT : From Excel select Add-Ins -> Home Directory and open the file called functions. R . في هذا الملف قم بلصق التعليمة البرمجية التالية. تأكد من إدراج المسار الصحيح.
هذا هو مجرد مصادر في بيرت ملف R قمت بإنشائه أعلاه. ثم حفظ وإغلاق الملف functions. R. Should you want to make any change to the R file created in step 1 you will have to reload it using the BERT button “Reload Startup File” from the Add-Ins menu in Excel.
3 & # 8211؛ In Excel: Create and save a file called myFile. xslm (any other name is fine). هذا هو ملف تمكين ماكرو الذي تقوم بحفظه في الدليل الذي تختاره. مرة واحدة يتم حفظ الملف إغلاقه.
4 & # 8211؛ Open the file created above in Custom UI editor : Once the file is open, paste the below code.
You should have something like this in the XML editor:
Essentially this piece of XML code creates an additional menu (RTrader), a new group (My Group) and a user defined button (New Button) in the Excel ribbon. Once you’re done, open myFile. xslm in Excel and close the Custom UI Editor. يجب أن نرى شيئا من هذا القبيل.
5 & # 8211؛ Open VBA editor : In myFile. xlsm insert a new module. قم بلصق التعليمة البرمجية أدناه في الوحدة النمطية التي تم إنشاؤها حديثا.
يؤدي ذلك إلى محو النتائج السابقة في ورقة العمل قبل التعامل مع نتائج جديدة.
6 & # 8211؛ Click New Button : Now go back to the spreadsheet and in the RTrader menu click the “New Button” زر. يجب أن تشاهد شيئا مثل ما يظهر أدناه.
الدليل أعلاه هو نسخة أساسية جدا من ما يمكن تحقيقه باستخدام بيرت لكنه يظهر لك كيفية الجمع بين قوة عدة أدوات محددة لبناء التطبيق المخصص الخاص بك. من وجهة نظري مصلحة هذا النهج هو القدرة على الغراء معا R و إكسيل الواضح ولكن أيضا لتشمل عن طريق شمل (والدفعة) قطعة من التعليمات البرمجية من بايثون، سكل وأكثر من ذلك. هذا هو بالضبط ما كنت بحاجة إليه. Finally I would be curious to know if anyone has any experience with BERT?
Trading strategy: Making the most of the out of sample data.
When testing trading strategies a common approach is to divide the initial data set into in sample data: the part of the data designed to calibrate the model and out of sample data: the part of the data used to validate the calibration and ensure that the performance created in sample will be reflected in the real world. As a rule of thumb around 70% of the initial data can be used for calibration (i. e. in sample) and 30% for validation (i. e. out of sample). ثم تساعد مقارنة البيانات داخل وخارج العينة على تحديد ما إذا كان النموذج قويا بما فيه الكفاية. ويهدف هذا المنصب إلى المضي قدما خطوة أخرى ويوفر طريقة إحصائية لتقرير ما إذا كان خارج العينة البيانات يتماشى مع ما تم إنشاؤه في العينة.
في الرسم البياني أدناه تمثل المنطقة الزرقاء خارج أداء العينة لأحد استراتيجياتي.
A simple visual inspection reveals a good fit between the in and out of sample performance but what degree of confidence do I have in this? At this stage not much and this is the issue. والمطلوب حقا هو مقياس للتشابه بين مجموعات البيانات داخل وخارج العينة. ومن الناحية الإحصائية، يمكن ترجمة ذلك على أنه احتمال أن تأتي أرقام أداء العينة وخارجها من نفس التوزيع. هناك اختبار إحصائي غير بارامتري الذي يفعل بالضبط هذا: اختبار كروسكال واليس. A good definition of this test could be found on R-Tutor “A collection of data samples are independent if they come from unrelated populations and the samples do not affect each other. Using the Kruskal-Wallis Test , we can decide whether the population distributions are identical without assuming them to follow the normal distribution.” The added benefit of this test is not assuming a normal distribution.
وتوجد اختبارات أخرى من نفس الطبيعة يمكن أن تتلاءم مع هذا الإطار. اختبار مان-ويتني-ويلكوكسون أو اختبارات كولموغوروف-سميرنوف يناسب تماما الإطار يصف هنا ولكن هذا خارج نطاق هذه المقالة لمناقشة إيجابيات وسلبيات كل من هذه الاختبارات. A good description along with R examples can be found here.
Here’s the code used to generate the chart above and the analysis:
In the example above the in sample period is longer than the out of sample period therefore I randomly created 1000 subsets of the in sample data each of them having the same length as the out of sample data. ثم اختبرت كل عينة فرعية في مقابل عينة من البيانات وسجلت قيم p. هذه العملية لا تخلق قيمة P واحدة لاختبار كروسكال واليس ولكن التوزيع يجعل التحليل أكثر قوة. في هذا المثال يكون متوسط قيم p أعلى بكثير من الصفر (0.478) مما يشير إلى أنه يجب قبول الفرضية الصفرية: فهناك أدلة قوية على أن البيانات داخل وخارج العينة تأتي من نفس التوزيع.
كالمعتاد ما هو عرض في هذا المنصب هو مثال لعبة أن خدوش فقط على سطح المشكلة ويجب أن تكون مصممة لتلبية الاحتياجات الفردية. ومع ذلك أعتقد أنه يقترح إطارا إحصائيا للاهتمام والعقلاني لتقييم نتائج العينة.
This post is inspired by the following two papers:
Vigier Alexandre, Chmil Swann (2007), “Effects of Various Optimization Functions on the Out of Sample Performance of Genetically Evolved Trading Strategies”, Forecasting Financial Markets Conference.
Vigier Alexandre, Chmil Swann (2018), « An optimization process to improve in/out of sample consistency, a Stock Market case», JP Morgan Cazenove Equity Quantitative Conference, London October 2018.
Introducing fidlr: FInancial Data LoadeR.
fidlr is an RStudio addin designed to simplify the financial data downloading process from various providers. This initial version is a wrapper around the getSymbols function in the quantmod package and only Yahoo, Google, FRED and Oanda are supported. I will probably add functionalities over time. As usual with those things just a kind reminder: “THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND…”
How to install and use fidlr?
You can get the addin/package from its Github repository here (I will register it on CRAN later on) Install the addin. There is an excellent tutorial to install RStudio Addins here. Once the addin is installed it should appear in the Addin menu. Just chose fidlr in the menu and a window as pictured below should appear. Choose a data provider from the the Source dropdown menu. Select a date range from the Date menu Enter the symbol you wish to download in the instrument text box. To download several symbols just enter the symbols separated by commas. Use the Radio buttons to choose whether you want to download the instrument in a csv file or in the global environment. The csv file will be saved in the working directory and there will be one csv file per instrument. Press Run to get the data or Close to close down the addin.
Error messages and warnings are handled by the underlying packages (quantmod and Shiny) and can be read from the console.
This is a very first version of the project so do not expect perfection but hopefully it will get better over time. Please report any comment, suggestion, bug etc… to: thertrader@gmail.
Maintaining a database of price files in R.
Doing quantitative research implies a lot of data crunching and one needs clean and reliable data to achieve this. ما هو مطلوب حقا هو البيانات النظيفة التي يمكن الوصول إليها بسهولة (حتى من دون اتصال بالإنترنت). وكانت الطريقة الأكثر فعالية للقيام بذلك بالنسبة لي للحفاظ على مجموعة من ملفات كسف. من الواضح أن هذه العملية يمكن التعامل معها في نواح كثيرة ولكن وجدت العمل الإضافي فعالة جدا وبسيطة للحفاظ على الدليل حيث يمكنني تخزين وتحديث ملفات كسف. لدي ملف كسف واحد لكل أداة ويسمى كل ملف بعد الصك أنه يحتوي على. The reason I do so is twofold: First, I don’t want to download (price) data from Yahoo, Google etc… every time I want to test a new idea but more importantly once I identified and fixed a problem, I don’t want to have to do it again the next time I need the same instrument. بسيطة لكنها فعالة جدا حتى الآن. يتم تلخيص العملية في الرسم البياني أدناه.
في كل ما يلي، أفترض أن البيانات تأتي من ياهو. The code will have to be amended for data from Google, Quandl etc… In addition I present the process of updating daily price data. سيكون الإعداد مختلفا عن بيانات التردد الأعلى والنوع الآخر من مجموعات البيانات (أي مختلف عن الأسعار).
1 & # 8211؛ Initial data downloading (listOfInstruments. R & historicalData. R)
The file listOfInstruments. R is a file containing only the list of all instruments.
If an instrument isn’t part of my list (i. e. no csv file in my data folder) or if you do it for the very first time you have to download the initial historical data set. المثال أدناه ينزل مجموعة من صناديق المؤشرات المتداولة يوميا من ياهو فينانس إلى يناير 2000 وتخزين البيانات في ملف كسف.
2 & # 8211؛ Update existing data (updateData. R)
The below code starts from existing files in the dedicated folder and updates all of them one after the other. I usually run this process everyday except when I’m on holiday. لإضافة أداة جديدة، ببساطة تشغيل الخطوة 1 أعلاه لهذا الصك وحده.
3 & # 8211؛ Create a batch file (updateDailyPrices. bat)
Another important part of the job is creating a batch file that automates the updating process above (I’m a Windows user). This avoids opening R/RStudio and run the code from there. The code below is placed on a. bat file (the path has to be amended with the reader’s setup). Note that I added an output file (updateLog. txt) to track the execution.
العملية المذكورة أعلاه بسيطة للغاية لأنها تصف فقط كيفية تحديث بيانات الأسعار اليومية. I’ve been using this for a while and it has been working very smoothly for me so far. For more advanced data and/or higher frequencies, things can get much trickier.
As usual any comments welcome.
The Rise of the Robots (Advisors…)
The Asset Management industry is on the verge of a major change. على مدى العامين الماضيين ظهرت الروبوتات المستشارين (را) لاعبين جدد. المصطلح نفسه يصعب تعريفه لأنه يشمل مجموعة كبيرة ومتنوعة من الخدمات. Some are designed to help traditional advisers to better allocate their clients money and some are real “black box”. The user enter a few criteria (age , income, children etc…) and the robot proposes a tailor-made allocation. Between those two extremes a full range of offers is available. لقد وجدت تعريف ويكيبيديا جيدة جدا. “They are a class of financial adviser that provides portfolio management online with minimal human intervention”. More precisely they use algorithm-based portfolio management to offer the full spectrum of services a traditional adviser would offer: dividend reinvesting, compliance reports, portfolio rebalancing, tax loss harvesting etc… (well this is what the quantitative investment community is doing for decades!). هذه الصناعة لا تزال في مهدها مع معظم اللاعبين لا تزال تدير كمية صغيرة من المال ولكن أدركت فقط مدى عميق كان التغيير عندما كنت في مدينة نيويورك قبل بضعة أيام. When RA get their names on TV adds or on the roof of NYC cab you know something big is happening…
it is getting more and more attention from the media and above all it makes a lot of sense from an investor perspective. There are actually two main advantages in using RA:
Significantly lower fees over traditional advisers Investment is made more transparent and simpler which is more appealing to people with limited financial knowledge.
In this post R is just an excuse to present nicely what is a major trend in the asset management industry. The chart below shows the market shares of most popular RA as of the end of 2018. The code used to generate the chart below can be found at the end of this post and the data is here.
هذه الأرقام هي مؤرخة قليلا نظرا لمدى سرعة هذه الصناعة تتطور ولكن لا تزال مفيدة للغاية. Not surprisingly the market is dominated by US providers like Wealthfront and Betterment but RA do emerge all over the world: Asia (8Now!), Switzerland (InvestGlass), France (Marie Quantier)….. It is starting to significantly affect the way traditional asset managers are doing business. ومن الأمثلة البارزة على ذلك الشراكة بين "الإخلاص" و "بيترمنت". Since December 2018 Betterment past the $2 billion AUM mark.
على الرغم من كل ما سبق، أعتقد أن التغيير الحقيقي هو أمامنا. ولأنهم يستخدمون وسطاء أقل ومنتجات عمولة منخفضة (مثل صناديق الاستثمار المتداولة)، فإنهم يتقاضون رسوما أقل بكثير من الرسوم التي يحصل عليها المستشارون التقليديون. RA will certainly gain significant market shares but they will also lowers fees charged by the industry as a whole. في نهاية المطاف سوف تؤثر على طريقة الشركات الاستثمارية التقليدية القيام بأعمال تجارية. إدارة محفظة النشطة التي تواجه وقتا صعبا لبعض سنوات الآن سوف تعاني أكثر من ذلك. إن الرسوم المرتفعة التي تتكبدها ستكون أكثر صعوبة لتبريرها ما لم تعيد اختراع نفسها. ومن الآثار المحتملة الأخرى ارتفاع صنادیق الاستثمار المتداولة والمنتجات المالیة منخفضة العمولات بشکل عام. ومن الواضح أن هذا قد بدأ منذ فترة ولكنني أعتقد أن التأثير سيكون أكثر وضوحا في السنوات المقبلة. وتتبع الأجيال الجديدة لصناديق الاستثمار المتداولة مؤشرات أكثر تعقيدا واستراتيجيات مخصصة. وسيزداد حتما هذا الاتجاه.
As usual any comments welcome.
R financial time series tips everyone should know about.
There are many R time series tutorials floating around on the web this post is not designed to be one of them. بدلا من ذلك أريد أن أعرض قائمة من الحيل الأكثر فائدة جئت عبر التعامل مع سلسلة الوقت المالي في R. بعض من الوظائف المقدمة هنا قوية بشكل لا يصدق ولكن للأسف دفن في الوثائق وبالتالي رغبتي في إنشاء وظيفة مخصصة. أنا فقط عنوان اليومية أو أقل تردد مرات سلسلة. يتطلب التعامل مع البيانات ذات التردد العالي أدوات محددة: حزم البيانات أو حزم التردد العالي هي بعض منها.
xts : The xts package is the must have when it comes to times series in R. The example below loads the package and creates a daily time series of 400 days normaly distributed returns.
merge. xts (package xts): This is incredibly powerful when it comes to binding two or more times series together whether they have the same length or not. The join argument does the magic! it determines how the binding is done.
apply. yearly/apply. monthly (package xts): Apply a specified function to each distinct period in a given time series object. The example below calculates monthly and yearly returns of the second series in the tsInter object. Note that I use the sum of returns (no compounding)
endpoints (package xts): Extract index values of a given xts object corresponding to the last observations given a period specified by on. يعطي المثال اليوم الأخير من الشهر إرجاع لكل سلسلة في كائن تسينتر باستخدام نقطة النهاية لتحديد التاريخ.
na. locf (حزمة حديقة الحيوان): وظيفة عامة لاستبدال كل نا مع أحدث غير نا قبل ذلك. Extremely useful when dealing with a time series with a few “holes” and when this time series is subsequently used as input for an R functions that does not accept arguments with NAs. في المثال أنا إنشاء سلسلة زمنية من أسعار عشوائية ثم يتضمن مصطنع عدد قليل من المنظمات غير الحكومية في ذلك واستبدالها مع أحدث قيمة.
charts. PerformanceSummary (باكيج بيرفورمانساناليتيكش): بالنسبة لمجموعة من العوائد، قم بإنشاء مخطط مؤشر الثروة، أشرطة لأداء كل فترة، والمخطط تحت الماء للتخفيض. هذا مفيد بشكل لا يصدق كما أنه يعرض على نافذة واحدة جميع المعلومات ذات الصلة لفحص بصري سريع لاستراتيجية التداول. المثال أدناه يتحول سلسلة الأسعار إلى كائن شتس ثم يعرض نافذة مع 3 المخططات المذكورة أعلاه.
القائمة أعلاه ليست بأي حال من الأحوال شاملة ولكن بمجرد السيطرة على وظائف تصف في هذا المنصب فإنه يجعل التلاعب من سلسلة الوقت المالي أسهل كثيرا، رمز أقصر وقراءة من التعليمات البرمجية بشكل أفضل.
As usual any comments welcome.
Factor Evaluation in Quantitative Portfolio Management.
When it comes to managing a portfolio of stocks versus a benchmark the problem is very different from defining an absolute return strategy. في السابق يجب أن تعقد المزيد من الأسهم مما كانت عليه في وقت لاحق حيث لا يمكن الاحتفاظ بأي أسهم على الإطلاق إذا لم تكن هناك فرصة جيدة بما فيه الكفاية. والسبب في ذلك هو خطأ التتبع. ويعرف هذا على أنه الانحراف المعياري لعائد المحفظة مطروحا منه العائد المرجعي. وكلما قلت المخزونات مقابل مقياس مرجعي كلما زاد خطأ التتبع (مثل ارتفاع المخاطر).
The analysis that follows is largely inspired by the book “Active Portfolio Management” by Grinold & Kahn. هذا هو الكتاب المقدس لأي شخص مهتم في تشغيل محفظة ضد المعيار. وأنا أشجع بقوة أي شخص لديه مصلحة في هذا الموضوع لقراءة الكتاب من البداية إلى النهاية. It’s very well written and lays the foundations of systematic active portfolio management (I have no affiliation to the editor or the authors).
Here we’re trying to rank as accurately as possible the stocks in the investment universe on a forward return basis. العديد من الناس جاءوا مع العديد من الأدوات و تم تطوير عدد لا يحصى من تلك الأدوات لتحقيق ذلك. في هذا المنصب، أركز على مقياسين بسيطين ومستخدمين على نطاق واسع: معامل المعلومات (إيك) وعائد الكميات (ريال قطري).
The IC gives an overview of the factor forecasting ability. More precisely, this is a measure of how well the factor ranks the stocks on a forward return basis. The IC is defined as the rank correlation ( ρ ) between the metric (e. g. factor) and the forward return. In statistical terms the rank correlation is a nonparametric measure of dependance between two variables. For a sample of size n , the n raw scores are converted to ranks , and ρ is computed from:
The horizon for the forward return has to be defined by the analyst and it’s a function of the strategy’s turnover and the alpha decay (this has been the subject of extensive research). من الواضح أن المراآز يجب أن تكون على أعلى مستوى ممكن من حيث القيمة المطلقة.
For the keen reader, in the book by Grinold & Kahn a formula linking Information Ratio (IR) and IC is given: with breadth being the number of independent bets (trades). وتعرف هذه الصيغة بالقانون الأساسي للإدارة الفعالة. المشكلة هي أنه في كثير من الأحيان، وتحديد اتساع بدقة ليست سهلة كما يبدو.
In order to have a more accurate estimate of the factor predictive power it’s necessary to go a step further and group stocks by quantile of factor values then analyse the average forward return (or any other central tendency metric) of each of those quantiles. فائدة هذه الأداة هي واضحة. يمكن أن يكون لعامل إيك جيد ولكن قد تنحصر قدرته التنبؤية على عدد قليل من الأسهم. This is not good as a portfolio manager will have to pick stocks within the entire universe in order to meet its tracking error constraint. وتتميز عودة الكميات الجيدة بعلاقة رتيبة بين الكميات الفردية والعوائد الآجلة.
All the stocks in the S&P500 index (at the time of writing). Obviously there is a survival ship bias: the list of stocks in the index has changed significantly between the start and the end of the sample period, however it’s good enough for illustration purposes only.
The code below downloads individual stock prices in the S&P500 between Jan 2005 and today (it takes a while) and turns the raw prices into return over the last 12 months and the last month. الأول هو عاملنا، وسيتم استخدام هذا الأخير كمقياس العودة إلى الأمام.
وفيما يلي رمز لحساب معامل المعلومات وعودة الكميات. Note that I used quintiles in this example but any other grouping method (terciles, deciles etc…) can be used. فإنه يعتمد حقا على حجم العينة، ما تريد التقاط والطقس تريد أن يكون لمحة عامة أو التركيز على ذيول التوزيع. ولتقدير العائدات في كل خمسية، استخدم الوسيط كمقدر للنزعة المركزية. هذا المقياس أقل حساسية بكثير من القيم المتطرفة من الوسط الحسابي.
وأخيرا رمز لإنتاج الرسم البياني كوانتيز ريتورن.
3 & # 8211؛ How to exploit the information above?
In the chart above Q1 is lowest past 12 months return and Q5 highest. There is an almost monotonic increase in the quantiles return between Q1 and Q5 which clearly indicates that stocks falling into Q5 outperform those falling into Q1 by about 1% per month. This is very significant and powerful for such a simple factor (not really a surprise though…). لذلك هناك فرص أكبر للتغلب على المؤشر من خلال زيادة الوزن للأسهم المتساقطة في Q5 وتخفيض الوزن لتلك التي تقع في الربع الأول بالنسبة إلى المؤشر المعياري.
An IC of 0.0206 might not mean a great deal in itself but it’s significantly different from 0 and indicates a good predictive power of the past 12 months return overall. يمكن تقييم اختبارات الأهمية الرسمية ولكن هذا خارج نطاق هذه المقالة.
The above framework is excellent for evaluating investments factor’s quality however there are a number of practical limitations that have to be addressed for real life implementation:
Rebalancing : In the description above, it’s assumed that at the end of each month the portfolio is fully rebalanced. وهذا يعني أن جميع الأسهم التي تندرج في الربع الأول من هذا العام تعاني من نقص الوزن، وأن جميع الأسهم التي تندرج في Q5 هي زيادة في الوزن مقارنة بالمؤشر المعياري. This is not always possible for practical reasons: some stocks might be excluded from the investment universe, there are constraints on industry or sector weight, there are constraints on turnover etc… Transaction Costs : This has not be taken into account in the analysis above and this is a serious brake to real life implementation. وعادة ما يتم تنفيذ اعتبارات دوران في الحياة الحقيقية في شكل عقوبة على جودة عامل. Transfer coefficient : This is an extension of the fundamental law of active management and it relaxes the assumption of Grinold’s model that managers face no constraints which preclude them from translating their investments insights directly into portfolio bets.
And finally, I’m amazed by what can be achieved in less than 80 lines of code with R…
As usual any comments welcome.
Risk as a “Survival Variable”
I come across a lot of strategies on the blogosphere some are interesting some are a complete waste of time but most share a common feature: people developing those strategies do their homework in term of analyzing the return but much less attention is paid to the risk side its random nature. I’ve seen comment like “a 25% drawdown in 2018 but excellent return overall”. Well my bet is that no one on earth will let you experience a 25% loss with their money (unless special agreements are in place). In the hedge fund world people have very low tolerance for drawdown. Generally, as a new trader in a hedge fund, assuming that you come with no reputation, you have very little time to prove yourself. You should make money from day 1 and keep on doing so for a few months before you gain a bit of credibility.
First let’s say you have a bad start and you lose money at the beginning. With a 10% drawdown you’re most certainly out but even with a 5% drawdown the chances of seeing your allocation reduced are very high. This has significant implications on your strategies. Let’s assume that if you lose 5% your allocation is divided by 2 and you come back to your initial allocation only when you passed the high water mark again (e. g. the drawdown comes back to 0). In the chart below I simulated the experiment with one of my strategies.
You start trading in 1st June 2003 and all goes well until 23rd Jul. 2003 where your drawdown curve hits the -5% threshold (**1**). Your allocation is cut by 50% and you don’t cross back the high water mark level until 05th Dec. 2003 (**3**). If you have kept the allocation unchanged, the high water mark level would have been crossed on 28th Oct. 2003 (**2**) and by the end of the year you would have made more money.
But let’s push the reasoning a bit further. Still on the chart above, assume you get really unlucky and you start trading toward mid-June 2003. You hit the 10% drawdown limit by the beginning of August and you’re most likely out of the game. You would have started in early August your allocation would not have been cut at all and you end up doing a good year in only 4 full months of trading. In those two examples nothing has changed but your starting date….
The trading success of any individual has some form of path dependency and there is not much you can do about it. However you can control the size of a strategy’s drawdown and this should be addressed with great care. A portfolio should be diversified in every possible dimension: asset classes, investment strategies, trading frequencies etc…. From that perspective risk is your “survival variable”. If managed properly you have a chance to stay in the game long enough to realise the potential of your strategy. Otherwise you won’t be there next month to see what happens.
Comments
Post a Comment