Quantstrat forex ซื้อขาย


ใช้ quantstrat เพื่อประเมินกลยุทธ์การซื้อขายในวันนี้ รุ่นนี้: 1 การใช้ quantstrat เพื่อประเมินกลยุทธ์การซื้อขายในวันนี้เวอร์ชัน: 2 สารบัญการสร้างกลยุทธ์ R tools กลยุทธ์ Luxor: การใช้งานง่ายพารามิเตอร์การเพิ่มประสิทธิภาพการควบคุมออกและการบริหารความเสี่ยง Walk forward analysis ภาคผนวก 3 ภาพรวม Richard Feynman กล่าวว่าวิทยาศาสตร์เป็นกระบวนการแรกที่คาดเดา (การสร้างแบบจำลอง) และในที่สุดก็ยืนยันหรือปฏิเสธเดาด้วยการทดลอง ทำไมเราทำผลงานย้อนหลังเราหวังว่าจะบรรลุอะไรเครื่องมืออะไรที่เราใช้สร้างวิธีการทางวิทยาศาสตร์สมมติฐานที่ขับเคลื่อนด้วยกลยุทธ์เชิงปริมาณ 4 การสร้างกลยุทธ์: ไอเดียช่องทางสร้างแนวคิดการทดสอบสมมุติฐานของคุณในแพลตฟอร์มการวิจัย (R ข้อมูลย้อนหลัง (เช่นรอยเตอร์)) ปรับแต่งหากมีแนวโน้ม (หรือความคิดใหม่แนะนำตัวเองในระหว่างการทดสอบ) ปฏิเสธได้อย่างรวดเร็วหากไม่ได้มีแนวโน้มมากเกินไปส่วนใหญ่ (90) ของแนวคิดจะไม่ทำงานออกประสิทธิภาพการทำงานของพารามิเตอร์และเดินไปข้างหน้าการทดสอบการเพิ่มประสิทธิภาพเมื่อคุณมีรูปแบบการวิจัยที่น่าเชื่อถือ (รหัส quantstrat ของคุณ) สำหรับไอเดียการนำเสนอการผลิตในยุทธศาสตร์ Out 5 Strategy Creation การทดสอบผลิตภัณฑ์การทดสอบผลิตภัณฑ์อาจทำได้ทั้งก่อนและหลังการผลิตโดยระบุสมมติฐานเกี่ยวกับกลไกการทำงานของกลยุทธ์ กลยุทธ์ของคุณทำเงินสร้างรายการเครื่องมือที่อาจขึ้นกับวิธีการเดียวกันของเครื่องมือทดสอบการดำเนินการเริ่มต้นด้วยพารามิเตอร์มาตรฐานหรือช่วงพารามิเตอร์ทำงานได้อย่างไร Parameter Robustness และ Walk Forward Optimisation บนเนื้อหาที่มีแนวโน้มสร้างเครื่องมือใหม่ในการผลิต 6 Strategy Improvement กระบวนการไม่มีกลยุทธ์จะทำจนกว่าคุณจะปิดการเก็บรวบรวมความคิดในการปรับปรุงกลยุทธ์การปรับแต่งสมมติฐานจากความคิดระบุการทดสอบที่จะแสดงการปรับปรุงตามสมมติฐานระบุเกณฑ์ความสำเร็จสำหรับการวัดผลลัพธ์สมมติฐานการปรับปรุงรหัสในการดำเนินงานการอ้างอิงของกลยุทธ์การเพิ่มประสิทธิภาพมาตรฐานใน เครื่องมือที่ใช้ในปัจจุบันมีการซื้อขายในยุทธศาสตร์ประเมินผลการปฏิบัติงาน: ถ้าประสิทธิภาพของตัวอย่างดีขึ้นการเปลี่ยนแปลงรหัสที่จะนำไปสู่การผลิตกำหนดสมมติฐานระบุการทดสอบใช้การทดสอบประสิทธิภาพดีขึ้นใช่นำไปใช้กับยุทธศาสตร์ No 7 เครื่องมือ R เราจะทำแบบจำลองการค้า 8 สิ่งนี้ได้อย่างไร โซ่เครื่องมือ M anage ข้อมูลประเมินข้อมูลกำหนดขนาดธุรกิจโดยรวมคำนวณประสิทธิภาพการวิเคราะห์ประสิทธิภาพระบุรายละเอียดของสัญญาคำนวณผลตอบแทนและความเสี่ยงการจับภาพการซื้อขายเปรียบเทียบกับ benchmarks คำนวณตำแหน่งให้ระบุการคำนวณ PampL วิเคราะห์ความเสี่ยงประเภทของกิจกรรมเชื่อมต่อกับฐานข้อมูลคำนวณตัวชี้วัดค่า pretrade การกำหนดราคา Optimize portfolio ดาวน์โหลดข้อมูลย้อนหลัง การคาดการณ์ผลตอบแทนความเสี่ยงด้านงบประมาณความผันผวนโดยประมาณความเสี่ยงในการพยากรณ์ความสะอาดและจัดเรียงข้อมูลราคาและตัวชี้วัดกราฟคำนวณปริมาตรต่อท้ายการประเมินกฎการสร้างสัญญาณคำนวณตำแหน่งเป้าหมายคำนวณขนาดการค้าประเมินต้นทุนการค้ารวมผลงานตัวอย่าง R แพคเกจการทำดัชนี quantmod RTAQ xts. TTR signalextraction urca quantstrat quantmod LSPM PortfolioAnalytics parma blotter ผลการดำเนินงานของเครื่องมือทางการเงิน Analytics 9 ตัวบ่งชี้ปริมาณข้อมูลสัญญาณหลักเกณฑ์ - มูลค่าเชิงปริมาณที่ได้จากข้อมูลตลาด - ใช้ในรูปแบบเวกเตอร์หรือสตรีมมิ่ง - คาดว่าจะสามารถคำนวณได้ในรูปแบบของ pathindependent - ไม่มีความรู้เกี่ยวกับตำแหน่งปัจจุบันหรือธุรกิจการค้า - ตัวอย่าง: ค่าเฉลี่ยเคลื่อนที่ค่าความผันผวน RSI MACD ช่องสัญญาณตัวชี้วัดทางเทคนิค - อธิบายการทำงานร่วมกันระหว่างข้อมูลการตลาดและตัวบ่งชี้ - อธิบายถึงความต้องการที่เป็นไปได้สำหรับการดำเนินการ แต่อาจไม่สามารถดำเนินการได้ - ใช้ในรูปแบบที่เป็นรูปแบบหรือสตรีมมิ่ง แจ้งการตัดสินใจของกฎตัวอย่าง: Crossovers, Thresholds, Multiples - ประเมินค่าในรูปแบบที่ขึ้นอยู่กับเส้นทาง - มีข้อมูลตลาดทั้งหมดก่อนที่จะมีการสังเกตการณ์ในปัจจุบัน - ทราบตำแหน่งปัจจุบันในเวลาที่ทำการประเมินผล - สร้างคำสั่งเข้าออกและจัดการความเสี่ยง - พฤษภาคม ป้อนคำสั่งซื้อใหม่หรือแก้ไขใบสั่งซื้อที่มีอยู่ - ประเภท: รายการทางออกความเสี่ยงการถ่วงดุล Chain Des ใช้กลยุทธ์เชิงปริมาณจริงที่ความถี่ทั้งหมดกลยุทธ์จำนวนมากอาจถูกสร้างขึ้นจากส่วนประกอบโอเพนซอร์สทั้งหมดกลยุทธ์ที่เป็นกรรมสิทธิ์เพิ่มตัวบ่งชี้ที่กำหนดเองฟังก์ชั่นสัญญาณสั่งซื้อขนาดลอจิก 10 การติดตั้งเครื่องวัดปริมาณซิลิคอนพัลซิ่ง quantrat ไม่ได้ (ยัง) ใช้ได้ใน cran รายชื่อผู้รับจดหมาย: 11 กลยุทธ์ Luxor การใช้งานง่ายดู: ระบบการซื้อขาย: แนวทางใหม่ในการพัฒนาระบบและการเพิ่มประสิทธิภาพผลงานโดย Emilio Tomasini เมือง Jaekle - Harriman House London ISBN (s) 12 เกี่ยวกับโค้ดอย่าตัดและวางโค้ดจากสไลด์เหล่านี้รหัสปัจจุบันสำหรับฟังก์ชันเหล่านี้อยู่ในพื้นที่เก็บข้อมูลของแพคเกจใน R-Forge การสาธิต luxor จะถูกเก็บรักษาไว้ค้นหาสคริปต์ในไดเร็กทอรีการสาธิต quantstrat ยังอยู่ระหว่างการพัฒนา ยังคงมีการเปลี่ยนแปลงในรูปแบบที่มีขนาดเล็ก (และบางครั้งก็ใหญ่) เพื่อให้เข้ากันได้เป็นเรื่องสำคัญ แต่เราไม่ต้องยอมเสียสละคุณสมบัติสำหรับการทำงานร่วมกัน 13 กลยุทธ์ quotLuxorquot ข้อมูลสัญลักษณ์: GBPUSD 30 นาทีข้าม OHLC ของ 2 SMA: SMA n10 (quotfastquot) SMA n30 (quotslowquot) : ยาว: ขีด จำกัด หยุดที่สูงของแถบข้าม SMA สั้น: ขีด จำกัด การหยุดที่ต่ำของแถบข้าม SMA 14 FinancialInstrument เก็บข้อมูล metadata กำหนดเครื่องมือเช่น สกุลเงิน: ต้องการสกุลเงิน (financialinstrument) (c (gbp, USD)) exchangerate (primaryidgbpusd, ticksize0.0001) หรือ exchangerate (currencyusd, countercurrencygbp, ticksize0.0001) ในสภาพแวดล้อมการผลิตคุณต้องการใช้ saveinstruments () และ loadinstruments มากที่สุด () เพื่อใช้สภาพแวดล้อมทั้งเครื่องมือของคุณอีกครั้ง 15 เรียกข้อมูลข้อมูลสัญลักษณ์ data. dir lt-r. symbols ตัวอย่างเช่นจาก lt -.to lt - getsymbols. fi (SymbolsGBPUSD, dirdata. dir, from. from, to. to) หรือ (โดยทั่วไป) setsymbollookup. fi (basedirdata. dir, SymbolsGBPUSD) getsymbols (gbpusd, from. from, to. to) หรือ (quantstratdemo) getsymbols. fi (SymbolsGBPUSD, dirsystem. file (extdata, packagequantstrat) from. from, to. to) อ็อบเจ็กต์ข้อมูล 16 xts GBPUSD gt getsymbols. fi (symbolsgbpusd, dirsystem. file (extdata, packagequantstrat) จากถึง) loading GBPUSD เราไม่ต้อง getsymbols () ทั้งหมดนี้สามารถทำได้ด้วย save () และ load () ปรับ periodicity change scale scale ปรับการจัดแนว (optional) การอ่าน GBPUSD. rda เสร็จแล้ว อ่าน GBPUSD. rda เสร็จแล้ว LT gt อ่าน GBPUSD. rda เสร็จแล้ว อ่าน GBPUSD. rda เสร็จแล้ว ข้อมูล rbinding เสร็จแล้ว 1 gbpusd gt USDUSD to. minutes30 (gbpusd) gt GBPUSD align. time (gbpusd, 1800) gt head (gbpusd) เปิดสูงต่ำสุดปิดปริมาณ: 30 00. 30. 00. 30. 00: ข้อมูลของคุณอาจแตกต่างกัน แต่การจัดรูปแบบให้สอดคล้องกับ is. ohlc () หรือ is. bbo () จาก quantmod จะทำให้ชีวิตของคุณง่ายขึ้น 17 การสร้างกลยุทธ์กลยุทธ์ใหม่ (nameluxor, storetrue) วัตถุกลยุทธ์กลยุทธ์ (storetrue) orderbook วัตถุตัวบ่งชี้กลยุทธ์ส่วนประกอบสัญญาณ paramsets กฎสร้างวัตถุ mktdata 18 วัตถุ mktdata xts สเปรดชีตกลยุทธ์ scratchpad แรก: ข้อมูลสัญลักษณ์จากผลงาน gt head (gbpusd) เปิดสูงต่ำสุดปิดปริมาณ: 01 02. 03. 04. 05. 06: ตัวบ่งชี้จะเพิ่มคอลัมน์สัญญาณจะเพิ่มคอลัมน์ผู้ใช้อาจเพิ่มคอลัมน์ 19 quantstrat ทั้งหมดของ quantstrat เป็นตัวชี้วัดแบบแยกส่วน - มูลค่าเชิงปริมาณที่ได้จากข้อมูลการตลาด - ใช้ในรูปแบบ vectorized หรือสตรีมมิ่ง - สันนิษฐานว่าสามารถ ที่จะคำนวณในรูปแบบ pathindependent - ความรู้เกี่ยวกับตำแหน่งปัจจุบันหรือธุรกิจการค้า - ตัวอย่าง: ค่าเฉลี่ยเคลื่อนที่, ความผันผวน, RSI, MACD, ช่องทางใด ๆ ตัวบ่งชี้การวิเคราะห์ทางเทคนิคสัญญาณ - อธิบายปฏิสัมพันธ์ระหว่างข้อมูลตลาดและตัวบ่งชี้ - อธิบายความปรารถนาที่เป็นไปได้สำหรับการดำเนินการ แต่ไม่สามารถดำเนินการได้ - ใช้ในรูปแบบเวกเตอร์หรือแบบสตรีมมิ่งใช้เพื่อแจ้งการตัดสินใจของกฎตัวอย่าง: Crossovers, เกณฑ์, กฎหลายรายการ - ประเมินตามเส้นทางที่กำหนดขึ้นตามเส้นทาง - มีข้อมูลตลาดทั้งหมดก่อนที่จะมีการสังเกตการณ์ในปัจจุบัน - ทราบถึงปัจจุบัน ตำแหน่งในเวลาของการประเมินผล - สร้างคำสั่งเข้าออกและการจัดการความเสี่ยง - อาจป้อนคำสั่งซื้อใหม่หรือปรับเปลี่ยนคำสั่งที่มีอยู่ - ประเภท: Entry, Exit, Ris k, Rebalance, Chain ชื่อคุณสมบัติของฟังก์ชัน quantstrat ส่วนใหญ่จะตั้งชื่อฟังก์ชันเพื่อเรียกใช้ประโยชน์จากการดำเนินการที่ล่าช้าข้อกำหนดด้านกลยุทธ์ของคุณสามารถใช้กับเครื่องมือต่างๆหรือกรอบเวลาต่างๆได้ 20 ตัวบ่งชี้ตัวบ่งชี้: การคำนวณทางคณิตศาสตร์ขึ้นอยู่กับราคาและปริมาณการรักษาความปลอดภัย (Investopedia) เช่น MA, MACD, RSI, ตัวชี้วัดที่กำหนดเองแพคเกจ TTR มีตัวบ่งชี้คลาสสิกจำนวนมาก a. o. MA, MACD, RSI เป็นต้นกลยุทธ์ที่เป็นกรรมสิทธิ์จำนวนมากใช้ตัวบ่งชี้ที่กำหนดเอง 21 quantstrat :: add. indicator () add. indicator (กลยุทธ์ luxor, ชื่อ SMA, อาร์กิวเมนต์รายการ (อ้าง x (cl (mktdata), 1), n ​​10), labelquotnfastquot ) SMA (), EMA () RSI () stoch () ข้อมูล add. indicator (กลยุทธ์ luxor, ชื่อ SMA, อาร์กิวเมนต์รายการ (อ้าง x (cl (mktdata), 1), n ​​30) labelquotnslowquot) ชื่อของตัวบ่งชี้เช่น . ตัวชี้วัด TTR ใช้วัตถุ mktdata ใช้ฟังก์ชัน Cl (): คอลัมน์แรกที่มีชื่อว่า Close quote (): ประเมินป้ายชื่อภายหลัง mktdata 22 ชื่อสัญญาณ Investopedia: เครื่องหมายโดยปกติจะใช้ตัวชี้วัดทางเทคนิคว่าเป็นเวลาที่เหมาะสมในการซื้อหรือขาย การรักษาความปลอดภัยโดยเฉพาะ Quantstrat: สัญญาณหมายถึงเวลาที่กลยุทธ์อาจต้องการดำเนินการ เช่น. (), sigclose (), sigthreshold (), sigformula () 23 quantstrat :: add. signal () add. signal (strategyluxor, namesigcrossover, อาร์กิวเมนต์รายการ (columnsc (quotnfastquot, quotnslowquot), relationshipquotgtquot), labellong) add. signal (strategyluxor, namesigcrossover รายการอาร์กิวเมนต์ (columnsc (quotnfastquot, quotnslowquot), relationshipquotltquot), labelhort) ฟังก์ชันตัวอย่าง: sigcroso () sigthreshold () sigcomparison () sigformula () sigpeak () อาร์กิวเมนต์: ความสัมพันธ์ของคอลัมน์ quotgtquot, quotltquot, quoteqquot ฯลฯ ชื่อคอลัมน์ป้ายชื่อ สถานที่ใน mktdata 24 กฎกติกามีเส้นทางขึ้นอยู่กับการเข้าถึงตลาดปัจจุบันและสถานะพอร์ตมักจะเรียกโดยกฎประเภทกฎความเสี่ยง rebalance ทางออกเข้ากฎโซ่เป็นจุดที่กลยุทธ์อาจวางหรือยกเลิกคำสั่ง 25 quantstrat :: add (กฎ, หน้าที่ที่จะใช้, รายการของอาร์กิวเมนต์สำหรับฟังก์ชันที่จะใช้ประเภทป้ายชื่อ) ฟังก์ชัน: ปกติ rulesignal () ประเภทของกฎ: ใส่, ออก, ความเสี่ยง label: แสดงในหนังสือสั่งจองถ้าไม่ใช้ rulesignal ใช้ฟังก์ชันที่มีลายเซ็นอาร์กิวเมนต์ที่คล้ายคลึงกันเพื่อใช้ประโยชน์จากการลดขนาด 26 quantstrat :: rulesignal () rulesignal (sigcollong, sigvaltrue, ordersidelong, ordertypestoplimit, preferhigh, threshold0.0005, orderqty100000 , replaceefalse) ordertypes: วงเงิน stoplimit stoptrailing ตลาด transacts ต่อไป barobs ถัดไป ค่าเริ่มต้น preferclose ภูเขาน้ำแข็งชอบ: คอลัมน์ราคาที่จะใช้ข้อมูลจากเกณฑ์เกณฑ์: เพิ่มราคา 27 add. rule () - luxor กฎรายการ add. rule (strategyluxor, namerulesignal, argumentslist (sigcollong, sigvaltrue, ordersidelong, ordertypestoplimit, preferhigh, threshold. threshold , orderqty. orderqty, replacefalse), typeenter, labelenterlong) add. rule (strategyluxor, namerulesignal, argumentslist (sigcolshort, sigvaltrue, ordersideshort, ordertypestoplimit, preferlow, threshold-threshold, orderqty-orderorder, replaceefalse), typeenter, labelentershort) stoplimit การสั่งซื้อโดยใช้ Highthreshold (ต่ำเกณฑ์) เป็นราคาที่ จำกัด เราไม่ต้องการแทนที่ใบสั่งซื้อที่รอดำเนินการใด ๆ 28 add. rule () - กฎการออก luxor add. rule (strategy. st, namerulesignal, argumentslist (sigcollong, sigvaltrue, ordersideshort, ordertypemarket , orderqtyall, TxnFees. txn. fees, replacetrue), typeexit, labelexit2long) add. rule (strategy. st, namerulesignal, argumentslist (sigcolshort, sigvaltrue, ordersidelong, ordertypemarket, orde rqtyall, marketall TxnFees เฉพาะในกฎการออก: สิ้นสุดเครื่องหมายการค้าสำหรับ tradestats () แทนที่รายการสั่งซื้อที่รอดำเนินการ (เปิด) TxnFees. txn. fees, replacetrue), typeexit, labelexit2short สลับกันใช้ methodtrade for tradestats () 29 quantstrat :: (กลยุทธ์.st, portfolio. st) 1 quot: 00: 00 GBPUSD quot It การค้า 1 quot: 30: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD quot 1 quot: 00: 00 GBPUSD quot 1 quot : 00: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD quot 1 quot: 00: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD quot 1 quot: 00: 00 GBPUSD quot 1 quot: 00: 00 GBPUSD 1.553quot 1 quot: 00:00 GBPUSD 1.553quot 1 quot: 00: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD quot 1 quot: 30: 00 GBPUSD 1.555quot 1 quot: 00: 00 GBPUSD quot 1 quot: 30:00 GBPUSD ขาดการทำธุรกรรม ณ จุดนี้อาจหมายความว่าคุณมีปัญหา 30 วัตถุ mktdata: gt view (mktdata) 31 quantstrat :: getorderbook () gt View (getOrderBook (portfolio. st) forex forexgbpusd) 32 blotter :: updateportf () updat eportf (portfolioportfolio. st, SymbolsGBPUSD, Datespaste (::, as. Date (Sys. time ()), sep)) gt วาง (::, as. date (sys. time ()), sep) 1 quot updateportf () หมายถึงหนังสือของพอร์ตโฟลิโอด้วยมาตรการทางการบัญชีต่างๆหากคุณทำงานกับข้อมูลความถี่สูงโดยทั่วไปการทำเครื่องหมายหนังสือที่ความถี่ต่ำเลือกความถี่เพื่อทำเครื่องหมายหนังสือไม่เปลี่ยนข้อมูลการค้าใด ๆ ซึ่งอาจ ยังคงเป็นความถี่สูงกว่า 35 blotter :: tradestats () gt View (t (tradeStats (forex)) tradestats () คำนวณสถิติที่เห็นได้ทั่วไปในรายงานกลยุทธ์จากหนังสือและแพลตฟอร์มการเรียกใช้การค้าถูกคำนวณโดยแบนเพื่อให้แบนสำหรับรายงานนี้ รอบการเดินทางสถิติทั้งหมดได้อธิบายไว้อย่างครบถ้วนในเอกสารประกอบ 36 blotter :: pertradestats () รวบรวมข้อมูลเกี่ยวกับการค้าแบบ flat-to-flat โดย charts. me สำหรับข้อมูลดิบแผนภูมิเหล่านี้วาดจากคุณสามารถใช้การค้าแต่ละแบบเหล่านี้ได้เช่น ป้อนยุทธศาสตร์ของคุณ 37 quantstrat :: save. strategy () บันทึกกลยุทธ์เพื่อให้เราสามารถโหลดได้ในภายหลังและเพิ่มส่วนประกอบมากขึ้นหรือใช้กับสถานการณ์ที่แตกต่างกัน save. strategy (strategy. st) ls - l luxor rdata - rw-r-r - 1 jan users 7 เม. ย. 22:53 luxor. rdata load. strategy (strategy. st) 38 quantstrat พารามิเตอร์การเพิ่มประสิทธิภาพ 39 พารามิเตอร์การเพิ่มประสิทธิภาพกลยุทธ์ทั้งหมดมีพารามิเตอร์: อะไรคือสิ่งที่ถูกต้องจำนวนมากของพารามิเตอร์ฟรี เพิ่มจำนวนของข้อมูลที่คุณต้องการลดองศาอิสระของคุณและเพิ่มโอกาสของการ overfitting แม้แต่ตัวเลือกพารามิเตอร์เริ่มต้นของคุณมีการเพิ่มประสิทธิภาพ youve เลือกค่าที่คุณเชื่อว่าอาจเพิ่มประสิทธิภาพพารามิเตอร์ที่ดีที่สุดเพียงเพิ่มกระบวนการและเครื่องมือในการตัดสินใจลงทุนของคุณ 40 พารามิเตอร์ ชุดพารามิเตอร์ชุดพารามิเตอร์เป็นส่วนหนึ่งของยุทธศาสตร์ paramset. label การกระจาย SMA ช่วง FastSMA ตั้งแต่ 1 ถึง 30 SlowSMA ในช่วง 20-80 ข้อ จำกัด FastSMA lt SlowSMA apply. paramset () เรียกใช้การสุ่มเลือกหรือ combo ทั้งหมด 41 Optimizing Luxor SMA values fastsma (1:30).SlowSMA (20:80) add. constraint (s, paramset. label SMA, distribution. label.1 nfast, load. strategy (strategy. st) distribution. label.2 nslow ผู้ดำเนินการ lt, add. distribution (strategy. st, ป้าย SMA) paramset. label SMA, ตัวบ่งชี้ component. type, save. strategy (strategy. st) component. label nfast, รายการตัวแปร (n. Fastast), nfast ป้ายชื่อ) add. distribution (strategy. st, paramset. label SMA, ตัวบ่งชี้ component. type, component. label nslow ต้องการลบรายการตัวแปร paramset นี้ (n. SlowSMA), label nslow) delete. paramset (strategy. st, SMA) 42 foreach package hybrid ของมาตรฐานสำหรับลูปและฟังก์ชัน lapply อำนวยความสะดวก parallelization ส่งกลับฟังก์ชัน valuebine เริ่มต้นรายการบางแบ็กเอนด์แบบขนาน: registerdoseq (): backend ค่าเริ่มต้น (เรียงลำดับ) domcdoparallel: CPU หลายตัวหรือแกน doredis: ข้ามแพลตฟอร์ม backend Redis server Redis workers 43 apply. paramset () ต้อง (domc) registerdomc (cores8) load. strategy (strategy. st) ผลลัพธ์ lt - apply. paramset (strategy. st, paramset. labelsma, portfolio. stportfolio. st, nsamples 80, การตรวจสอบค่า NULL, verbosetrue) print (resultstradestats ) สร้าง parambos จากการกระจายและข้อ จำกัด รันใช้ กลยุทธ์ () ในพอร์ตโฟลิโอสำหรับแต่ละพารามิเตอร์ nsamples คำสั่งผสม: ดึงการตรวจสอบการสุ่มเลือก: ชื่อไฟล์เพื่อเก็บพอร์ตการลงทุนทั้งหมดและ orderbooks 44 SMA paramset tradestats () View (t (resultstradeStats)) 45 quantstrat :: tradegraphs () แสดงกราฟทางการค้าจากสถิติ tradegraphs (stats stats, free. params c. (quotParam. indicator.1.nFastquot, quotParam. indicator.2.nSlowquot) สถิติ c (quotNet. Trading. PLquot, quotmaxdrawdownquot, quotAvg. Trade. PLquot, quotNum. Tradesquot, quotProfit. Factorquot) ชื่อ Luxor SMA Parameter Scan) สร้างการแสดงผล 3 มิติของพื้นผิวพารามิเตอร์นึกคิดกลยุทธ์จะเป็นพารามิเตอร์ที่แข็งแกร่งเรียบราบรื่นไม่มียอดมากขึ้นอยู่กับการเปลี่ยนแปลงเล็ก ๆ tradegraphs () สามารถสร้างหลายแผนภูมิด้วยการเรียกเพียงครั้งเดียวต้องใช้แพคเกจ rgl 47 ออกจากปริมาณและการบริหารความเสี่ยง 48 การสั่งซื้อ ชุดชุดประกอบด้วยหนึ่งหรือมากกว่าหนึ่งคำสั่ง OCO OCO - หนึ่งยกเลิกอื่นหากได้รับการเติมอื่น ๆ ทั้งหมดจะถูกยกเลิกการระบุด้วยแท็กชื่อของชุดคำสั่งเช่น คำสั่ง Stop-Loss คำสั่ง order-profit profit-order (. ordersetocolong.) รวมกันทั่วไปกับลำดับโซ่ 49 Order Chains rule typechain การเติมคำสั่งหนึ่งคำสั่งสร้างคำสั่งซื้อใหม่ (s) คำสั่ง parent ที่ระบุโดย quotlabelquot child orders ใช้พารามิเตอร์ quotparentquot เพื่ออ้างถึง parent รวมกับชุดคำสั่งซื้อ 50 ออร์เดอร์สแอ็กทีฟ Orderchains stop order entry order Orderchain parent orderet สั่งซื้อ chain order stop order คำสั่ง limitquot คำสั่ง stoplimit order quotstop คำจำกัดความสั่งซื้อ quotting profitquot 51 กฎสำหรับการหยุดการขาดทุน add. rule (strategy. st ชื่อ rulesignal, argumentslist (sigcollong , sigvaltrue, replaceefalse, orderidelpestoplimit, tmulttrue, thresholdquote (.stoploss), TxnFees. txnfees, orderqtyall, ordersetocolong), typechain, parententerlong, labelstoplosslong, enabledfalse) add. rule (strategy. st, rulesignal ชื่ออาร์กิวเมนต์ (sigcolshort, sigvaltrue , replaceefalse, ordersideshort, ordertypestoplimit, tmulttrue, thresholdquote (.stoploss), TxnFees. txnfees, orderqtyal ลำดับการสั่งซื้อลำดับชั้นเกณฑ์ผู้ปกครองเกณฑ์ tmult () การเปิดใช้งานการแทนที่ต้องเป็น FALSE (คำสั่งซื้อ) 52 การสั่งซื้อขนาดการจัดเรียงคำสั่งเช่นเดียวกับทุกสิ่งทุกอย่างใน quantstrat เป็นแบบโมดูลาร์ คุณสามารถเขียนฟังก์ชันการปรับขนาดการสั่งซื้อของคุณเองได้ รวมอยู่ด้วย: rulesignal () รวม osnof osnop () ไม่มีการดำเนินการค่าเริ่มต้น osmaxpos () ใช้ระดับสูงสุดตามแบบ maximums ทำงานร่วมกับ addposlimit () และ getposlimit () 53 addposlimit () amp osmaxpos () addposlimit (portfolioportfolio. st, symbolgbpusd , timestampinitdate, maxpos. orderqty แยกตำแหน่งสูงสุดออกจากกฎ) add. rule (strategy. st, rulesignal ชื่อ argumentslist (sigcollong, sigvaltrue, replaceefalse, ordersidelong, ordertypestoplimit, preferhigh) ทำให้การตัดสินใจขึ้นอยู่กับตำแหน่งปัจจุบันไม่ใช่คำสั่งซื้อที่เปิดอยู่ ), ตัวอย่างเช่นการเพิ่มประสิทธิภาพการค้าแนวทางวิธีการอ้างอิงแรงโน้มถ่วงครอบคลุมส่วนใหญ่เป็นไปได้ osmaxpos () เป็นตัวอย่าง ของพื้นที่พารามิเตอร์ทั้งหมด MAEMFE - quantgraphsquot quantiles - quotstatisticquot ใช้ข้อมูลจากการทำ backtest หรือการผลิตเพื่อการค้า evalua te หยุดการสูญเสียหรือการสั่งซื้อกำไรเพิ่มขึ้นเดินไปข้างหน้าใช้ฟังก์ชันวัตถุประสงค์เพื่อเปลี่ยนพารามิเตอร์ตลอดเวลา 55 Stop loss โดยใช้ paramsets. stoploss seq (0.05, 2.4, length. out48) 100 require (foreach) require (domc) add การแจกจ่าย (strategy. st, registerdomc (cores8) paramset. label StopLoss, component. type chain, component. label StopLossLONG, รายการตัวแปร (threshold. StopLoss), results lt - apply. paramset (strategy. st, paramset. labelstoploss, portfolio. stportfolio. st, account. staccount. st, nsamples80, verbosetrue) ป้ายกำกับ StopLossLONG plot (100resultstradestradestatsstoplosslong, statsnet. trading. pl, typeb, xlabstoploss, ylabnet. trading. pl, mainluxor)) add. distribution (strategy. st, paramset.) ป้ายชื่อ StopLoss, component. type chain, component. label StopLossSHORT, รายการตัวแปร (threshold. StopLoss), ป้าย StopLossSHORT) add. constraint (strategy. st, paramset. label StopLoss, distribution. label.1 StopLossLONG, distribution. label.2 StopLossSHORT , ผู้ดำเนินการป้าย StopLo ss) 56 หยุดการขาดทุน paramset tradestats () View (t (resultstradeStats)) 57 MAE: ทัศนคติที่ไม่พึงประสงค์สูงสุด chart. me (Portfolioforex, SymbolGBPUSD, typemae, scalepercent) ธุรกิจการค้าบนแกนเส้นทแยงมุมปิดการซื้อขายต่ำของพวกเขาบนแกนแนวตั้งประสบการณ์การเบิกไม่ Chart. ME ประเภท MAE MFE scale percentage ร้อยละเงินสด 58 MAE ใช้ 0.4 stop loss 59 MFE: Max Favorable Excursion chart. me ในรูปแบบเส้นทแยงมุมปิดการซื้อขายบนแกนสูง ไม่มีบวก PampL บรรทัดแนวนอนแสดงให้เห็นถึงอิทธิพลของการหยุดในชุดข้อมูลนี้ 60 ทำกำไรโดยใช้พล็อต paramsets (100statstakeprofitlong, statsnet. trading. pl, typeb, xlabtakeprofit, ylabnet. trading. pl, mainluxor) พล็อต (100statstakeprofitlong, statsmax drawdownl, typeb, xlabmax. drawdown, ylabmax. drawdown, mainluxor) 61 PerformanceAnalytics :: chart. Histogram gt ps lt - pertradestats (forex, symbolGBPUSD) gt chart. histogram (pspct. trading. pl, methodsc (add. normal), mainluxor อีกครั้ง เปลี่ยน) สังเกตเห็นยอด: หยุดขาดทุนทำกำไรอื่น ๆ obs: Negative skew บวกมากเกินไป kurtosis 62 blotter :: tradequantiles () gt tradequantiles (forex, SymbolGBPUSD, scalepercent, probsc (.5, .9, .99)) forex. gbpusd pospctpl 50 pospctpl 90 pospctpl 99 negpctpl 50 negpctpl 90 negpctpl 99 pospctmfe 50 pospctmfe 90 pospctmfe 99 pospctmae 50 pospctmae 90 pospctmae 99 negpctmfe 50 negpctmfe 90 negpctmfe 99 negpctmae 50 negpctmae 90 negpctmae 99 tradequantiles () คำนวณและส่งกลับสถิติสำหรับ quantiles ของบวกและลบ PampL MAE MFE MAE max line จับจุดสูงสุดของการแจกจ่าย (ด้วยการมองย้อนกลับที่สมบูรณ์แบบ) MAE max (cumPL) ตัวเลือกอื่น ๆ ได้แก่ quantiles เป็น ticks หรือ cash pampL 63 quantstrat เดินไปข้างหน้าวิเคราะห์ 64 เดินไปข้างหน้าวิเคราะห์เดินไปข้างหน้าการวิเคราะห์เป็นระยะ reparameterizes กลยุทธ์ในการผลิต จะทำรายวันรายสัปดาห์รายเดือนหรือรายไตรมาสการวิเคราะห์หน้าต่างเป็นส่วนใหญ่สมมติว่าการพัฒนาพื้นที่ทอดสมอพารามิเตอร์การวิเคราะห์สมมติว่า residu ข้อมูลจากงวดก่อนหน้าช่วยให้คุณสามารถตัดสินใจได้ตอนนี้ 65 walk. forward () ess lt-function (account. st, portfolio. st) my. obj. func lt - function (x) walk. forward (strategy. st, paramset. labelwfa, portfolio. stportfolio. st, account. staccount. st, periodmonths, k. training3, k. testing1, obj. funcmy. obj. func, obj. argslist (xquote (resultapply. paramset)), user. funcess ผู้ใช้ argslist (account. staccount. st, portfolio. stportfolio. st), audit. prefixwfa. ples, anchoredfalse) chart. posn (portfolio. st) ดู (t (tradeStats (portfolio. st))) ฟังก์ชัน paramset ระยะเวลาวัตถุประสงค์ (ทำงานบน master) ฟังก์ชั่นผู้ใช้เสริม (รันบนทาส) audit. prefix anchored 66 walk. forward () graphs chart. forward. testing (wfa. trading. pl. results. rdata) RData) chart. forward. testing (wfa. max. drawdown. ผล. 67 walk. forward () ใช้ ES เลือกฟังก์ชั่นเป้าหมายของคุณเป็นสิ่งสำคัญมากที่จะเดินไปข้างหน้าการวิเคราะห์ในกรณีนี้ฟังก์ชั่นเป้าหมายเลือกพารามิเตอร์ที่ค่อนข้างออกจากตัวอย่างที่ไม่ดีของการวิ่ง End. Eq insample สูงสุดไม่ทำงาน 68 ภาคผนวกสิ่งอื่น ๆ ที่เราอาจไม่ได้มีเวลาสำหรับความเร็ว 69 ความเร็ว: ทำให้เร็วขึ้นความเร็ว quantstrats เป็นฟังก์ชันเชิงเส้นเกือบของจำนวนการประเมินกฎซึ่งหมายความว่าคุณควรดูแลไม่ให้เพิ่มกฎที่ไม่จำเป็นคุณควรพิจารณาก่อนการประมวลผลสัญญาณของคุณ ผ่านการดำเนินการทางตรรกะและประเภทเป็นไปได้ที่จะได้รับความเร็วของนาทีหลัก 1 ต่อสัญลักษณ์ต่อวันเกี่ยวกับข้อมูลความถี่สูง 70 Analyzing ส่งกลับ quantstrat (และ blotter) การทำงานใน quotquice และ spacequot ค้าบางครั้งคุณต้องทำวิเคราะห์ใน quotreturns ฟังก์ชัน spacequot PortfReturns () (rsi) และ demo (faber) สำหรับตัวอย่างทำให้ผลตอบแทนจากการวิเคราะห์ทั้งหมดของแพคเกจเช่น PerformanceAnalytics หรือ PortfolioAnalytics มีอยู่ 71 การปรับสมดุลใหม่วิธีการจัดสรรทุนระหว่างเครื่องมือที่แตกต่างกันใน กลยุทธ์เป็นระยะ ๆ ใช้กฎการปรับสมดุลอีกครั้งรวมถึงการถ่วงดุลกฎพิเศษและรุ่นพิเศษของ applystrategy () applystrategy การปรับสมดุลใหม่ () ตัวอย่างกฎการถ่วงดุลและกฎกติกา (ruleweight) มีให้ดูตัวอย่าง (faberrebal) สำหรับการจัดสรรแบบข้ามกลยุทธ์อาจต้องใช้ PortfolioAnalytics ไม่ใช่แค่การปรับสมดุลกฎอีกต่อไป 72 งานอื่น ๆ กำลังทำงานอยู่หรือต้องการรวบรวมแอ็ปปรูลส์ เพื่อเริ่มต้นการเรียบเรียงกลยุทธ์โค้ดที่เรียบเรียงขึ้นและลดขนาดลงบนโค้ด boilerplate จะลดการทำสำเนารหัสในเช่น paramsets มอนติคาร์โลหรือแบบเบิร์นส์ลักษณะธุรกิจการค้าแบบสุ่มวิเคราะห์วัตถุประสงค์ทั่วไปสำหรับการเดินไปข้างหน้าการวิเคราะห์ Encyclopedia of Trading Strategies มีส่วนร่วมในการเขียนการสาธิตที่เราสามารถรวมไว้ในแพคเกจ 73 ข้อสรุปตามวิธีการทางวิทยาศาสตร์เพื่อ backtesting: เดาสร้างแบบทดสอบสมมติฐานของคุณผ่านการทดสอบ overfitting ยังคง อันตรายพยายามที่จะทำให้หลายสมมติฐานของคุณเป็นไปได้ชัดเจนมากกว่า backtest นัยที่ทำให้เงินให้คุณเป็นไปได้ของการทำเงินในการผลิตกับรูปแบบของคุณ backtest สูญเสียเกือบรับประกันการสูญเสียการผลิตขนาดใหญ่ 74 สรุปการสร้างกลยุทธ์ R เครื่องมือ Luxor กลยุทธ์: การใช้งานง่ายพารามิเตอร์การเพิ่มประสิทธิภาพการควบคุมและการจัดการความเสี่ยงเดินไปข้างหน้าการวิเคราะห์ภาคผนวก 75 ขอบคุณสำหรับความสนใจของคุณ Bios Jan Humme ผู้ประกอบการทางการเงินอิสระนักวิทยาศาสตร์คอมพิวเตอร์และผู้พัฒนาซอฟต์แวร์ quantstrat package coauthor Brian G. Peterson หุ้นส่วนและผู้อำนวยการฝ่ายการค้าเชิงปริมาณที่ DV Trading ในชิคาโกผู้เขียนหรือ co-au thor กว่า 10 แพคเกจ R สำหรับการเงินมักเขียนและพูดเกี่ยวกับการสร้างพอร์ตโฟลิโอและความเสี่ยง 77 ทรัพยากร R-forge r-forge. r-project. orgprojectsblotter R-SIG - การเงินรายชื่อผู้รับจดหมาย stat. ethz. chmailmanlistinfor-sig-finance บล็อก github, StackOverflow เป็นต้นเรา 78 ลิงก์ไปยังสไลด์สไลด์ล่าสุดมีอยู่ใน Google ไดรฟ์ที่นี่: docs. googlepresentationd1fgzdclffcqjkhhzaonspux1ttm1eb5hlvcedsz7zwpub โพสต์นี้จะแนะนำกลไกกลไกระยะเวลาในการตอบสนองอัตโนมัติของจอห์น Ehlers8217s ที่ออกแบบมาเพื่อค้นหาระยะเวลามองย้อนกลับแบบไดนามิก นั่นคือพารามิเตอร์ที่ใช้กันทั่วไปใน backtests คือช่วงเวลาที่มองย้อนกลับ ก่อนที่จะเริ่มโพสต์นี้ฉันต้องให้เครดิตที่ it8217s เนื่องจากหนึ่งนาย Fabrizio Maccallini หัวหน้าอนุพันธ์โครงสร้างที่ Nordea Markets ในกรุงลอนดอนกล่าว คุณสามารถค้นหาส่วนที่เหลือของพื้นที่เก็บข้อมูลที่เขาใช้สำหรับการวิเคราะห์วัฏจักรดร. John Ehlers8217s สำหรับผู้ค้าใน github ของเขา ฉันรู้สึกขอบคุณและเป็นเกียรติที่บุคคลที่ชาญฉลาดและมีประสบการณ์ดังกล่าวช่วยในการนำวิธีการของ Dr. Ehlers8217s ไปใช้เป็นส่วน ๆ ใน R. จุดการวัดความถ่วงดุลอัตโนมัติของ Ehlers คือการกำหนดระยะเวลาระหว่างความยาวขั้นต่ำและระยะเวลาสูงสุด ในขณะที่ฉันออกจากคำอธิบายที่แน่นอนของช่างซ่อมหนังสือ Dr. Ehlers8217s สำหรับความตั้งใจและเจตนาในทางปฏิบัติทั้งหมดในความคิดของฉันความคิดริเริ่มของวิธีนี้คือพยายามที่จะลบแหล่งใหญ่ของการใช้จ่ายเกินจากการสร้างระบบการซื้อขาย 821 โดยระบุช่วงเวลาที่มองย้อนกลับ SMA 50 วัน 100 วัน 200 วันอัลกอริธึมนี้ใช้ความสามารถในการเอาชนะให้พ้นมือได้ เพียงแค่ระบุขอบเขตบนและล่างสำหรับ lookback ของคุณและส่วนที่เหลือจะทำ วิธีการที่ดีมันไม่ได้เป็นหัวข้อของการสนทนาสำหรับผู้ที่รอบรู้ในวิธีการของวิศวกรรมไฟฟ้า (I8217m ไม่) จึงรู้สึกฟรีเพื่อแสดงความคิดเห็นที่หารือถึงวิธีการที่ดีขั้นตอนวิธีการทำงานของตนและรู้สึกฟรีเพื่อบล็อกเกี่ยวกับเรื่องนี้เป็น ดี. ในกรณีใด here8217s รหัสขั้นตอนเดิมมารยาทของนาย Maccallini: สิ่งหนึ่งที่ฉันจะแจ้งให้ทราบว่ารหัสนี้ใช้วงที่บอกว่าสำหรับ (i in 1: length (filt)) ซึ่งเป็น O (จุดข้อมูล) loop ซึ่งผมมองว่าเป็นโรคระบาดใน R. ในขณะที่ I8217ve ใช้ Rcpp มาก่อน it8217s ได้รับเพียงขั้นพื้นฐานที่สุดของลูปดังนั้นนี่จึงเป็นสถานที่ที่อัลกอริธึมสามารถที่จะปรับปรุงให้ดีขึ้นได้ด้วย Rcpp เนื่องจาก R8217s มีลูปดีๆโดยธรรมชาติ ผู้ที่สนใจตรรกะที่แน่นอนของอัลกอริทึมจะหาข้อมูลนี้อีกครั้งใน John Ehlers8217s Cycle Analytics สำหรับหนังสือ Traders (ดูลิงก์ก่อนหน้านี้ในโพสต์) แน่นอนสิ่งแรกที่ต้องทำคือการทดสอบว่าอัลกอริธึมทำสิ่งที่ควรทำอย่างไรซึ่งจะกำหนดระยะเวลามองย้อนกลับของอัลกอริทึม Let8217 เรียกใช้ข้อมูลบางอย่าง ตอนนี้ช่วงเวลามองย้อนกลับที่กำหนดโดยอัลกอริทึมมีลักษณะเหมือน Let8217s เมื่อปีพ. ศ. 2544 ถึงปี 2546 เมื่อตลาดผ่านช่วงกลียุค ในภาพที่ซูมเข้านี้เราจะเห็นว่าค่าประมาณของ algorithm8217s ดูไม่เป็นระเบียบ Here8217s รหัสบางส่วนเพื่อป้อนค่าประมาณ algorithm8217s ของ n เป็นตัวบ่งชี้เพื่อคำนวณตัวบ่งชี้ที่มีช่วงเวลามองย้อนกลับแบบไดนามิกตามที่กำหนดโดย periodogram อัตโนมัติสัมพันธ์ของ Ehlers8217s และนี่คือฟังก์ชันที่ใช้กับ SMA เพื่อปรับค่าระหว่าง 120 และ 252 วัน เมื่อเห็นแล้วอัลกอริทึมนี้มีความสอดคล้องน้อยกว่าที่ฉันต้องการอย่างน้อยที่สุดเมื่อใช้ค่าเฉลี่ยเคลื่อนที่แบบง่ายๆ สำหรับตอนนี้ I8217m จะปล่อยให้รหัสนี้อยู่ที่นี่และให้ทุกคนทดสอบด้วย ฉันหวังว่าบางคนจะพบว่าตัวบ่งชี้นี้เป็นประโยชน์ต่อพวกเขา ขอบคุณที่อ่าน. หมายเหตุ: ฉันสนใจเสมอในการสร้างเครือข่ายในภาคตะวันออกเฉียงเหนือ (PhiladelphiaNYC) นอกจากนี้หากคุณเชื่อว่า บริษัท ของคุณจะได้รับประโยชน์จากทักษะของฉันโปรดอย่าลังเลที่จะติดต่อฉัน สามารถดูรายละเอียด linkedin ของฉันได้ที่นี่ สุดท้ายฉันอาสาที่จะดูแลแผนก R สำหรับหนังสือเกี่ยวกับระบบควอนตัม หากคุณมีหนังสือเกี่ยวกับ R ที่สามารถนำไปใช้กับการเงินได้โปรดแจ้งให้เราทราบเพื่อที่ฉันจะได้ตรวจสอบและแนะนำให้ทำ Thakn คุณ บทความนี้จะเป็นบทวิจารณ์เชิงลึกเกี่ยวกับหนังสือ Momentum Alpha Architect8217s เชิงปริมาณ โดยรวมแล้วในความคิดของฉันหนังสือเล่มนี้เป็นเรื่องที่ยอดเยี่ยมสำหรับผู้ที่เป็นผู้ประกอบการในการจัดการกองทุนในแต่ละส่วนของทุนและยังคงมีความคิดที่น่าคิดเกี่ยวกับด้านนอกของพื้นที่นั้นด้วย อย่างไรก็ตามระบบรายละเอียดในหนังสือจะได้รับประโยชน์จากการจัดอันดับที่ซ้อนกัน (จัดเรียงตามแกน X ให้อยู่ด้านบนสุดอันดับตามแกน Y ด้านในสุดยอดใน X และใช้ด้านบนสุดตามแกน Y โดยหลักจะ จำกัด การเลือกให้เป็น 1 จักรวาล). นอกจากนี้หนังสือไม่ได้ทำมากที่จะสัมผัสกับการควบคุมความผันผวนซึ่งอาจมีการปรับปรุงระบบที่ระบุไว้อย่างมาก ก่อนที่ฉันจะเข้าสู่ความรุนแรงของโพสต์นี้ I8217d ต้องการแจ้งให้ผู้อ่านของฉันทราบว่าฉันได้กรงเล็บถั่วและสลักเกลียวของชุดข้อความ quantstrat เป็นหลักสูตรดาต้าดัมอย่างเป็นทางการ Datacamp เป็นวิธีที่ถูกมากในการเรียนรู้กลุ่ม R และการใช้งานด้านการเงินอยู่ในหัวข้อเหล่านี้ หลักสูตรของฉันครอบคลุมพื้นฐานของ quantstrat และหากผู้ที่จบหลักสูตรเช่นนั้นฉันอาจจะสร้างโมดูล quantstrat ขั้นสูงเพิ่มเติมใน datacamp I8217m หวังว่าหลักสูตรการเงินจะได้รับอย่างดีเนื่องจากมีหัวข้อทางการเงินใน R I8217d ต้องการเรียนรู้ตัวเองว่าการบรรยาย 45 นาทีไม่เพียงพอสำหรับ (เช่นดร. เดวิดแมทเธียนแปลงจุดเปลี่ยนมายากล, PortfolioAnalytics และอื่น ๆ ) ไม่ว่าในกรณีใด here8217s link So, let8217s start with a summary of the book: Part 1 is several chapters that are the giant expose - of why momentum works (or at least, has worked for at least 20 years since 1993)8230namely that human biases and irrational behaviors act in certain ways to make the anomaly work. Then there8217s also the career risk (AKA it8217s a risk factor, and so, if your benchmark is SPY and you run across a 3 year period of underperformance, you have severe career risk), and essentially, a whole litany of why a professional asset manager would get fired but if you just stick with the anomaly over many many years and ride out multi-year stretches of relative underperformance, you8217ll come out ahead in the very long run. Generally, I feel like there8217s work to be done if this is the best that can be done, but okay, I8217ll accept it. Essentially, part 1 is for the uninitiated. For those that have been around the momentum block a couple of times, they can skip right past this. Unfortunately, it8217s half the book, so that leaves a little bit of a sour taste in the mouth. Next, part two is where, in my opinion, the real meat and potatoes of the book8211the 8220how8221. Essentially, the algorithm can be boiled down into the following: Taking the universe of large and mid-cap stocks, do the following: 1) Sort the stocks into deciles by 2-12 momentum8211that is, at the end of every month, calculate momentum by last month8217s closing price minus the closing price 12 months ago. Essentially, research states that there8217s a reversion effect on the 1-month momentum. However, this effect doesn8217t carry over into the ETF universe in my experience. 2) Here8217s the interesting part which makes the book worth picking up on its own (in my opinion): after sorting into deciles, rank the top decile by the following metric: multiply the sign of the 2-12 momentum by the following equation: ( negative returns 8211 positive). Essentially, the idea here is to determine smoothness of momentum. That is, in the most extreme situation, imagine a stock that did absolutely nothing for 230 days, and then had one massive day that gave it its entire price appreciation (think Google when it had a 10 jump off of better-than-expected numbers reports), and in the other extreme, a stock that simply had each and every single day be a small positive price appreciation. Obviously, you8217d want the second type of stock. That8217s this idea. Again, sort into deciles, and take the top decile. Therefore, taking the top decile of the top decile leaves you with 1 of the universe. Essentially, this makes the idea very difficult to replicate8211since you8217d need to track down a massive universe of stocks. That stated, I think the expression is actually a pretty good idea as a stand-in for volatility. That is, regardless of how volatile an asset is8211whether it8217s as volatile as a commodity like DBC, or as non-volatile as a fixed-income product like SHY, this expression is an interesting way of stating 8220this path is choppy8221 vs. 8220this path is smooth8221. I might investigate this expression on my blog further in the future. 3) Lastly, if the portfolio is turning over quarterly instead of monthly, the best months to turn it over are the months preceding end-of-quarter month (that is, February, May, August, November) because a bunch of amateur asset managers like to 8220window dress8221 their portfolios. That is, they had a crummy quarter, so at the last month before they have to send out quarterly statements, they load up on some recent winners so that their clients don8217t think they8217re as amateur as they really let on, and there8217s a bump for this. Similarly, January has some selling anomalies due to tax-loss harvesting. As far as practical implementations go, I think this is a very nice touch. Conceding the fact that turning over every month may be a bit too expensive, I like that Wes and Jack say 8220sure, you want to turn it over once every three months, but on which months8221. It8217s a very good question to ask if it means you get an additional percentage point or 150 bps a year from that, as it just might cover the transaction costs and then some. All in all, it8217s a fairly simple to understand strategy. However, the part that sort of gates off the book to a perfect replication is the difficulty in obtaining the CRSP data. However, I do commend Alpha Architect for disclosing the entire algorithm from start to finish. Furthermore, if the basic 2-12 momentum is not enough, there8217s an appendix detailing other types of momentum ideas (earnings momentum, ranking by distance to 52-week highs, absolute historical momentum, and so on). None of these strategies are really that much better than the basic price momentum strategy, so they8217re there for those interested, but it seems there8217s nothing really ground-breaking there. That is, if you8217re trading once a month, there8217s only so many ways of saying 8220hey, I think this thing is going up8221 I also like that Wes and Jack touched on the fact that trend-following, while it doesn8217t improve overall CAGR or Sharpe, does a massive amount to improve on max drawdown. That is, if faced with the prospect of losing 70-80 of everything, and losing only 30, that8217s an easy choice to make. Trend-following is good, even a simplistic version. All in all, I think the book accomplishes what it sets out to do, which is to present a well-researched algorithm. Ultimately, the punchline is on Alpha Architect8217s site (I believe they have some sort of monthly stock filter). Furthermore, the book states that there are better risk-adjusted returns when combined with the algorithm outlined in the 8220quantitative value8221 book. In my experience, I8217ve never had value algorithms impress me in the backtests I8217ve done, but I can chalk that up to me being inexperienced with all the various valuation metrics. My criticism of the book, however, is this: The momentum algorithm in the book misses what I feel is one key component: volatility targeting control. Simply, the paper 8220momentum has its moments8221 (which I covered in my hypothesis-driven development series of posts) essentially states that the usual Fama-French momentum strategy does far better from a risk-reward strategy by deleveraging during times of excessive volatility, and avoiding momentum crashes. I8217m not sure why Wes and Jack didn8217t touch upon this paper, since the implementation is very simple (targetrealized volatility leverage factor). Ideally, I8217d love if Wes or Jack could send me the stream of returns for this strategy (preferably daily, but monthly also works). Essentially, I think this book is very comprehensive. However, I think it also has a somewhat 8220don8217t try this at home8221 feel to it due to the data requirement to replicate it. Certainly, if your broker charges you 8 a transaction, it8217s not a feasible strategy to drop several thousand bucks a year on transaction costs that8217ll just give your returns to your broker. However, I do wonder if the QMOM ETF (from Alpha Architect, of course) is, in fact, a better version of this strategy, outside of the management fee. In any case, my final opinion is this: while this book leaves a little bit of knowledge on the table, on a whole, it accomplishes what it sets out to do, is clear with its procedures, and provides several worthwhile ideas. For the price of a non-technical textbook (aka those 60 books on amazon), this book is a steal. ขอบคุณที่อ่าน. NOTE: While I am currently employed in a successful analytics capacity, I am interested in hearing about full-time positions more closely related to the topics on this blog. If you have a full-time position which can benefit from my current skills, please let me know. My Linkedin can be found here. This post will be about attempting to use the Depmix package for online state prediction. While the depmix package performs admirably when it comes to describing the states of the past, when used for one-step-ahead prediction, under the assumption that tomorrow8217s state will be identical to today8217s, the hidden markov model process found within the package does not perform to expectations. So, to start off, this post was motivated by Michael Halls-Moore, who recently posted some R code about using the depmixS4 library to use hidden markov models. Generally, I am loath to create posts on topics I don8217t feel I have an absolutely front-to-back understanding of, but I8217m doing this in the hope of learning from others on how to appropriately do online state-space prediction, or 8220regime switching8221 detection, as it may be called in more financial parlance. While I8217ve seen the usual theory of hidden markov models (that is, it can rain or it can be sunny, but you can only infer the weather judging by the clothes you see people wearing outside your window when you wake up), and have worked with toy examples in MOOCs (Udacity8217s self-driving car course deals with them, if I recall correctly8211or maybe it was the AI course), at the end of the day, theory is only as good as how well an implementation can work on real data. For this experiment, I decided to take SPY data since inception, and do a full in-sample 8220backtest8221 on the data. That is, given that the HMM algorithm from depmix sees the whole history of returns, with this 8220god8217s eye8221 view of the data, does the algorithm correctly classify the regimes, if the backtest results are any indication Here8217s the code to do so, inspired by Dr. Halls-Moore8217s. Essentially, while I did select three states, I noted that anything with an intercept above zero is a bull state, and below zero is a bear state, so essentially, it reduces to two states. With the result: So, not particularly terrible. The algorithm works, kind of, sort of, right Well, let8217s try online prediction now. So what I did here was I took an expanding window, starting from 500 days since SPY8217s inception, and kept increasing it, by one day at a time. My prediction, was, trivially enough, the most recent day, using a 1 for a bull state, and a -1 for a bear state. I ran this process in parallel (on a linux cluster, because windows8217s doParallel library seems to not even know that certain packages are loaded, and it8217s more messy), and the first big issue is that this process took about three hours on seven cores for about 23 years of data. Not exactly encouraging, but computing time isn8217t expensive these days. So let8217s see if this process actually works. First, let8217s test if the algorithm does what it8217s actually supposed to do and use one day of look-ahead bias (that is, the algorithm tells us the state at the end of the day8211how correct is it even for that day). With the result: So, allegedly, the algorithm seems to do what it was designed to do, which is to classify a state for a given data set. Now, the most pertinent question: how well do these predictions do even one day ahead You8217d think that state space predictions would be parsimonious from day to day, given the long history, correct With the result: That is, without the lookahead bias, the state space prediction algorithm is atrocious. Why is that Well, here8217s the plot of the states: In short, the online hmm algorithm in the depmix package seems to change its mind very easily, with obvious (negative) implications for actual trading strategies. So, that wraps it up for this post. Essentially, the main message here is this: there8217s a vast difference between loading doing descriptive analysis (AKA 8220where have you been, why did things happen8221) vs. predictive analysis (that is, 8220if I correctly predict the future, I get a positive payoff8221). In my opinion, while descriptive statistics have their purpose in terms of explaining why a strategy may have performed how it did, ultimately, we8217re always looking for better prediction tools. In this case, depmix, at least in this 8220out-of-the-box8221 demonstration does not seem to be the tool for that. If anyone has had success with using depmix (or other regime-switching algorithm in R) for prediction, I would love to see work that details the procedure taken, as it8217s an area I8217m looking to expand my toolbox into, but don8217t have any particular good leads. Essentially, I8217d like to think of this post as me describing my own experiences with the package. ขอบคุณที่อ่าน. NOTE: On Oct. 5th, I will be in New York City. On Oct. 6th, I will be presenting at The Trading Show on the Programming Wars panel. NOTE: My current analytics contract is up for review at the end of the year, so I am officially looking for other offers as well. If you have a full-time role which may benefit from the skills you see on my blog, please get in touch with me. My linkedin profile can be found here. This post will introduce component conditional value at risk mechanics found in PerformanceAnalytics from a paper written by Brian Peterson, Kris Boudt, and Peter Carl. This is a mechanism that is an easy-to-call mechanism for computing component expected shortfall in asset returns as they apply to a portfolio. While the exact mechanics are fairly complex, the upside is that the running time is nearly instantaneous, and this method is a solid tool for including in asset allocation analysis. For those interested in an in-depth analysis of the intuition of component conditional value at risk, I refer them to the paper written by Brian Peterson, Peter Carl, and Kris Boudt. Essentially, here8217s the idea: all assets in a given portfolio have a marginal contribution to its total conditional value at risk (also known as expected shortfall)8211that is, the expected loss when the loss surpasses a certain threshold. For instance, if you want to know your 5 expected shortfall, then it8217s the average of the worst 5 returns per 100 days, and so on. For returns using daily resolution, the idea of expected shortfall may sound as though there will never be enough data in a sufficiently fast time frame (on one year or less), the formula for expected shortfall in the PerformanceAnalytics defaults to an approximation calculation using a Cornish-Fisher expansion, which delivers very good results so long as the p-value isn8217t too extreme (that is, it works for relatively sane p values such as the 1-10 range). Component Conditional Value at Risk has two uses: first off, given no input weights, it uses an equal weight default, which allows it to provide a risk estimate for each individual asset without burdening the researcher to create his or her own correlationcovariance heuristics. Secondly, when provided with a set of weights, the output changes to reflect the contribution of various assets in proportion to those weights. This means that this methodology works very nicely with strategies that exclude assets based on momentum, but need a weighting scheme for the remaining assets. Furthermore, using this methodology also allows an ex-post analysis of risk contribution to see which instrument contributed what to risk. First, a demonstration of how the mechanism works using the edhec data set. There is no strategy here, just a demonstration of syntax. This will assume an equal-weight contribution from all of the funds in the edhec data set. So tmp is the contribution to expected shortfall from each of the various edhec managers over the entire time period. Here8217s the output: The salient part of this is the percent contribution (the last output). Notice that it can be negative, meaning that certain funds gain when others lose. At least, this was the case over the current data set. These assets diversify a portfolio and actually lower expected shortfall. In this case, I equally weighted the first ten managers in the edhec data set, and put zero weight in the last three. Furthermore, we can see what happens when the weights are not equal. This time, notice that as the weight increased in the convertible arb manager, so too did his contribution to maximum expected shortfall. For a future backtest, I would like to make some data requests. I would like to use the universe found in Faber8217s Global Asset Allocation book. That said, the simulations in that book go back to 1972, and I was wondering if anyone out there has daily returns for those assetsindices. While some ETFs go back into the early 2000s, there are some that start rather late such as DBC (commodities, early 2006), GLD (gold, early 2004), BWX (foreign bonds, late 2007), and FTY (NAREIT, early 2007). As an eight-year backtest would be a bit short, I was wondering if anyone had data with more history. One other thing, I will in New York for the trading show. and speaking on the 8220programming wars8221 panel on October 6th. ขอบคุณที่อ่าน. NOTE: While I am currently contracting, I am also looking for a permanent position which can benefit from my skills for when my current contract ends. If you have or are aware of such an opening, I will be happy to speak with you. This post will cover a function to simplify creating Harry Long type rebalancing strategies from SeekingAlpha for interested readers. As Harry Long has stated, most, if not all of his strategies are more for demonstrative purposes rather than actual recommended investments. So, since Harry Long has been posting some more articles on Seeknig Alpha, I8217ve had a reader or two ask me to analyze his strategies (again). Instead of doing that, however, I8217ll simply put this tool here, which is a wrapper that automates the acquisition of data and simulates portfolio rebalancing with one line of code. Here8217s the tool. It fetches the data for you (usually from Yahoo, but a big thank you to Mr. Helumth Vollmeier in the case of ZIV and VXX), and has the option of either simply displaying an equity curve and some statistics (CAGR, annualized standard dev, Sharpe, max Drawdown, Calmar), or giving you the return stream as an output if you wish to do more analysis in R. Here8217s an example of simply getting the statistics, with an 80 XLPSPLV (they8217re more or less interchangeable) and 20 TMF (aka 60 TLT, so an 8060 portfolio), from one of Harry Long8217s articles . Nothing out of the ordinary of what we might expect from a balanced equitybonds portfolio. Generally does well, has its largest drawdown in the financial crisis, and some other bumps in the road, but overall, I8217d think a fairly vanilla 8220set it and forget it8221 sort of thing. And here would be the way to get the stream of individual daily returns, assuming you wanted to rebalance these two instruments weekly, instead of yearly (as is the default). And now let8217s get some statistics. Turns out, moving the rebalancing from annually to weekly didn8217t have much of an effect here (besides give a bunch of money to your broker, if you factored in transaction costs, which this doesn8217t). So, that8217s how this tool works. The results, of course, begin from the latest instrument8217s inception. The trick, in my opinion, is to try and find proxy substitutes with longer histories for newer ETFs that are simply leveraged ETFs, such as using a 60 weight in TLT with an 80 weight in XLP instead of a 20 weight in TMF with 80 allocation in SPLV. For instance, here are some proxies: SPXL XLP SPXLUPRO SPY 3 TMF TLT 3 That said, I8217ve worked with Harry Long before, and he develops more sophisticated strategies behind the scenes, so I8217d recommend that SeekingAlpha readers take his publicly released strategies as concept demonstrations, as opposed to fully-fledged investment ideas, and contact Mr. Long himself about more customized, private solutions for investment institutions if you are so interested. ขอบคุณที่อ่าน. NOTE: I am currently in the northeast. While I am currently contracting, I am interested in networking with individuals or firms with regards to potential collaboration opportunities. This post will demonstrate how to take into account turnover when dealing with returns-based data using PerformanceAnalytics and the Return. Portfolio function in R. It will demonstrate this on a basic strategy on the nine sector SPDRs. So, first off, this is in response to a question posed by one Robert Wages on the R-SIG-Finance mailing list. While there are many individuals out there with a plethora of questions (many of which can be found to be demonstrated on this blog already), occasionally, there will be an industry veteran, a PhD statistics student from Stanford, or other very intelligent individual that will ask a question on a topic that I haven8217t yet touched on this blog, which will prompt a post to demonstrate another technical aspect found in R. This is one of those times. So, this demonstration will be about computing turnover in returns space using the PerformanceAnalytics package. Simply, outside of the PortfolioAnalytics package, PerformanceAnalytics with its Return. Portfolio function is the go-to R package for portfolio management simulations, as it can take a set of weights, a set of returns, and generate a set of portfolio returns for analysis with the rest of PerformanceAnalytics8217s functions. Again, the strategy is this: take the 9 three-letter sector SPDRs (since there are four-letter ETFs now), and at the end of every month, if the adjusted price is above its 200-day moving average, invest into it. Normalize across all invested sectors (that is, 19th if invested into all 9, 100 into 1 if only 1 invested into, 100 cash, denoted with a zero return vector, if no sectors are invested into). It8217s a simple, toy strategy, as the strategy isn8217t the point of the demonstration. Here8217s the basic setup code: So, get the SPDRs, put them together, compute their returns, generate the signal, and create the zero vector, since Return. Portfolio treats weights less than 1 as a withdrawal, and weights above 1 as the addition of more capital (big FYI here). Now, here8217s how to compute turnover: So, the trick is this: when you call Return. portfolio, use the verbose TRUE option. This creates several objects, among them returns, BOP. Weight, and EOP. Weight. These stand for Beginning Of Period Weight, and End Of Period Weight. The way that turnover is computed is simply the difference between how the day8217s return moves the allocated portfolio from its previous ending point to where that portfolio actually stands at the beginning of next period. That is, the end of period weight is the beginning of period drift after taking into account the day8217s driftreturn for that asset. The new beginning of period weight is the end of period weight plus any transacting that would have been done. Thus, in order to find the actual transactions (or turnover), one subtracts the previous end of period weight from the beginning of period weight. This is what such transactions look like for this strategy. Something we can do with such data is take a one-year rolling turnover, accomplished with the following code: It looks like this: This essentially means that one year8217s worth of two-way turnover (that is, if selling an entirely invested portfolio is 100 turnover, and buying an entirely new set of assets is another 100, then two-way turnover is 200) is around 800 at maximum. That may be pretty high for some people. Now, here8217s the application when you penalize transaction costs at 20 basis points per percentage point traded (that is, it costs 20 cents to transact 100). So, at 20 basis points on transaction costs, that takes about one percent in returns per year out of this (admittedly, terrible) strategy. This is far from negligible. So, that is how you actually compute turnover and transaction costs. In this case, the transaction cost model was very simple. However, given that Return. portfolio returns transactions at the individual asset level, one could get as complex as they would like with modeling the transaction costs. ขอบคุณที่อ่าน. NOTE: I will be giving a lightning talk at RFinance, so for those attending, you8217ll be able to find me there. This post will outline an easy-to-make mistake in writing vectorized backtests8211namely in using a signal obtained at the end of a period to enter (or exit) a position in that same period. The difference in results one obtains is massive. Today, I saw two separate posts from Alpha Architect and Mike Harris both referencing a paper by Valeriy Zakamulin on the fact that some previous trend-following research by Glabadanidis was done with shoddy results, and that Glabadanidis8217s results were only reproducible through instituting lookahead bias. The following code shows how to reproduce this lookahead bias. First, the setup of a basic moving average strategy on the SampP 500 index from as far back as Yahoo data will provide. And here is how to institute the lookahead bias. These are the 8220results8221: Of course, this equity curve is of no use, so here8217s one in log scale. As can be seen, lookahead bias makes a massive difference. Here are the numerical results: Again, absolutely ridiculous. Note that when using Return. Portfolio (the function in PerformanceAnalytics), that package will automatically give you the next period8217s return, instead of the current one, for your weights. However, for those writing 8220simple8221 backtests that can be quickly done using vectorized operations, an off-by-one error can make all the difference between a backtest in the realm of reasonable, and pure nonsense. However, should one wish to test for said nonsense when faced with impossible-to-replicate results, the mechanics demonstrated above are the way to do it. Now, onto other news: I8217d like to thank Gerald M for staying on top of one of the Logical Invest strategies8211namely, their simple global market rotation strategy outlined in an article from an earlier blog post. Up until March 2015 (the date of the blog post), the strategy had performed well. However, after said date It has been a complete disaster, which, in hindsight, was evident when I passed it through the hypothesis-driven development framework process I wrote about earlier. So, while there has been a great deal written about not simply throwing away a strategy because of short-term underperformance, and that anomalies such as momentum and value exist because of career risk due to said short-term underperformance, it8217s never a good thing when a strategy creates historically large losses, particularly after being published in such a humble corner of the quantitative financial world. In any case, this was a post demonstrating some mechanics, and an update on a strategy I blogged about not too long ago. ขอบคุณที่อ่าน. NOTE: I am always interested in hearing about new opportunities which may benefit from my expertise, and am always happy to network. You can find my LinkedIn profile here . This post will shed light on the values of R2s behind two rather simplistic strategies 8212 the simple 10 month SMA, and its relative, the 10 month momentum (which is simply a difference of SMAs, as Alpha Architect showed in their book DIY Financial Advisor . Not too long ago, a friend of mine named Josh asked me a question regarding R2s in finance. He8217s finishing up his PhD in statistics at Stanford, so when people like that ask me questions, I8217d like to answer them. His assertion is that in some instances, models that have less than perfect predictive power (EG R2s of .4, for instance), can still deliver very promising predictions, and that if someone were to have a financial model that was able to explain 40 of the variance of returns, they could happily retire with that model making them very wealthy. Indeed. 4 is a very optimistic outlook (to put it lightly), as this post will show. In order to illustrate this example, I took two 8220staple8221 strategies 8212 buy SPY when i ts closing monthly price is above its ten month simple moving average, and when its ten month momentum (basically the difference of a ten month moving average and its lag) is positive. While these models are simplistic, they are ubiquitously talked about, and many momentum strategies are an improvement upon these baseline, 8220out-of-the-box8221 strategies. Here8217s the code to do that: And here are the results: In short, the SMA10 and the 10-month momentum (aka ROC 10 aka MOM10) both handily outperform the buy and hold, not only in absolute returns, but especially in risk-adjusted returns (Sharpe and Calmar ratios). Again, simplistic analysis, and many models get much more sophisticated than this, but once again, simple, illustrative example using two strategies that outperform a benchmark (over the long term, anyway). Now, the question is, what was the R2 of these models To answer this, I took a rolling five-year window that essentially asked: how well did these quantities (the ratio between the closing price and the moving average 8211 1, or the ten month momentum) predict the next month8217s returns That is, what proportion of the variance is explained through the monthly returns regressed against the previous month8217s signals in numerical form (perhaps not the best framing, as the signal is binary as opposed to continuous which is what is being regressed, but let8217s set that aside, again, for the sake of illustration). Here8217s the code to generate the answer. And the answer, in pictorial form: In short, even in the best case scenarios, namely, crises which provide momentumtrend-followingcall it what you will its raison d8217etre, that is, its risk management appeal, the proportion of variance explained by the actual signal quantities was very small. In the best of times, around 20. But then again, think about what the R2 value actually is8211it8217s the percentage of variance explained by a predictor. If a small set of signals (let alone one) was able to explain the majority of the change in the returns of the SampP 500, or even a not-insignificant portion, such a person would stand to become very wealthy. More to the point, given that two strategies that handily outperform the market have R2s that are exceptionally low for extended periods of time, it goes to show that holding the R2 up as some form of statistical holy grail certainly is incorrect in the general sense, and anyone who does so either is painting with too broad a brush, is creating disingenuous arguments, or should simply attempt to understand another field which may not work the way their intuition tells them. ขอบคุณที่อ่าน. This review will review the 8220Adaptive Asset Allocation: Dynamic Global Portfolios to Profit in Good Times 8211 and Bad8221 book by the people at ReSolve Asset Management. Overall, this book is a definite must-read for those who have never been exposed to the ideas within it. However, when it comes to a solution that can be fully replicated, this book is lacking. Okay, it8217s been a while since I reviewed my last book, DIY Financial Advisor. from the awesome people at Alpha Architect. This book in my opinion, is set up in a similar sort of format. This is the structure of the book, and my reviews along with it: Part 1: Why in the heck you actually need to have a diversified portfolio, and why a diversified portfolio is a good thing. In a world in which there is so much emphasis put on single-security performance, this is certainly something that absolutely must be stated for those not familiar with portfolio theory. It highlights the example of two people8211one from Abbott Labs, and one from Enron, who had so much of their savings concentrated in their company8217s stock. Mr. Abbott got hit hard and changed his outlook on how to save for retirement, and Mr. Enron was never heard from again. Long story short: a diversified portfolio is good, and a properly diversified portfolio can offset one asset8217s zigs with another asset8217s zags. This is the key to establishing a stream of returns that will help meet financial goals. Basically, this is your common sense story (humans love being told stories) so as to motivate you to read the rest of the book. It does its job, though for someone like me, it8217s more akin to a big 8220wait for it, wait for it8230and there8217s the reason why we should read on, as expected8221. Part 2: Something not often brought up in many corners of the quant world (because it8217s real life boring stuff) is the importance not only of average returns, but when those returns are achieved. Namely, imagine your everyday saver. At the beginning of their careers, they8217re taking home less salary and have less money in their retirement portfolio (or speculation portfolio, but the book uses retirement portfolio). As they get into middle age and closer to retirement, they have a lot more money in said retirement portfolio. Thus, strong returns are most vital when there is more cash available to the portfolio, and the difference between mediocre returns at the beginning and strong returns at the end of one8217s working life as opposed to vice versa is astronomical and cannot be understated. Furthermore, once in retirement, strong returns in the early years matter far more than returns in the later years once money has been withdrawn out of the portfolio (though I8217d hope that a portfolio8217s returns can be so strong that one can simply 8220live off the interest8221). Or, put more intuitively: when you have 10,000 in your portfolio, a 20 drawdown doesn8217t exactly hurt because you can make more money and put more into your retirement account. But when you8217re 62 and have 500,000 and suddenly lose 30 of everything, well, that8217s massive. How much an investor wants to avoid such a scenario cannot be understated. Warren Buffett once said that if you can8217t bear to lose 50 of everything, you shouldn8217t be in stocks. I really like this part of the book because it shows just how dangerous the ideas of 8220a 50 drawdown is unavoidable8221 and other 8220stay invested for the long haul8221 refrains are. Essentially, this part of the book makes a resounding statement that any financial adviser keeping his or her clients invested in equities when they8217re near retirement age is doing something not very advisable, to put it lightly. In my opinion, those who advise pension funds should especially keep this section of the book in mind, since for some people, the long-term may be coming to an end, and what matters is not only steady returns, but to make sure the strategy doesn8217t fall off a cliff and destroy decades of hard-earned savings. Part 3: This part is also one that is a very important read. First off, it lays out in clear terms that the long-term forward-looking valuations for equities are at rock bottom. That is, the expected forward 15-year returns are very low, using approximately 75 years of evidence. Currently, according to the book, equity valuations imply a negative 15-year forward return. However, one thing I will take issue with is that while forward-looking long-term returns for equities may be very low, if one believed this chart and only invested in the stock market when forecast 15-year returns were above the long term average, one would have missed out on both the 2003-2007 bull runs, and the one since 2009 that8217s just about over. So, while the book makes a strong case for caution, readers should also take the chart with a grain of salt in my opinion. However, another aspect of portfolio construction that this book covers is how to construct a robust (assets for any economic environment) and coherent (asset classes balanced in number) universe for implementation with any asset allocation algorithm. I think this bears repeating: universe selection is an extremely important topic in the discussion of asset allocation, yet there is very little discussion about it. Most researchtopics simply take some 8220conventional universe8221, such as 8220all stocks on the NYSE8221, or 8220all the stocks in the SampP 5008221, or 8220the entire set of the 50-60 most liquid futures8221 without consideration for robustness and coherence. This book is the first source I8217ve seen that actually puts this topic under a magnifying glass besides 8220finger in the air pick and choose8221. Part 4: and here8217s where I level my main criticism at this book. For those that have read 8220Adaptive Asset Allocation: A Primer8221. this section of the book is basically one giant copy and paste. It8217s all one large buildup to 8220momentum rank min-variance optimization8221. All well and good, until there8217s very little detail beyond the basics as to how the minimum variance portfolio was constructed. Namely, what exactly is the minimum variance algorithm in use Is it one of the poor variants susceptible to numerical instability inherent in inverting sample covariance matrices Or is it a heuristic like David Varadi8217s minimum variance and minimum correlation algorithm The one feeling I absolutely could not shake was that this book had a perfect opportunity to present a robust approach to minimum variance, and instead, it8217s long on concept, short on details. While the theory of 8220maximize return for unit risk8221 is all well and good, the actual algorithm to implement that theory into practice is not trivial, with the solutions taught to undergrads and master8217s students having some well-known weaknesses. On top of this, one thing that got hammered into my head in the past was that ranking also had a weakness at the inclusionexclusion point. E. G. if, out of ten assets, the fifth asset had a momentum of say, 10.9, and the sixth asset had a momentum of 10.8, how are we so sure the fifth is so much better And while I realize that this book was ultimately meant to be a primer, in my opinion, it would have been a no-objections five-star if there were an appendix that actually went into some detail on how to go from the simple concepts and included a small numerical example of some algorithms that may address the well-known weaknesses. This doesn8217t mean Greekmathematical jargon. Just an appendix that acknowledged that not every reader is someone only picking up his first or second book about systematic investing, and that some of us are familiar with the 8220whys8221 and are more interested in the 8220hows8221. Furthermore, I8217d really love to know where the authors of this book got their data to back-date some of these ETFs into the 90s. Part 5: some more formal research on topics already covered in the rest of the book8211namely a section about how many independent bets one can take as the number of assets grow, if I remember it correctly. Long story short You easily get the most bang for your buck among disparate asset classes, such as treasuries of various duration, commodities, developed vs. emerging equities, and so on, as opposed to trying to pick among stocks in the same asset class (though there8217s some potential for alpha there8230just8230a lot less than you imagine). So in case the idea of asset class selection, not stock selection wasn8217t beaten into the reader8217s head before this point, this part should do the trick. The other research paper is something I briefly skimmed over which went into more depth about volatility and retirement portfolios, though I felt that the book covered this topic earlier on to a sufficient degree by building up the intuition using very understandable scenarios. So that8217s the review of the book. Overall, it8217s a very solid piece of writing, and as far as establishing the why, it does an absolutely superb job. For those that aren8217t familiar with the concepts in this book, this is definitely a must-read, and ASAP. However, for those familiar with most of the concepts and looking for a detailed 8220how8221 procedure, this book does not deliver as much as I would have liked. And I realize that while it8217s a bad idea to publish secret sauce, I bought this book in the hope of being exposed to a new algorithm presented in the understandable and intuitive language that the rest of the book was written in, and was left wanting. Still, that by no means diminishes the impact of the rest of the book. For those who are more likely to be its target audience, it8217s a 55. For those that wanted some specifics, it still has its gem on universe construction. Overall, I rate it a 45. Thanks for reading. Happy new year. This post will be a quick one covering the relationship between the simple moving average and time series momentum. The implication is that one can potentially derive better time series momentum indicators than the classical one applied in so many papers. Okay, so the main idea for this post is quite simple: I8217m sure we8217re all familiar with classical momentum. That is, the price now compared to the price however long ago (3 months, 10 months, 12 months, etc.). E. G. P(now) 8211 P(10) And I8217m sure everyone is familiar with the simple moving average indicator, as well. E. G. SMA(10). Well, as it turns out, these two quantities are actually related. It turns out, if instead of expressing momentum as the difference of two numbers, it is expressed as the sum of returns, it can be written (for a 10 month momentum) as: MOM10 return of this month return of last month return of 2 months ago 8230 return of 9 months ago, for a total of 10 months in our little example. This can be written as MOM10 (P(0) 8211 P(1)) (P(1) 8211 P(2)) 8230 (P(9) 8211 P(10)). (Each difference within parentheses denotes one month8217s worth of returns.) Which can then be rewritten by associative arithmetic as: (P(0) P(1) 8230 P(9)) 8211 (P(1) P(2) 8230 P(10)). In other words, momentum 8212 aka the difference between two prices, can be rewritten as the difference between two cumulative sums of prices. And what is a simple moving average Simply a cumulative sum of prices divided by however many prices summed over. Here8217s some R code to demonstrate. With the resulting number of times these two signals are equal: In short, every time. Now, what exactly is the punchline of this little example Here8217s the punchline: The simple moving average is8230fairly simplistic as far as filters go. It works as a pedagogical example, but it has some well known weaknesses regarding lag, windowing effects, and so on. Here8217s a toy example how one can get a different momentum signal by changing the filter. With the following results: While the difference of EMA10 strategy didn8217t do better than the difference of SMA10 (aka standard 10-month momentum), that8217s not the point. The point is that the momentum signal is derived from a simple moving average filter, and that by using a different filter, one can still use a momentum type of strategy. Or, put differently, the maingeneral takeaway here is that momentum is the slope of a filter, and one can compute momentum in an infinite number of ways depending on the filter used, and can come up with a myriad of different momentum strategies. ขอบคุณที่อ่าน. NOTE: I am currently contracting in Chicago, and am always open to networking. Contact me at my email at ilya. kipnisgmail or find me on my LinkedIn here. Post navigation CategoriesCategory Archives: Trading This post will introduce John Ehlers8217s Autocorrelation Periodogram mechanism8211a mechanism designed to dynamically find a lookback period. That is, the most common parameter optimized in backtests is the lookback period. Before beginning this post, I must give credit where it8217s due, to one Mr. Fabrizio Maccallini. the head of structured derivatives at Nordea Markets in London. You can find the rest of the repository he did for Dr. John Ehlers8217s Cycle Analytics for Traders on his github. I am grateful and honored that such intelligent and experienced individuals are helping to bring some of Dr. Ehlers8217s methods into R. The point of the Ehlers Autocorrelation Periodogram is to dynamically set a period between a minimum and a maximum period length. While I leave the exact explanation of the mechanic to Dr. Ehlers8217s book, for all practical intents and purposes, in my opinion, the punchline of this method is to attempt to remove a massive source of overfitting from trading system creation8211namely specifying a lookback period. SMA of 50 days 100 days 200 days Well, this algorithm takes that possibility of overfitting out of your hands. Simply, specify an upper and lower bound for your lookback, and it does the rest. How well it does it is a topic of discussion for those well-versed in the methodologies of electrical engineering (I8217m not), so feel free to leave comments that discuss how well the algorithm does its job, and feel free to blog about it as well. In any case, here8217s the original algorithm code, courtesy of Mr. Maccallini: One thing I do notice is that this code uses a loop that says for(i in 1:length(filt)), which is an O(data points) loop, which I view as the plague in R. While I8217ve used Rcpp before, it8217s been for only the most basic of loops, so this is definitely a place where the algorithm can stand to be improved with Rcpp due to R8217s inherent poor looping. Those interested in the exact logic of the algorithm will, once again, find it in John Ehlers8217s Cycle Analytics For Traders book (see link earlier in the post). Of course, the first thing to do is to test how well the algorithm does what it purports to do, which is to dictate the lookback period of an algorithm. Let8217s run it on some data. Now, what does the algorithm-set lookback period look like Let8217s zoom in on 2001 through 2003, when the markets went through some upheaval. In this zoomed-in image, we can see that the algorithm8217s estimates seem fairly jumpy. Here8217s some code to feed the algorithm8217s estimates of n into an indicator to compute an indicator with a dynamic lookback period as set by Ehlers8217s autocorrelation periodogram. And here is the function applied with an SMA, to tune between 120 and 252 days. As seen, this algorithm is less consistent than I would like, at least when it comes to using a simple moving average. For now, I8217m going to leave this code here, and let people experiment with it. I hope that someone will find that this indicator is helpful to them. ขอบคุณที่อ่าน. NOTES: I am always interested in networkingmeet-ups in the northeast (PhiladelphiaNYC). Furthermore, if you believe your firm will benefit from my skills, please do not hesitate to reach out to me. My linkedin profile can be found here. Lastly, I am volunteering to curate the R section for books on quantocracy. If you have a book about R that can apply to finance, be sure to let me know about it, so that I can review it and possibly recommend it. Thakn you. This post will be about attempting to use the Depmix package for online state prediction. While the depmix package performs admirably when it comes to describing the states of the past, when used for one-step-ahead prediction, under the assumption that tomorrow8217s state will be identical to today8217s, the hidden markov model process found within the package does not perform to expectations. So, to start off, this post was motivated by Michael Halls-Moore, who recently posted some R code about using the depmixS4 library to use hidden markov models. Generally, I am loath to create posts on topics I don8217t feel I have an absolutely front-to-back understanding of, but I8217m doing this in the hope of learning from others on how to appropriately do online state-space prediction, or 8220regime switching8221 detection, as it may be called in more financial parlance. While I8217ve seen the usual theory of hidden markov models (that is, it can rain or it can be sunny, but you can only infer the weather judging by the clothes you see people wearing outside your window when you wake up), and have worked with toy examples in MOOCs (Udacity8217s self-driving car course deals with them, if I recall correctly8211or maybe it was the AI course), at the end of the day, theory is only as good as how well an implementation can work on real data. For this experiment, I decided to take SPY data since inception, and do a full in-sample 8220backtest8221 on the data. That is, given that the HMM algorithm from depmix sees the whole history of returns, with this 8220god8217s eye8221 view of the data, does the algorithm correctly classify the regimes, if the backtest results are any indication Here8217s the code to do so, inspired by Dr. Halls-Moore8217s. Essentially, while I did select three states, I noted that anything with an intercept above zero is a bull state, and below zero is a bear state, so essentially, it reduces to two states. With the result: So, not particularly terrible. The algorithm works, kind of, sort of, right Well, let8217s try online prediction now. So what I did here was I took an expanding window, starting from 500 days since SPY8217s inception, and kept increasing it, by one day at a time. My prediction, was, trivially enough, the most recent day, using a 1 for a bull state, and a -1 for a bear state. I ran this process in parallel (on a linux cluster, because windows8217s doParallel library seems to not even know that certain packages are loaded, and it8217s more messy), and the first big issue is that this process took about three hours on seven cores for about 23 years of data. Not exactly encouraging, but computing time isn8217t expensive these days. So let8217s see if this process actually works. First, let8217s test if the algorithm does what it8217s actually supposed to do and use one day of look-ahead bias (that is, the algorithm tells us the state at the end of the day8211how correct is it even for that day). With the result: So, allegedly, the algorithm seems to do what it was designed to do, which is to classify a state for a given data set. Now, the most pertinent question: how well do these predictions do even one day ahead You8217d think that state space predictions would be parsimonious from day to day, given the long history, correct With the result: That is, without the lookahead bias, the state space prediction algorithm is atrocious. Why is that Well, here8217s the plot of the states: In short, the online hmm algorithm in the depmix package seems to change its mind very easily, with obvious (negative) implications for actual trading strategies. So, that wraps it up for this post. Essentially, the main message here is this: there8217s a vast difference between loading doing descriptive analysis (AKA 8220where have you been, why did things happen8221) vs. predictive analysis (that is, 8220if I correctly predict the future, I get a positive payoff8221). In my opinion, while descriptive statistics have their purpose in terms of explaining why a strategy may have performed how it did, ultimately, we8217re always looking for better prediction tools. In this case, depmix, at least in this 8220out-of-the-box8221 demonstration does not seem to be the tool for that. If anyone has had success with using depmix (or other regime-switching algorithm in R) for prediction, I would love to see work that details the procedure taken, as it8217s an area I8217m looking to expand my toolbox into, but don8217t have any particular good leads. Essentially, I8217d like to think of this post as me describing my own experiences with the package. ขอบคุณที่อ่าน. NOTE: On Oct. 5th, I will be in New York City. On Oct. 6th, I will be presenting at The Trading Show on the Programming Wars panel. NOTE: My current analytics contract is up for review at the end of the year, so I am officially looking for other offers as well. If you have a full-time role which may benefit from the skills you see on my blog, please get in touch with me. My linkedin profile can be found here. This post will demonstrate how to take into account turnover when dealing with returns-based data using PerformanceAnalytics and the Return. Portfolio function in R. It will demonstrate this on a basic strategy on the nine sector SPDRs. So, first off, this is in response to a question posed by one Robert Wages on the R-SIG-Finance mailing list. While there are many individuals out there with a plethora of questions (many of which can be found to be demonstrated on this blog already), occasionally, there will be an industry veteran, a PhD statistics student from Stanford, or other very intelligent individual that will ask a question on a topic that I haven8217t yet touched on this blog, which will prompt a post to demonstrate another technical aspect found in R. This is one of those times. So, this demonstration will be about computing turnover in returns space using the PerformanceAnalytics package. Simply, outside of the PortfolioAnalytics package, PerformanceAnalytics with its Return. Portfolio function is the go-to R package for portfolio management simulations, as it can take a set of weights, a set of returns, and generate a set of portfolio returns for analysis with the rest of PerformanceAnalytics8217s functions. Again, the strategy is this: take the 9 three-letter sector SPDRs (since there are four-letter ETFs now), and at the end of every month, if the adjusted price is above its 200-day moving average, invest into it. Normalize across all invested sectors (that is, 19th if invested into all 9, 100 into 1 if only 1 invested into, 100 cash, denoted with a zero return vector, if no sectors are invested into). It8217s a simple, toy strategy, as the strategy isn8217t the point of the demonstration. Here8217s the basic setup code: So, get the SPDRs, put them together, compute their returns, generate the signal, and create the zero vector, since Return. Portfolio treats weights less than 1 as a withdrawal, and weights above 1 as the addition of more capital (big FYI here). Now, here8217s how to compute turnover: So, the trick is this: when you call Return. portfolio, use the verbose TRUE option. This creates several objects, among them returns, BOP. Weight, and EOP. Weight. These stand for Beginning Of Period Weight, and End Of Period Weight. The way that turnover is computed is simply the difference between how the day8217s return moves the allocated portfolio from its previous ending point to where that portfolio actually stands at the beginning of next period. That is, the end of period weight is the beginning of period drift after taking into account the day8217s driftreturn for that asset. The new beginning of period weight is the end of period weight plus any transacting that would have been done. Thus, in order to find the actual transactions (or turnover), one subtracts the previous end of period weight from the beginning of period weight. This is what such transactions look like for this strategy. Something we can do with such data is take a one-year rolling turnover, accomplished with the following code: It looks like this: This essentially means that one year8217s worth of two-way turnover (that is, if selling an entirely invested portfolio is 100 turnover, and buying an entirely new set of assets is another 100, then two-way turnover is 200) is around 800 at maximum. That may be pretty high for some people. Now, here8217s the application when you penalize transaction costs at 20 basis points per percentage point traded (that is, it costs 20 cents to transact 100). So, at 20 basis points on transaction costs, that takes about one percent in returns per year out of this (admittedly, terrible) strategy. This is far from negligible. So, that is how you actually compute turnover and transaction costs. In this case, the transaction cost model was very simple. However, given that Return. portfolio returns transactions at the individual asset level, one could get as complex as they would like with modeling the transaction costs. ขอบคุณที่อ่าน. NOTE: I will be giving a lightning talk at RFinance, so for those attending, you8217ll be able to find me there. This post will outline an easy-to-make mistake in writing vectorized backtests8211namely in using a signal obtained at the end of a period to enter (or exit) a position in that same period. The difference in results one obtains is massive. Today, I saw two separate posts from Alpha Architect and Mike Harris both referencing a paper by Valeriy Zakamulin on the fact that some previous trend-following research by Glabadanidis was done with shoddy results, and that Glabadanidis8217s results were only reproducible through instituting lookahead bias. The following code shows how to reproduce this lookahead bias. First, the setup of a basic moving average strategy on the SampP 500 index from as far back as Yahoo data will provide. And here is how to institute the lookahead bias. These are the 8220results8221: Of course, this equity curve is of no use, so here8217s one in log scale. As can be seen, lookahead bias makes a massive difference. Here are the numerical results: Again, absolutely ridiculous. Note that when using Return. Portfolio (the function in PerformanceAnalytics), that package will automatically give you the next period8217s return, instead of the current one, for your weights. However, for those writing 8220simple8221 backtests that can be quickly done using vectorized operations, an off-by-one error can make all the difference between a backtest in the realm of reasonable, and pure nonsense. However, should one wish to test for said nonsense when faced with impossible-to-replicate results, the mechanics demonstrated above are the way to do it. Now, onto other news: I8217d like to thank Gerald M for staying on top of one of the Logical Invest strategies8211namely, their simple global market rotation strategy outlined in an article from an earlier blog post. Up until March 2015 (the date of the blog post), the strategy had performed well. However, after said date It has been a complete disaster, which, in hindsight, was evident when I passed it through the hypothesis-driven development framework process I wrote about earlier. So, while there has been a great deal written about not simply throwing away a strategy because of short-term underperformance, and that anomalies such as momentum and value exist because of career risk due to said short-term underperformance, it8217s never a good thing when a strategy creates historically large losses, particularly after being published in such a humble corner of the quantitative financial world. In any case, this was a post demonstrating some mechanics, and an update on a strategy I blogged about not too long ago. ขอบคุณที่อ่าน. NOTE: I am always interested in hearing about new opportunities which may benefit from my expertise, and am always happy to network. You can find my LinkedIn profile here . Happy new year. This post will be a quick one covering the relationship between the simple moving average and time series momentum. The implication is that one can potentially derive better time series momentum indicators than the classical one applied in so many papers. Okay, so the main idea for this post is quite simple: I8217m sure we8217re all familiar with classical momentum. That is, the price now compared to the price however long ago (3 months, 10 months, 12 months, etc.). E. G. P(now) 8211 P(10) And I8217m sure everyone is familiar with the simple moving average indicator, as well. E. G. SMA(10). Well, as it turns out, these two quantities are actually related. It turns out, if instead of expressing momentum as the difference of two numbers, it is expressed as the sum of returns, it can be written (for a 10 month momentum) as: MOM10 return of this month return of last month return of 2 months ago 8230 return of 9 months ago, for a total of 10 months in our little example. This can be written as MOM10 (P(0) 8211 P(1)) (P(1) 8211 P(2)) 8230 (P(9) 8211 P(10)). (Each difference within parentheses denotes one month8217s worth of returns.) Which can then be rewritten by associative arithmetic as: (P(0) P(1) 8230 P(9)) 8211 (P(1) P(2) 8230 P(10)). In other words, momentum 8212 aka the difference between two prices, can be rewritten as the difference between two cumulative sums of prices. And what is a simple moving average Simply a cumulative sum of prices divided by however many prices summed over. Here8217s some R code to demonstrate. With the resulting number of times these two signals are equal: In short, every time. Now, what exactly is the punchline of this little example Here8217s the punchline: The simple moving average is8230fairly simplistic as far as filters go. It works as a pedagogical example, but it has some well known weaknesses regarding lag, windowing effects, and so on. Here8217s a toy example how one can get a different momentum signal by changing the filter. With the following results: While the difference of EMA10 strategy didn8217t do better than the difference of SMA10 (aka standard 10-month momentum), that8217s not the point. The point is that the momentum signal is derived from a simple moving average filter, and that by using a different filter, one can still use a momentum type of strategy. Or, put differently, the maingeneral takeaway here is that momentum is the slope of a filter, and one can compute momentum in an infinite number of ways depending on the filter used, and can come up with a myriad of different momentum strategies. ขอบคุณที่อ่าน. NOTE: I am currently contracting in Chicago, and am always open to networking. Contact me at my email at ilya. kipnisgmail or find me on my LinkedIn here. This post will outline a first failed attempt at applying the ensemble filter methodology to try and come up with a weighting process on SPY that should theoretically be a gradual process to shift from conviction between a bull market, a bear market, and anywhere in between. This is a follow-up post to this blog post. So, my thinking went like this: in a bull market, as one transitions from responsiveness to smoothness, responsive filters should be higher than smooth filters, and vice versa, as there8217s generally a trade-off between the two. In fact, in my particular formulation, the quantity of the square root of the EMA of squared returns punishes any deviation from a flat line altogether (although inspired by Basel8217s measure of volatility, which is the square root of the 18-day EMA of squared returns), while the responsiveness quantity punishes any deviation from the time series of the realized prices. Whether these are the two best measures of smoothness and responsiveness is a topic I8217d certainly appreciate feedback on. In any case, an idea I had on the top of my head was that in addition to having a way of weighing multiple filters by their responsiveness (deviation from price action) and smoothness (deviation from a flat line), that by taking the sums of the sign of the difference between one filter and its neighbor on the responsiveness to smoothness spectrum, provided enough ensemble filters (say, 101, so there are 100 differences), one would obtain a way to move from full conviction of a bull market, to a bear market, to anything in between, and have this be a smooth process that doesn8217t have schizophrenic swings of conviction. Here8217s the code to do this on SPY from inception to 2003: And here8217s the very underwhelming result: Essentially, while I expected to see changes in conviction of maybe 20 at most, instead, my indicator of sum of sign differences did exactly as I had hoped it wouldn8217t, which is to be a very binary sort of mechanic. My intuition was that between an 8220obvious bull market8221 and an 8220obvious bear market8221 that some differences would be positive, some negative, and that they8217d net each other out, and the conviction would be zero. Furthermore, that while any individual crossover is binary, all one hundred signs being either positive or negative would be a more gradual process. Apparently, this was not the case. To continue this train of thought later, one thing to try would be an all-pairs sign difference. Certainly, I don8217t feel like giving up on this idea at this point, and, as usual, feedback would always be appreciated. ขอบคุณที่อ่าน. NOTE: I am currently consulting in an analytics capacity in downtown Chicago. However, I am also looking for collaborators that wish to pursue interesting trading ideas. If you feel my skills may be of help to you, let8217s talk. You can email me at ilya. kipnisgmail, or find me on my LinkedIn here . This review will be about Inovance Tech8217s TRAIDE system. It is an application geared towards letting retail investors apply proprietary machine learning algorithms to assist them in creating systematic trading strategies. Currently, my one-line review is that while I hope the company founders mean well, the application is still in an early stage, and so, should be checked out by potential usersventure capitalists as something with proof of potential, rather than a finished product ready for mass market. While this acts as a review, it8217s also my thoughts as to how Inovance Tech can improve its product. A bit of background: I have spoken several times to some of the company8217s founders, who sound like individuals at about my age level (so, fellow millennials). Ultimately, the selling point is this: Systematic trading is cool. Machine learning is cool. Therefore, applying machine learning to systematic trading is awesome (And a surefire way to make profits, as Renaissance Technologies has shown.) While this may sound a bit snarky, it8217s also, in some ways, true. Machine learning has become the talk of the town, from IBM8217s Watson (RenTec itself hired a bunch of speech recognition experts from IBM a couple of decades back), to Stanford8217s self-driving car (invented by Sebastian Thrun, who now heads Udacity), to the Netflix prize, to god knows what Andrew Ng is doing with deep learning at Baidu. Considering how well machine learning has done at much more complex tasks than 8220create a half-decent systematic trading algorithm8221, it shouldn8217t be too much to ask this powerful field at the intersection of computer science and statistics to help the retail investor glued to watching charts generate a lot more return on his or her investments than through discretionary chart-watching and noise trading. To my understanding from conversations with Inovance Tech8217s founders, this is explicitly their mission. However, I am not sure that Inovance8217s TRAIDE application actually accomplishes this mission in its current state. Here8217s how it works: Users select one asset at a time, and select a date range (data going back to Dec. 31, 2009). Assets are currently limited to highly liquid currency pairs, and can take the following settings: 1 hour, 2 hour, 4 hour, 6 hour, or daily bar time frames. Users then select from a variety of indicators, ranging from technical (moving averages, oscillators, volume calculations, etc. Mostly an assortment of 20th century indicators, though the occasional adaptive moving average has managed to sneak in8211namely KAMA8211see my DSTrading package, and MAMA8211aka the Mesa Adaptive Moving Average, from John Ehlers) to more esoteric ones such as some sentiment indicators. Here8217s where things start to head south for me, however. Namely, that while it8217s easy to add as many indicators as a user would like, there is basically no documentation on any of them, with no links to reference, etc. so users will have to bear the onus of actually understanding what each and every one of the indicators they select actually does, and whether or not those indicators are useful. The TRAIDE application makes zero effort (thus far) to actually get users acquainted with the purpose of these indicators, what their theoretical objective is (measure conviction in a trend, detect a trend, oscillator type indicator, etc.) Furthermore, regarding indicator selections, users also specify one parameter setting for each indicator per strategy. E. G. if I had an EMA crossover, I8217d have to create a new strategy for a 20100 crossover, a 21100 crossover, rather than specifying something like this: short EMA: 20-60 long EMA: 80-200 Quantstrat itself has this functionality, and while I don8217t recall covering parameter robustness checksoptimization (in other words, testing multiple parameter sets8211whether one uses them for optimization or robustness is up to the user, not the functionality) in quantstrat on this blog specifically, this information very much exists in what I deem 8220the official quantstrat manual8221, found here. In my opinion, the option of covering a range of values is mandatory so as to demonstrate that any given parameter setting is not a random fluke. Outside of quantstrat, I have demonstrated this methodology in my Hypothesis Driven Development posts, and in coming up for parameter selection for volatility trading. Where TRAIDE may do something interesting, however, is that after the user specifies his indicators and parameters, its 8220proprietary machine learning8221 algorithms (WARNING: COMPLETELY BLACK BOX) determine for what range of values of the indicators in question generated the best results within the backtest, and assign them bullishness and bearishness scores. In other words, 8220looking backwards, these were the indicator values that did best over the course of the sample8221. While there is definite value to exploring the relationships between indicators and future returns, I think that TRAIDE needs to do more in this area, such as reporting P-values, conviction, and so on. For instance, if you combine enough indicators, your 8220rule8221 is a market order that8217s simply the intersection of all of the ranges of your indicators. For instance, TRAIDE may tell a user that the strongest bullish signal when the difference of the moving averages is between 1 and 2, the ADX is between 20 and 25, the ATR is between 0.5 and 1, and so on. Each setting the user selects further narrows down the number of trades the simulation makes. In my opinion, there are more ways to explore the interplay of indicators than simply one giant AND statement, such as an 8220OR8221 statement, of some sort. (E. G. select all values, put on a trade when 3 out of 5 indicators fall into the selected bullish range in order to place more trades). While it may be wise to filter down trades to very rare instances if trading a massive amount of instruments, such that of several thousand possible instruments, only several are trading at any given time, with TRAIDE, a user selects only one asset class (currently, one currency pair) at a time, so I8217m hoping to see TRAIDE create more functionality in terms of what constitutes a trading rule. After the user selects both a long and a short rule (by simply filtering on indicator ranges that TRAIDE8217s machine learning algorithms have said are good), TRAIDE turns that into a backtest with a long equity curve, short equity curve, total equity curve, and trade statistics for aggregate, long, and short trades. For instance, in quantstrat, one only receives aggregate trade statistics. Whether long or short, all that matters to quantstrat is whether or not the trade made or lost money. For sophisticated users, it8217s trivial enough to turn one set of rules on or off, but TRAIDE does more to hold the user8217s hand in that regard. Lastly, TRAIDE then generates MetaTrader4 code for a user to download. And that8217s the process. In my opinion, while what Inovance Tech has set out to do with TRAIDE is interesting, I wouldn8217t recommend it in its current state. For sophisticated individuals that know how to go through a proper research process, TRAIDE is too stringent in terms of parameter settings (one at a time), pre-coded indicators (its target audience probably can8217t program too well), and asset classes (again, one at a time). However, for retail investors, my issue with TRAIDE is this: There is a whole assortment of undocumented indicators, which then move to black-box machine learning algorithms. The result is that the user has very little understanding of what the underlying algorithms actually do, and why the logic he or she is presented with is the output. While TRAIDE makes it trivially easy to generate any one given trading system, as multiple individuals have stated in slightly different ways before, writing a strategy is the easy part. Doing the work to understand if that strategy actually has an edge is much harder. Namely, checking its robustness, its predictive power, its sensitivity to various regimes, and so on. Given TRAIDE8217s rather short data history (2010 onwards), and coupled with the opaqueness that the user operates under, my analogy would be this: It8217s like giving an inexperienced driver the keys to a sports car in a thick fog on a winding road. Nobody disputes that a sports car is awesome. However, the true burden of the work lies in making sure that the user doesn8217t wind up smashing into a tree. Overall, I like the TRAIDE application8217s mission, and I think it may have potential as something for the retail investors that don8217t intend to learn the ins-and-outs of coding a trading system in R (despite me demonstrating many times over how to put such systems together). I just think that there needs to be more work put into making sure that the results a user sees are indicative of an edge, rather than open the possibility of highly-flexible machine learning algorithms chasing ghosts in one of the noisiest and most dynamic data sets one can possibly find. My recommendations are these: 1) Multiple asset classes 2) Allow parameter ranges, and cap the number of trials at any given point (E. G. 4 indicators with ten settings each 10,000 possible trading systems blow up the servers). To narrow down the number of trial runs, use techniques from experimental design to arrive at decent combinations. (I wish I remembered my response surface methodology techniques from my master8217s degree about now) 3) Allow modifications of order sizing (E. G. volatility targeting, stop losses), such as I wrote about in my hypothesis-driven development posts. 4) Provide some sort of documentation for the indicators, even if it8217s as simple as a link to investopedia (preferably a lot more). 5) Far more output is necessary, especially for users who don8217t program. Namely, to distinguish whether or not there is a legitimate edge, or if there are too few observations to reject the null hypothesis of random noise. 6) Far longer data histories. 2010 onwards just seems too short of a time-frame to be sure of a strategy8217s efficacy, at least on daily data (may not be true for hourly). 7) Factor in transaction costs. Trading on an hourly time frame will mean far less PampL per trade than on a daily resolution. If MT4 charges a fixed ticket price, users need to know how this factors into their strategy. 8) Lastly, dogfooding. When I spoke last time with Inovance Tech8217s founders, they claimed they were using their own algorithms to create a forex strategy, which was doing well in live trading. By the time more of these suggestions are implemented, it8217d be interesting to see if they have a track record as a fund, in addition to as a software provider. If all of these things are accounted for and automated, the product will hopefully accomplish its mission of bringing systematic trading and machine learning to more people. I think TRAIDE has potential, and I8217m hoping that its staff will realize that potential. ขอบคุณที่อ่าน. NOTE: I am currently contracting in downtown Chicago, and am always interested in networking with professionals in the systematic trading and systematic asset managementallocation spaces. Find my LinkedIn here. EDIT: Today in my email (Dec. 3, 2015), I received a notice that Inovance was making TRAIDE completely free. Perhaps they want a bunch more feedback on it This post will demonstrate a method to create an ensemble filter based on a trade-off between smoothness and responsiveness, two properties looked for in a filter. An ideal filter would both be responsive to price action so as to not hold incorrect positions, while also be smooth, so as to not incur false signals and unnecessary transaction costs. So, ever since my volatility trading strategy, using three very naive filters (all SMAs) completely missed a 27 month in XIV. I8217ve decided to try and improve ways to create better indicators in trend following. Now, under the realization that there can potentially be tons of complex filters in existence, I decided instead to focus on a way to create ensemble filters, by using an analogy from statisticsmachine learning. In static data analysis, for a regression or classification task, there is a trade-off between bias and variance. In a nutshell, variance is bad because of the possibility of overfitting on a few irregular observations, and bias is bad because of the possibility of underfitting legitimate data. Similarly, with filtering time series, there are similar concerns, except bias is called lag, and variance can be thought of as a 8220whipsawing8221 indicator. Essentially, an ideal indicator would move quickly with the data, while at the same time, not possess a myriad of small bumps-and-reverses along the way, which may send false signals to a trading strategy. So, here8217s how my simple algorithm works: The inputs to the function are the following: A) The time series of the data you8217re trying to filter B) A collection of candidate filters C) A period over which to measure smoothness and responsiveness, defined as the square root of the n-day EMA (2(n1) convention) of the following: a) Responsiveness: the squared quantity of pricefilter 8211 1 b) Smoothness: the squared quantity of filter(t)filter(t-1) 8211 1 (aka R8217s return. calculate) function D) A conviction factor, to which power the errors will be raised. This should probably be between .5 and 3 E) A vector that defines the emphasis on smoothness (vs. emphasis on responsiveness), which should range from 0 to 1. Here8217s the code: This gets SPY data, and creates two utility functions8211xtsApply, which is simply a column-based apply that replaces the original index that using a column-wise apply discards, and sumIsNa, which I use later for counting the numbers of NAs in a given row. It also creates my candidate filters, which, to keep things simple, are just SMAs 2-250. Here8217s the actual code of the function, with comments in the code itself to better explain the process from a technical level (for those still unfamiliar with R, look for the hashtags): The vast majority of the computational time takes place in the two xtsApply calls. On 249 different simple moving averages, the process takes about 30 seconds. Here8217s the output, using a conviction factor of 2: And here is an example, looking at SPY from 2007 through 2011. In this case, I chose to go from blue to green, orange, brown, maroon, purple, and finally red for smoothness emphasis of 0, 5, 25, 50, 75, 95, and 1, respectively. Notice that the blue line is very wiggly, while the red line sometimes barely moves, such as during the 2011 drop-off. One thing that I noticed in the course of putting this process together is something that eluded me earlier8211namely, that naive trend-following strategies which are either fully long or fully short based on a crossover signal can lose money quickly in sideways markets. However, theoretically, by finely varying the jumps between 0 to 100 emphasis on smoothness, whether in steps of 1 or finer, one can have a sort of 8220continuous8221 conviction, by simply adding up the signs of differences between various ensemble filters. In an 8220uptrend8221, the difference as one moves from the most responsive to most smooth filter should constantly be positive, and vice versa. In the interest of brevity, this post doesn8217t even have a trading strategy attached to it. However, an implied trading strategy can be to be long or short the SPY depending on the sum of signs of the differences in filters as you move from responsiveness to smoothness. Of course, as the candidate filters are all SMAs, it probably wouldn8217t be particularly spectacular. However, for those out there who use more complex filters, this may be a way to create ensembles out of various candidate filters, and create even better filters. Furthermore, I hope that given enough candidate filters and an objective way of selecting them, it would be possible to reduce the chances of creating an overfit trading system. However, anything with parameters can potentially be overfit, so that may be wishful thinking. All in all, this is still a new idea for me. For instance, the filter to compute the error terms can probably be improved. The inspiration for an EMA 20 essentially came from how Basel computes volatility (if I recall, correctly, it uses the square root of an 18 day EMA of squared returns), and the very fact that I use an EMA can itself be improved upon (why an EMA instead of some other, more complex filter). In fact, I8217m always open to how I can improve this concept (and others) from readers. ขอบคุณที่อ่าน. NOTE: I am currently contracting in Chicago in an analytics capacity. If anyone would like to meet up, let me know. You can email me at ilya. kipnisgmail, or contact me through my LinkedIn here. This post will deal with a quick, finger in the air way of seeing how well a strategy scales8211namely, how sensitive it is to latency between signal and execution, using a simple volatility trading strategy as an example. The signal will be the VIXVXV ratio trading VXX and XIV, an idea I got from Volatility Made Simple8217s amazing blog. particularly this post. The three signals compared will be the 8220magical thinking8221 signal (observe the close, buy the close, named from the ruleOrderProc setting in quantstrat), buy on next-day open, and buy on next-day close. Let8217s เริ่มต้น So here8217s the run-through. In addition to the magical thinking strategy (observe the close, buy that same close), I tested three other variants8211a variant which transacts the next open, a variant which transacts the next close, and the average of those two. Effectively, I feel these three could give a sense of a strategy8217s performance under more realistic conditions8211that is, how well does the strategy perform if transacted throughout the day, assuming you8217re managing a sum of money too large to just plow into the market in the closing minutes (and if you hope to get rich off of trading, you will have a larger sum of money than the amount you can apply magical thinking to). Ideally, I8217d use VWAP pricing, but as that8217s not available for free anywhere I know of, that means that readers can8217t replicate it even if I had such data. In any case, here are the results. Log scale (for Mr. Tony Cooper and others): My reaction The execute on next day8217s close performance being vastly lower than the other configurations (and that deterioration occurring in the most recent years) essentially means that the fills will have to come pretty quickly at the beginning of the day. While the strategy seems somewhat scalable through the lens of this finger-in-the-air technique, in my opinion, if the first full day of possible execution after signal reception will tank a strategy from a 1.44 Calmar to a .92, that8217s a massive drop-off, after holding everything else constant. In my opinion, I think this is quite a valid question to ask anyone who simply sells signals, as opposed to manages assets. Namely, how sensitive are the signals to execution on the next day After all, unless those signals come at 3:55 PM, one is most likely going to be getting filled the next day. Now, while this strategy is a bit of a tomato can in terms of how good volatility trading strategies can get (they can get a lot better in my opinion), I think it made for a simple little demonstration of this technique. Again, a huge thank you to Mr. Helmuth Vollmeier for so kindly keeping up his dropbox all this time for the volatility data Thanks for reading. NOTE: I am currently contracting in a data science capacity in Chicago. You can email me at ilya. kipnisgmail, or find me on my LinkedIn here. I8217m always open to beers after work if you8217re in the Chicago area. NOTE 2: Today, on October 21, 2015, if you8217re in Chicago, there8217s a Chicago R Users Group conference at Jaks Tap at 6:00 PM. Free pizza, networking, and R, hosted by Paul Teetor, who8217s a finance guy. Hope to see you there. This post deals with an impossible-to-implement statistical arbitrage strategy using VXX and XIV. The strategy is simple: if the average daily return of VXX and XIV was positive, short both of them at the close. This strategy makes two assumptions of varying dubiousness: that one can 8220observe the close and act on the close8221, and that one can short VXX and XIV. So, recently, I decided to play around with everyone8217s two favorite instruments on this blog8211VXX and XIV, with the idea that 8220hey, these two instruments are diametrically opposed, so shouldn8217t there be a stat-arb trade here8221 So, in order to do a lick-finger-in-the-air visualization, I implemented Mike Harris8217s momersion indicator . And then I ran the spread through it. In other words, this spread is certainly mean-reverting at just about all times. And here is the code for the results from 2011 onward, from when the XIV and VXX actually started trading. Here are the equity curves: With the following statistics: In other words, the short side is absolutely amazing as a trade8211except for the one small fact of having it be impossible to actually execute, or at least as far as I8217m aware. Anyhow, this was simply a for-fun post, but hopefully it served some purpose. ขอบคุณที่อ่าน. NOTE: I am currently contracting and am looking to network in the Chicago area. You can find my LinkedIn here. Post navigation Categories

Comments

Popular posts from this blog

การฝึกอบรม ในการ แลกเปลี่ยน ซื้อขาย ใน ไฮเดอรา

อะไร เป็น ไบนารี ตัวเลือก โบรกเกอร์