ebook img

Python for Finance PDF

13.59 MB·English
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 Python for Finance

Preface Page: 4 Conventions Used in This Book Page: 5 Using Code Examples Page: 5 O’Reilly Online Learning Page: 5 How to Contact Us Page: 5 Acknowledgments Page: 5 I. Python and Finance Page: 7 1. Why Python for Finance Page: 8 The Python Programming Language Page: 8 A Brief History of Python Page: 8 The Python Ecosystem Page: 9 The Python User Spectrum Page: 9 The Scientific Stack Page: 9 Technology in Finance Page: 9 Technology Spending Page: 10 Technology as Enabler Page: 10 Technology and Talent as Barriers to Entry Page: 10 Ever-Increasing Speeds, Frequencies, and Data Volumes Page: 11 The Rise of Real-Time Analytics Page: 11 Python for Finance Page: 11 Finance and Python Syntax Page: 11 Efficiency and Productivity Through Python Page: 12 From Prototyping to Production Page: 14 Data-Driven and AI-First Finance Page: 15 Data-Driven Finance Page: 15 AI-First Finance Page: 16 Conclusion Page: 17 Further Resources Page: 17 2. Python Infrastructure Page: 19 conda as a Package Manager Page: 19 Installing Miniconda Page: 19 Basic Operations with conda Page: 20 conda as a Virtual Environment Manager Page: 21 Using Docker Containers Page: 22 Docker Images and Containers Page: 22 Building an Ubuntu and Python Docker Image Page: 22 Using Cloud Instances Page: 23 RSA Public and Private Keys Page: 24 Jupyter Notebook Configuration File Page: 24 Installation Script for Python and Jupyter Notebook Page: 25 Script to Orchestrate the Droplet Setup Page: 25 Conclusion Page: 26 Further Resources Page: 26 II. Mastering the Basics Page: 27 3. Data Types and Structures Page: 28 Basic Data Types Page: 28 Integers Page: 28 Floats Page: 28 Booleans Page: 29 Strings Page: 30 Excursion: Printing and String Replacements Page: 30 Excursion: Regular Expressions Page: 31 Basic Data Structures Page: 31 Tuples Page: 31 Lists Page: 32 Excursion: Control Structures Page: 32 Excursion: Functional Programming Page: 33 Dicts Page: 33 Sets Page: 33 Conclusion Page: 34 Further Resources Page: 34 4. Numerical Computing with NumPy Page: 35 Arrays of Data Page: 35 Arrays with Python Lists Page: 35 The Python array Class Page: 36 Regular NumPy Arrays Page: 36 The Basics Page: 36 Multiple Dimensions Page: 37 Metainformation Page: 38 Reshaping and Resizing Page: 38 Boolean Arrays Page: 39 Speed Comparison Page: 40 Structured NumPy Arrays Page: 40 Vectorization of Code Page: 40 Basic Vectorization Page: 40 Memory Layout Page: 41 Conclusion Page: 42 Further Resources Page: 42 5. Data Analysis with pandas Page: 43 The DataFrame Class Page: 43 First Steps with the DataFrame Class Page: 43 Second Steps with the DataFrame Class Page: 44 Basic Analytics Page: 46 Basic Visualization Page: 47 The Series Class Page: 47 GroupBy Operations Page: 47 Complex Selection Page: 48 Concatenation, Joining, and Merging Page: 49 Concatenation Page: 49 Joining Page: 49 Merging Page: 50 Performance Aspects Page: 50 Conclusion Page: 51 Further Reading Page: 51 6. Object-Oriented Programming Page: 52 A Look at Python Objects Page: 53 int Page: 53 list Page: 53 ndarray Page: 53 DataFrame Page: 53 Basics of Python Classes Page: 54 Python Data Model Page: 55 The Vector Class Page: 56 Conclusion Page: 56 Further Resources Page: 56 III. Financial Data Science Page: 57 7. Data Visualization Page: 58 Static 2D Plotting Page: 58 One-Dimensional Data Sets Page: 58 Two-Dimensional Data Sets Page: 59 Other Plot Styles Page: 60 Static 3D Plotting Page: 62 Interactive 2D Plotting Page: 63 Basic Plots Page: 63 Financial Plots Page: 64 Conclusion Page: 64 Further Resources Page: 65 8. Financial Time Series Page: 66 Financial Data Page: 66 Data Import Page: 66 Summary Statistics Page: 67 Changes over Time Page: 68 Resampling Page: 69 Rolling Statistics Page: 69 An Overview Page: 69 A Technical Analysis Example Page: 70 Correlation Analysis Page: 70 The Data Page: 70 Logarithmic Returns Page: 70 OLS Regression Page: 71 Correlation Page: 71 High-Frequency Data Page: 71 Conclusion Page: 71 Further Resources Page: 71 9. Input/Output Operations Page: 73 Basic I/O with Python Page: 73 Writing Objects to Disk Page: 73 Reading and Writing Text Files Page: 74 Working with SQL Databases Page: 75 Writing and Reading NumPy Arrays Page: 76 I/O with pandas Page: 77 Working with SQL Databases Page: 77 From SQL to pandas Page: 77 Working with CSV Files Page: 78 Working with Excel Files Page: 78 I/O with PyTables Page: 79 Working with Tables Page: 79 Working with Compressed Tables Page: 81 Working with Arrays Page: 82 Out-of-Memory Computations Page: 82 I/O with TsTables Page: 83 Sample Data Page: 83 Data Storage Page: 84 Data Retrieval Page: 84 Conclusion Page: 84 Further Resources Page: 85 10. Performance Python Page: 86 Loops Page: 86 Python Page: 86 NumPy Page: 86 Numba Page: 87 Cython Page: 87 Algorithms Page: 87 Prime Numbers Page: 87 Fibonacci Numbers Page: 88 The Number Pi Page: 89 Binomial Trees Page: 90 Python Page: 91 NumPy Page: 91 Numba Page: 91 Cython Page: 92 Monte Carlo Simulation Page: 92 Python Page: 93 NumPy Page: 93 Numba Page: 93 Cython Page: 93 Multiprocessing Page: 94 Recursive pandas Algorithm Page: 94 Python Page: 94 Numba Page: 95 Cython Page: 95 Conclusion Page: 95 Further Resources Page: 96 11. Mathematical Tools Page: 97 Approximation Page: 97 Regression Page: 97 Interpolation Page: 99 Convex Optimization Page: 100 Global Optimization Page: 100 Local Optimization Page: 101 Constrained Optimization Page: 101 Integration Page: 102 Numerical Integration Page: 103 Integration by Simulation Page: 103 Symbolic Computation Page: 103 Basics Page: 103 Equations Page: 104 Integration and Differentiation Page: 104 Differentiation Page: 104 Conclusion Page: 105 Further Resources Page: 105 12. Stochastics Page: 106 Random Numbers Page: 106 Simulation Page: 108 Random Variables Page: 108 Stochastic Processes Page: 109 Variance Reduction Page: 113 Valuation Page: 113 European Options Page: 113 American Options Page: 114 Risk Measures Page: 115 Value-at-Risk Page: 115 Credit Valuation Adjustments Page: 116 Python Script Page: 117 Conclusion Page: 118 Further Resources Page: 118 13. Statistics Page: 119 Normality Tests Page: 119 Benchmark Case Page: 119 Real-World Data Page: 122 Portfolio Optimization Page: 123 The Data Page: 123 The Basic Theory Page: 124 Optimal Portfolios Page: 125 Efficient Frontier Page: 126 Capital Market Line Page: 126 Bayesian Statistics Page: 128 Bayes’ Formula Page: 128 Bayesian Regression Page: 128 Two Financial Instruments Page: 129 Updating Estimates over Time Page: 130 Machine Learning Page: 131 Unsupervised Learning Page: 131 Supervised Learning Page: 132 Conclusion Page: 136 Further Resources Page: 137 IV. Algorithmic Trading Page: 138 14. The FXCM Trading Platform Page: 139 Getting Started Page: 139 Retrieving Data Page: 139 Retrieving Tick Data Page: 139 Retrieving Candles Data Page: 140 Working with the API Page: 141 Retrieving Historical Data Page: 141 Retrieving Streaming Data Page: 141 Placing Orders Page: 142 Account Information Page: 142 Conclusion Page: 143 Further Resources Page: 143 15. Trading Strategies Page: 144 Simple Moving Averages Page: 144 Data Import Page: 144 Trading Strategy Page: 144 Vectorized Backtesting Page: 145 Optimization Page: 145 Random Walk Hypothesis Page: 146 Linear OLS Regression Page: 147 The Data Page: 147 Regression Page: 148 Clustering Page: 148 Frequency Approach Page: 149 Classification Page: 149 Two Binary Features Page: 149 Five Binary Features Page: 150 Five Digitized Features Page: 150 Sequential Train-Test Split Page: 150 Randomized Train-Test Split Page: 151 Deep Neural Networks Page: 151 DNNs with scikit-learn Page: 151 DNNs with TensorFlow Page: 152 Conclusion Page: 153 Further Resources Page: 153 16. Automated Trading Page: 155 Capital Management Page: 155 The Kelly Criterion in a Binomial Setting Page: 155 The Kelly Criterion for Stocks and Indices Page: 157 ML-Based Trading Strategy Page: 158 Vectorized Backtesting Page: 158 Optimal Leverage Page: 160 Risk Analysis Page: 160 Persisting the Model Object Page: 161 Online Algorithm Page: 161 Infrastructure and Deployment Page: 162 Logging and Monitoring Page: 163 Conclusion Page: 164 Python Scripts Page: 164 Automated Trading Strategy Page: 164 Strategy Monitoring Page: 164 Further Resources Page: 164 V. Derivatives Analytics Page: 166 17. Valuation Framework Page: 167 Fundamental Theorem of Asset Pricing Page: 167 A Simple Example Page: 167 The General Results Page: 167 Risk-Neutral Discounting Page: 168 Modeling and Handling Dates Page: 168 Constant Short Rate Page: 169 Market Environments Page: 169 Conclusion Page: 170 Further Resources Page: 170 18. Simulation of Financial Models Page: 172 Random Number Generation Page: 172 Generic Simulation Class Page: 172 Geometric Brownian Motion Page: 174 The Simulation Class Page: 174 A Use Case Page: 175 Jump Diffusion Page: 175 The Simulation Class Page: 176 A Use Case Page: 176 Square-Root Diffusion Page: 177 The Simulation Class Page: 177 A Use Case Page: 178 Conclusion Page: 178 Further Resources Page: 178 19. Derivatives Valuation Page: 180 Generic Valuation Class Page: 180 European Exercise Page: 181 The Valuation Class Page: 181 A Use Case Page: 182 American Exercise Page: 183 Least-Squares Monte Carlo Page: 183 The Valuation Class Page: 184 A Use Case Page: 185 Conclusion Page: 186 Further Resources Page: 186 20. Portfolio Valuation Page: 188 Derivatives Positions Page: 188 The Class Page: 188 A Use Case Page: 188 Derivatives Portfolios Page: 189 The Class Page: 189 A Use Case Page: 190 Conclusion Page: 192 Further Resources Page: 193 21. Market-Based Valuation Page: 194 Options Data Page: 194 Model Calibration Page: 194 Relevant Market Data Page: 194 Option Modeling Page: 195 Calibration Procedure Page: 196 Portfolio Valuation Page: 198 Modeling Option Positions Page: 198 The Options Portfolio Page: 198 Python Code Page: 199 Conclusion Page: 199 Further Resources Page: 200 A. Dates and Times Page: 201 Python Page: 201 NumPy Page: 202 pandas Page: 203 B. BSM Option Class Page: 205 Class Definition Page: 205 Class Usage Page: 205 Index Page: 206

Description:
The financial industry has recently adopted Python at a tremendous rate, with some of the largest investment banks and hedge funds using it to build core trading and risk management systems. Updated for Python 3, the second edition of this hands-on book helps you get started with the language, guiding developers and quantitative analysts through Python libraries and tools for building financial applications and interactive financial analytics. Using practical examples throughout the book, author Yves Hilpisch also shows you how to develop a full-fledged framework for Monte Carlo simulation-based derivatives and risk analytics, based on a large, realistic case study. Much of the book uses interactive IPython Notebooks.
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.