35,99 €
Python is one of the most popular programming languages in the financial industry, with a huge collection of accompanying libraries. In this new edition of the Python for Finance Cookbook, you will explore classical quantitative finance approaches to data modeling, such as GARCH, CAPM, factor models, as well as modern machine learning and deep learning solutions.
You will use popular Python libraries that, in a few lines of code, provide the means to quickly process, analyze, and draw conclusions from financial data. In this new edition, more emphasis was put on exploratory data analysis to help you visualize and better understand financial data. While doing so, you will also learn how to use Streamlit to create elegant, interactive web applications to present the results of technical analyses.
Using the recipes in this book, you will become proficient in financial data analysis, be it for personal or professional projects. You will also understand which potential issues to expect with such analyses and, more importantly, how to overcome them.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 878
Veröffentlichungsjahr: 2022
Python for Finance Cookbook
Second Edition
Over 80 powerful recipes for effective financial data analysis
Eryk Lewinson
BIRMINGHAM—MUMBAI
“Python” and the Python Logo are trademarks of the Python Software Foundation.
Python for Finance Cookbook
Second Edition
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Senior Publishing Product Manager: Devika Battike
Acquisition Editor – Peer Reviews: Gaurav Gavas
Project Editor: Rianna Rodrigues
Content Development Editor: Edward Doxey
Copy Editor: Safis Editing
Technical Editor: Karan Sonawane
Proofreader: Safis Editing
Indexer: Rekha Nair
Presentation Designer: Ganesh Bhadwalkar
Developer Relations Marketing Executive: Vidhi Vashisth
First published: Jan 2020
Second edition: Dec 2022
Production reference: 2291222
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80324-319-1
www.packt.com
Eryk Lewinson received his master’s degree in Quantitative Finance from Erasmus University Rotterdam. In his professional career, he has gained experience in the practical application of data science methods while working in risk management and data science departments of two “big 4” companies, a Dutch neo-broker and most recently the Netherlands’ largest online retailer.
Outside of work, he has written over a hundred articles about topics related to data science, which have been viewed more than 3 million times. In his free time, he enjoys playing video games, reading books, and traveling with his girlfriend.
Writing the second edition of my book was a unique experience. On the one hand, I knew what I should expect. On the other, it proved to be much more challenging in terms of both improving the existing content and expanding upon it. I must also admit that it was a very rewarding feeling to be contacted by readers with kind words about the first edition and valuable feedback on what to add and improve. Thanks to all of that, I have certainly learned a lot, and—in the end—I will remember those times fondly.
I would like to thank Agnieszka for her undeterred support and patience, my brother for once again being my first reader, and my mom for always having my back. I also greatly appreciated all the words of encouragement from my friends and colleagues. Without all of you, completing this book would not have been possible. Thank you.
Roman Paolucci is a quantitative researcher specializing in the use of applied natural language processing and machine learning to extract equity trading signals. He is the course director and founder of Quant Guild (https://quantguild.com), an online community dedicated to education on topics pertaining to quantitative finance, data science, and software engineering. Roman is also the maintainer and sole contributor of the popular quantitative finance Python library QFin, available on GitHub and PyPi for use in the simulation of stochastic processes and various derivative pricing settings. His current research interests include natural language processing, machine learning for derivative pricing, randomized numerical linear algebra, and optimal portfolio hedging via reinforcement learning.
Thank you to my family and friends—without them none of my work would be possible.
To join the Discord community for this book – where you can share feedback, ask questions to the author, and learn about new releases – follow the QR code below:
https://packt.link/ips2H
Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
Acquiring Financial Data
Getting data from Yahoo Finance
Getting data from Nasdaq Data Link
Getting data from Intrinio
Getting data from Alpha Vantage
Getting data from CoinGecko
Summary
Data Preprocessing
Converting prices to returns
Adjusting the returns for inflation
Changing the frequency of time series data
Different ways of imputing missing data
Converting currencies
Different ways of aggregating trade data
Summary
Visualizing Financial Time Series
Basic visualization of time series data
Visualizing seasonal patterns
Creating interactive visualizations
Creating a candlestick chart
Summary
Exploring Financial Time Series Data
Outlier detection using rolling statistics
Outlier detection with the Hampel filter
Detecting changepoints in time series
Detecting trends in time series
Detecting patterns in a time series using the Hurst exponent
Investigating stylized facts of asset returns
Summary
Technical Analysis and Building Interactive Dashboards
Calculating the most popular technical indicators
Downloading the technical indicators
Recognizing candlestick patterns
Building an interactive web app for technical analysis using Streamlit
Deploying the technical analysis app
Summary
Time Series Analysis and Forecasting
Time series decomposition
Testing for stationarity in time series
Correcting for stationarity in time series
Modeling time series with exponential smoothing methods
Modeling time series with ARIMA class models
Finding the best-fitting ARIMA model with auto-ARIMA
Summary
Machine Learning-Based Approaches to Time Series Forecasting
Validation methods for time series
Feature engineering for time series
Time series forecasting as reduced regression
Forecasting with Meta’s Prophet
AutoML for time series forecasting with PyCaret
Summary
Multi-Factor Models
Estimating the CAPM
Estimating the Fama-French three-factor model
Estimating the rolling three-factor model on a portfolio of assets
Estimating the four- and five-factor models
Estimating cross-sectional factor models using the Fama-MacBeth regression
Summary
Modeling Volatility with GARCH Class Models
Modeling stock returns’ volatility with ARCH models
Modeling stock returns’ volatility with GARCH models
Forecasting volatility using GARCH models
Multivariate volatility forecasting with the CCC-GARCH model
Forecasting the conditional covariance matrix using DCC-GARCH
Summary
Monte Carlo Simulations in Finance
Simulating stock price dynamics using a geometric Brownian motion
Pricing European options using simulations
Pricing American options with Least Squares Monte Carlo
Pricing American options using QuantLib
Pricing barrier options
Estimating Value-at-Risk using Monte Carlo
Summary
Asset Allocation
Evaluating an equally-weighted portfolio’s performance
Finding the efficient frontier using Monte Carlo simulations
Finding the efficient frontier using optimization with SciPy
Finding the efficient frontier using convex optimization with CVXPY
Finding the optimal portfolio with Hierarchical Risk Parity
Summary
Backtesting Trading Strategies
Vectorized backtesting with pandas
Event-driven backtesting with backtrader
Backtesting a long/short strategy based on the RSI
Backtesting a buy/sell strategy based on Bollinger bands
Backtesting a moving average crossover strategy using crypto data
Backtesting a mean-variance portfolio optimization
Summary
Applied Machine Learning: Identifying Credit Default
Loading data and managing data types
Exploratory data analysis
Splitting data into training and test sets
Identifying and dealing with missing values
Encoding categorical variables
Fitting a decision tree classifier
Organizing the project with pipelines
Tuning hyperparameters using grid searches and cross-validation
Summary
Advanced Concepts for Machine Learning Projects
Exploring ensemble classifiers
Exploring alternative approaches to encoding categorical features
Investigating different approaches to handling imbalanced data
Leveraging the wisdom of the crowds with stacked ensembles
Bayesian hyperparameter optimization
Investigating feature importance
Exploring feature selection techniques
Exploring explainable AI techniques
Summary
Deep Learning in Finance
Exploring fastai’s Tabular Learner
Exploring Google’s TabNet
Time series forecasting with Amazon’s DeepAR
Time series forecasting with NeuralProphet
Summary
Other Books You May Enjoy
Index
Cover
Index
Once you’ve read Python for Finance Cookbook - Second Edition, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link belowhttps://packt.link/free-ebook/9781803243191
Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directly