ebook img

R for programmers. Quantitative investment applications PDF

387 Pages·2018·17.568 MB·English
by  ZhangDan
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview R for programmers. Quantitative investment applications

R for Programmers R for Programmers Quantitative Investment Applications Dan Zhang Published in 2018 by CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2018 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group No claim to original U.S. Government works Printed in the United States of America on acid-free paper 10 9 8 7 6 5 4 3 2 1 International Standard Book Number-13: 978-1-4987-3689-3 (Paperback) This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materials or for the consequences of their use. No part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http:// www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Zhang, Dan, 1983- author. Title: R for programmers. Quantitative investment applications/Dan Zhang. Description: Boca Raton, FL : CRC Press/Taylor & Francis Group, 2018. | “A CRC title, part of the Taylor & Francis imprint, a member of the Taylor & Francis Group, the academic division of T&F Informa plc.” | Includes bibliographical references and index. Identifiers: LCCN 2018000799 (print) | LCCN 2018006702 (ebook) | ISBN 9781315382197 (e) | ISBN 9781498736893 (pbk. : acid-free paper) | ISBN 1498736890 (pbk. : acid-free paper) Subjects: LCSH: Investment analysis--Data processing. | R (Computer program language) Classification: LCC HG4529 (ebook) | LCC HG4529 .Z48 2018 (print) | DDC 332.60285/5133--dc23 LC record available at https://lccn.loc.gov/2018000799 Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com Contents Foreword ..................................................................................................................................vii Preface .......................................................................................................................................ix Acknowledgments ..................................................................................................................xiii Author .......................................................................................................................................xv SeCtion i FinAnCiAL MARKet AnD FinAnCiAL tHeoRY 1 Financial Market Overview ..........................................................................................3 1.1 R for Quantification ................................................................................................3 1.2 H ow Algorithms Change Fate ................................................................................14 1.3 F inTech, the Booming Sector in Finance Field ......................................................20 1.4 Quantitative Investment Tools in China.................................................................25 1.5 Low-Risk Trading Strategy in China .....................................................................39 2 Financial Theory.........................................................................................................51 2.1 R Interpretation of Capital Asset Pricing Model (CAPM) ......................................51 2.2 R Interpretation of Simple Linear Regression Model .............................................66 2.3 R Interpretation of Multiple Linear Regression Model ..........................................79 2.4 R Interpretation of Autoregression Model ...............................................................91 SeCtion ii DAtA PRoCeSSinG AnD HiGH PeRFoRMAnCe CoMPUtinG oF R 3 Data Processing of R ................................................................................................103 3.1 Family of apply Functions ....................................................................................103 3.2 U ltra-High Performance Data Processing Package: data.table ..............................117 3.3 Efficient Pipe Operation of R: magrittr ................................................................132 3.4 String Processing Package of R: stringr.................................................................140 3.5 Chinese Words Segmentation Package of R: jiebaR ..............................................157 4 High Performance Computing of R .........................................................................171 4.1 OpenBlas Speeds Up Matrix Calculation of R .....................................................171 4.2 R Calls C++ across Boundary ...............................................................................179 4.3 W hen R Meets Docker .........................................................................................194 v vi ◾ Contents SeCtion iii FinAnCiAL StRAteGY PRACtiCe 5 Bonds and Repurchase .............................................................................................205 5.1 T reasury Bonds ....................................................................................................205 5.2 Enterprise Bonds and the Arbitrage ......................................................................215 5.3 Convertible Bonds Arbitrage Practice ..................................................................227 5.4 Reverse Repurchase with Risk-Free Financial Instruments ..................................244 6 Quantitative Investment Strategy Cases ..................................................................255 6.1 M ean Reversion, the Investment Opportunity against Market .............................255 6.2 B uild Quantitative Trading Model of Upswing Buying and Downswing Selling with R .......................................................................................................276 6.3 B uild Quantitative Model of Pairs Trading with R ..............................................294 6.4 F und Accounting System Design and Implementation ........................................308 6.5 D ata Interpretation of Machine Gene Investment ................................................332 Epilogue ............................................................................................................................349 Appendix: Docker Installation in Ubuntu ........................................................................351 Index .................................................................................................................................361 Foreword It’s my pleasure to have this opportunity to recommend Mr. Dan Zhang’s new book in quantita- tive trading using R. I knew Dan Zhang from his blog and his books about R. Since then, we started discussing trading ideas via emails and phone calls. His R books have been very useful to me. He is a very sincere person and is willing to share what he has learned with other people. As far as I know, he is well known and very active in the R community in China. He began his career as an IT engineer and now focuses on bank IT infrastructures and trading. His new R book covers several topics, including financial markets in China, data management and high performance computing, financial theory and quantitative investment strategies. Here are some topics I find very useful: ◾ A chapter focuses on Fast Data Handling and Processing with C ++ procedures. ◾ A chapter discusses the Docker architecture, which provides guidelines on the automated deployment of applications. ◾ An excellent example of using R on a convertible bond system, which forms the basis for designing a more advanced bond trading model. ◾ A chapter on the fundamental principles of quantitative trading and how to apply them to the real world. ◾ A mutual fund IT system which is very useful for the operation and management of funds. ◾ A case study on a China Robo Advisor company which gives us insights of wealth manage- ment business in China. To be honest, it’s rare to see a book which covers so many useful topics. I have learned a lot from Dan’s new book and I highly recommend that everyone should keep one copy on the bookshelf. Max Chen, Ph.D. University of Washington Founder, Magic Flute Capital Management vii Preface Why Did i Write this Book? This is the third book of the series R for Programmers. It combines R language with quantitative investment of finance, mainly to achieve the combination of the technology of R language and the practical cases of financial quantification and to help readers experience how to turn knowledge into real productivity. Traditional traders watch the quotes and market situations every day by using their transaction experience of years. A good trader can simultaneously observe dozens of trading instruments in several financial markets. As the development of financial products, there are already over 3000 A-shares, more than 7000 bonds, almost 4000 publicly offered funds and various financial deriva- tives in China’s market. There are too many for manual labor to digest and analyze. However, with a computer, we can scan the whole market to discover the irrational pricing and the arbitrage opportunities, which will tremendously improve the work efficiency of traders. An ideal design to deal and make money with programs will free us to do whatever we like. The realization of technology will liberate our life. The original thoughts and methods stated in this book are what I learned from the applica- tion of theory research. Actually, I have been, for a long time, looking for such a book, in which theoretical models and practical cases are combined. Unfortunately, I didn’t find any; or rather, I didn’t find any that contain practical cases suitable for China’s market. Therefore, I had to write one myself. The contents of this book are, kind of, notes I kept. I review them a lot to help clear my mind. Features of this Book A main thought of writing this book was, from the perspective of IT practitioners, to introduce technology to the financial market and make quantitative investments with it. Then with the spirit of IT practitioners that concentrate on learning and are willing to share and with the rapid spread of the Internet, we would break the traditional financial barriers. Exploit the creativity of geeks, turn knowledge into productivity and enable more ambitious IT practitioners to have the opportunities to enter the financial field, thus to propel the revolution and innovation of financial industry. However, this is not a book that can be easily understood, for quantitative investment is a cross-discipline field. You need to prepare yourselves with knowledge of multiple disciplines to be competent in quantitative investment jobs. To comprehend the contents of the book, knowledge of many books may be needed. ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.