0%

Book Description

Solve common and not-so-common financial problems using Python libraries such as NumPy, SciPy, and pandas

Key Features

  • Use powerful Python libraries such as pandas, NumPy, and SciPy to analyze your financial data
  • Explore unique recipes for financial data analysis and processing with Python
  • Estimate popular financial models such as CAPM and GARCH using a problem-solution approach

Book Description

Python is one of the most popular programming languages used in the financial industry, with a huge set of accompanying libraries.

In this book, you'll cover different ways of downloading financial data and preparing it for modeling. You'll calculate popular indicators used in technical analysis, such as Bollinger Bands, MACD, RSI, and backtest automatic trading strategies. Next, you'll cover time series analysis and models, such as exponential smoothing, ARIMA, and GARCH (including multivariate specifications), before exploring the popular CAPM and the Fama-French three-factor model. You'll then discover how to optimize asset allocation and use Monte Carlo simulations for tasks such as calculating the price of American options and estimating the Value at Risk (VaR). In later chapters, you'll work through an entire data science project in the financial domain. You'll also learn how to solve the credit card fraud and default problems using advanced classifiers such as random forest, XGBoost, LightGBM, and stacked models. You'll then be able to tune the hyperparameters of the models and handle class imbalance. Finally, you'll focus on learning how to use deep learning (PyTorch) for approaching financial tasks.

By the end of this book, you'll have learned how to effectively analyze financial data using a recipe-based approach.

What you will learn

  • Download and preprocess financial data from different sources
  • Backtest the performance of automatic trading strategies in a real-world setting
  • Estimate financial econometrics models in Python and interpret their results
  • Use Monte Carlo simulations for a variety of tasks such as derivatives valuation and risk assessment
  • Improve the performance of financial models with the latest Python libraries
  • Apply machine learning and deep learning techniques to solve different financial problems
  • Understand the different approaches used to model financial time series data

Who this book is for

This book is for financial analysts, data analysts, and Python developers who want to learn how to implement a broad range of tasks in the finance domain. Data scientists looking to devise intelligent financial strategies to perform efficient financial analysis will also find this book useful. Working knowledge of the Python programming language is mandatory to grasp the concepts covered in the book effectively.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Python for Finance Cookbook
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. Financial Data and Preprocessing
    1. Getting data from Yahoo Finance
      1. How to do it...
      2. How it works...
      3. There's more...
    2. Getting data from Quandl
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Getting data from Intrinio
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Converting prices to returns
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Changing frequency
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Visualizing time series data
      1. Getting ready
      2. How to do it...
        1. The plot method of pandas
        2. plotly and cufflinks
      3. How it works...
        1. The plot method of pandas
        2. plotly and cufflinks
      4. There's more...
      5. See also
    7. Identifying outliers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Investigating stylized facts of asset returns
      1. Getting ready
      2. How to do it...
        1. Non-Gaussian distribution of returns
        2. Volatility clustering
        3. Absence of autocorrelation in returns
        4. Small and decreasing autocorrelation in squared/absolute returns
        5. Leverage effect
      3. How it works...
        1. Fact 1
        2. Fact 2
        3. Fact 3
        4. Fact 4
        5. Fact 5
      4. There's more...
      5. See also
  8. Technical Analysis in Python
    1. Creating a candlestick chart
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Backtesting a strategy based on simple moving average 
      1. How to do it...
        1. Signal
        2. Strategy
      2. How it works...
        1. Common elements
        2. Signal
        3. Strategy
      3. There's more...
      4. See also 
    3. Calculating Bollinger Bands and testing a buy/sell strategy
      1. How to do it...
      2. How it works...
    4. Calculating the relative strength index and testing a long/short strategy
      1. How to do it...
      2. How it works...
    5. Building an interactive dashboard for TA
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Time Series Modeling
    1. Decomposing time series
      1. How to do it...
      2. How it works...
      3. See also
    2. Decomposing time series using Facebook's Prophet
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Testing for stationarity in time series
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Correcting for stationarity in time series
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Modeling time series with exponential smoothing methods
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Modeling time series with ARIMA class models 
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Forecasting using ARIMA class models
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  10. Multi-Factor Models
    1. Implementing the CAPM in Python
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Implementing the Fama-French three-factor model in Python
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Implementing the rolling three-factor model on a portfolio of assets
      1. How to do it...
      2. How it works...
    4. Implementing the four- and five-factor models in Python
      1. How to do it...
      2. How it works...
      3. See also
  11. Modeling Volatility with GARCH Class Models
    1. Explaining stock returns' volatility with ARCH models
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Explaining stock returns' volatility with GARCH models
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Conditional mean model
        2. Conditional volatility model
        3. Distribution of errors
      4. See also
    3. Implementing a CCC-GARCH model for multivariate volatility forecasting
      1. How to do it...
      2. How it works...
      3. See also
    4. Forecasting the conditional covariance matrix using DCC-GARCH
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  12. Monte Carlo Simulations in Finance
    1. Simulating stock price dynamics using Geometric Brownian Motion
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Pricing European options using simulations
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Pricing American options with Least Squares Monte Carlo
      1. How to do it...
      2. How it works...
      3. See also
    4. Pricing American options using Quantlib
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Estimating value-at-risk using Monte Carlo
      1. How to do it...
      2. How it works...
      3. There's more...
  13. Asset Allocation in Python
    1. Evaluating the performance of a basic 1/n portfolio
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Finding the Efficient Frontier using Monte Carlo simulations
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Finding the Efficient Frontier using optimization with scipy
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Finding the Efficient Frontier using convex optimization with cvxpy
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  14. Identifying Credit Default with Machine Learning
    1. Loading data and managing data types
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Exploratory data analysis
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Splitting data into training and test sets
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Dealing with missing values
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Encoding categorical variables
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Using pandas.get_dummies for one-hot encoding
        2. Specifying possible categories for OneHotEncoder
        3. Category Encoders library
      4. See also
    6. Fitting a decision tree classifier
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Implementing scikit-learn's pipelines
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Tuning hyperparameters using grid searches and cross-validation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  15. Advanced Machine Learning Models in Finance
    1. Investigating advanced classifiers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    2. Using stacking for improved performance
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Investigating the feature importance
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Investigating different approaches to handling imbalanced data
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Bayesian hyperparameter optimization
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  16. Deep Learning in Finance
    1. Deep learning for tabular data
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    2. Multilayer perceptrons for time series forecasting
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Convolutional neural networks for time series forecasting
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Recurrent neural networks for time series forecasting
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.147.103.8