Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Pandas for Finance
Mastering Pandas for Finance

Mastering Pandas for Finance: Master pandas, an open source Python Data Analysis Library, for financial data analysis

eBook
₹799.99 ₹2919.99
Paperback
₹3649.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering Pandas for Finance

Chapter 1. Getting Started with pandas Using Wakari.io

In Mastering pandas for Finance, we will examine the use of pandas to manage financial data and perform various financial analyses with a specific focus on financial processes that can be facilitated using the capabilities provided within pandas, along with an occasional quantitative financial technique. I have made an assumption that you have basic knowledge of Python programming and have used IPython and IPython Notebooks. Knowledge of pandas is preferred, but we will cover enough information on pandas for any reader to be able to understand the technique being used. We will occasionally and briefly touch upon areas of quantitative finance, but those times will be mostly for information purposes and will have implementations that are provided in the code of the text.

During this voyage of discovery, we will begin with an overview/review of concepts and data structures in pandas that are of importance to financial analysis. We will then move into various concepts, techniques, tools, and examples of specific financial analysis problems as solved with Python, pandas, and several other Python libraries and tools, including Wakari, matplotlib, SciPy, Quandl, Zipline, and Mibian. These will be varied in nature, and topics ranging from analysis of historical stock data, correlating search data with trends in stock prices, algorithmic trading and backtesting, options modeling and pricing, and portfolio and risk analysis will be covered.

In this first chapter, we will walk through creating an account and environment in Wakari.io and installing the code samples into that environment. I have chosen Wakari.io as a basis for a pandas-based financial environment because it is relatively painless to get up and running with all of the tools we will utilize, and also the samples provided in the code bundle of this book are in the IPython Notebook format, which is simple to use within Wakari.io.

The use of Wakari, however, does not prevent you from using your own Python environment. The examples in the text will run in any Python environment and were originally built using the Anaconda and IPython Notebook formats with all of the mentioned tools installed within the environment. Just in case you don't want to use Wakari, all the code examples in the text are presented as IPython and will run in a properly configured IPython environment.

So, let's get started. In this chapter, we will cover the following topics:

  • What is Wakari.io?
  • Creating a Wakari account
  • Updating the default Wakari environment to run all our examples
  • Installing and running the code samples in Wakari

What is Wakari?

Wakari (http://continuum.io/wakari) is a collaborative data analytics platform that allows you to explore data and create analytic scripts in collaboration with IPython Notebooks. It is an offering of Continuum Analytics, the creators of the Anaconda Python distribution, which is generally considered to be one of the best Python distributions. Wakari is offered as a solution that you can run in your enterprise at an expense, or as a web- or cloud-based solution offered on a freemium basis. The following screenshot shows Wakari as an offering of Continuum Analytics:

What is Wakari?

The approach in this text will be to guide you in using the cloud-based Wakari solution. This environment provides an effective quick start to learning pandas and performing all the data analysis in this text but with very minimal effort in managing a local Python installation.

Creating a Wakari cloud account

The cloud-based offering for Wakari is available at https://wakari.io. For convenience, from this point on, I will refer to Wakari.io as Wakari, but always know that I am referring to the cloud-based solution.

Wakari is a freemium service that allows you to run web-based Python distributions. Specifics on the free part of the freemium services can be found on the site, but all of the examples in this text can be run for free in the Wakari environment (at least at the time of writing this book). Wakari offers very low resistance to success in learning all of the concepts in this text as well as many others.

The guidance in this chapter will take you through creating and setting up an online Python environment, which can run all of the examples in this book. To start, open your browser and enter https://wakari.io in the address bar. This will display the following page:

Creating a Wakari cloud account

Sign up for a new account, and upon successful registration for the service, you will be presented with the following web interface to manage IPython Notebooks:

Creating a Wakari cloud account

IPython Notebooks are a default feature in Wakari for the purpose of developing Python applications. All the examples in this book were developed as IPython Notebooks, although the code can be run sequentially in IPython or even Python. An advantage of IPython Notebooks is the ability to intermix markdown with Python code within a semi-dynamic web page, which allows easy reuse of code, and perhaps more importantly, publishing of code on the Web.

As a matter of fact, you can find all the code files for this book on Wakari at https://wakari.io/sharing/bundle/Pandas4Finance/MasteringPandas4Finance_Index.

At the time of writing this book, the default Python environment provided by Wakari is Python 2.7.9, and more specifically, Anaconda 1.9.1 (all version numbers are at the time of writing, so when you read this, they may be newer). This is, in general, a good environment for what we want to accomplish in this book, although a few packages need updating and several others need to be installed. In Wakari, pandas is currently at 0.16.0, which is satisfactory for our needs.

The specific packages that either need updating or installing are as follows:

  • matplotlib
  • Zipline
  • Quandl
  • html5lib
  • Mibian
  • tzlocal

We will go over each of these briefly and also see how to install/update each. In general, the update/install process will be performed using a shell within Wakari. One of the spectacular features of Wakari includes running both interactive IPython sessions and operating system shells directly in the browser.

From a new environment within Wakari, you can open terminals using the Terminals tab. Click on the Terminals tab, and you will see the following screenshot, which represents a default IPython shell for your account (currently referred to as np18py27-19):

Creating a Wakari cloud account

You can perform any Python programming within this web-based interface, including all of the examples in this book. However, the default Wakari environment needs a few updates and first-time installs to run all of the examples in the text.

We can perform updates to the environment by opening a shell. This can be performed by selecting Shell from the drop-down menu, along with np18py27-1.9, and pressing the +Tab button. After that, you will be presented with the following screenshot:

Creating a Wakari cloud account

We are now in an OS shell that provides you with many options, including updating your Python environment, which we will now perform.

Updating existing packages

We need to update one package in the default Wakari environment—matplotlib. This is the graphics package we will use at various points in this book. For most of the purposes, the version in Wakari (1.3.1) is satisfactory, but the candlestick charts that we will create require an update to matplotlib from 1.3.1 to a higher version. This is performed with the conda package manager using the conda update matplotlib command. When issuing this, you will see something similar to the following in the terminal tab in your web browser:

Updating existing packages

Installing new packages

The remainder of the packages need to be installed. All these package installations follow the same process, although there are slightly different commands, which alternate between using pip and the conda package manager for installation.

For time zone operations, tzlocal is used and is updated using pip. The installation is performed as shown here:

Installing new packages

The samples do not use html5lib directly, but other libraries do use it indirectly. We will use these libraries to read and parse data. We need to update this using conda, as shown here:

Installing new packages

A library provided at https://www.quandl.com/, Quandl is a provider of data that you can integrate into your applications via download or the API. The Python API that we will use to access S&P 500 data is free and can be installed using conda, as shown here:

Installing new packages

Available at https://www.quantopian.com/, Zipline is a backtesting/trading simulator that we will use. Quantopian is a website that focuses on algorithmic trading, and it produces Zipline, which it uses as one of its underlying technologies. Although installed using conda, Zipline requires the use of a different channel. Notice the slight variation in the use of conda to specify the Quantopian channel in the following screenshot:

Installing new packages

The final package we need to install is Mibian, a small library that computes Black-Scholes and its derivatives. This is installed using pip, as shown here:

Installing new packages

We are now ready to run any of the sample Notebooks.

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Installing the samples in Wakari

To install the examples in Wakari, download the code bundle and unzip the files to a local directory. You will see a set of files as shown here:

Installing the samples in Wakari

To upload the files to Wakari, click on the upload files icon and drag the files into the Drag & Drop Here section of the web page:

Installing the samples in Wakari

Once dropped, click on the Upload Files button, and you will see the following files in your Wakari directory:

Installing the samples in Wakari

At this point, you should be able to open and run any of the Notebooks and even examine the data in the browser. As an example, the following screenshot demonstrates the Notebook for Chapter 2, Introducing the Series and DataFrame, opened in Wakari:

Installing the samples in Wakari

Summary

This chapter was a brief introduction to this book. You learned how to set up a Python environment in Wakari.io to be able to run the code samples provided throughout the text. This included instructions on how to update the default Wakari.io Python environment to support the required packages that are required for all of the examples in the remainder of the text.

In the next chapter, we will dive into using pandas and its core data structures, Series and DataFrame. These will be core to representing data in later chapters, where we primarily use pandas DataFrame objects to represent financial data, which we apply to various financial analyses.

Left arrow icon Right arrow icon
Download code icon Download Code

Description

If you are interested in quantitative finance, financial modeling, and trading, or simply want to learn how Python and pandas can be applied to finance, then this book is ideal for you. Some knowledge of Python and pandas is assumed. Interest in financial concepts is helpful, but no prior knowledge is expected.

Who is this book for?

If you are interested in quantitative finance, financial modeling, and trading, or simply want to learn how Python and pandas can be applied to finance, then this book is ideal for you. Some knowledge of Python and pandas is assumed. Interest in financial concepts is helpful, but no prior knowledge is expected.

What you will learn

  • Modeling and manipulating financial data using the pandas DataFrame
  • Indexing, grouping, and calculating statistical results on financial information
  • Timeseries modeling, frequency conversion, and deriving results on fixed and moving windows
  • Calculating cumulative returns and performing correlations with index and social data
  • Algorithmic trading and backtesting using momentum and mean reversion strategies
  • Option pricing and calculation of Value at Risk
  • Modeling and optimization of financial portfolios

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 25, 2015
Length: 298 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985104
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 25, 2015
Length: 298 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985104
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 11,396.97
Mastering Python for Finance
₹4096.99
Python for Finance
₹3649.99
Mastering Pandas for Finance
₹3649.99
Total 11,396.97 Stars icon

Table of Contents

10 Chapters
1. Getting Started with pandas Using Wakari.io Chevron down icon Chevron up icon
2. Introducing the Series and DataFrame Chevron down icon Chevron up icon
3. Reshaping, Reorganizing, and Aggregating Chevron down icon Chevron up icon
4. Time-series Chevron down icon Chevron up icon
5. Time-series Stock Data Chevron down icon Chevron up icon
6. Trading Using Google Trends Chevron down icon Chevron up icon
7. Algorithmic Trading Chevron down icon Chevron up icon
8. Working with Options Chevron down icon Chevron up icon
9. Portfolios and Risk Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(6 Ratings)
5 star 0%
4 star 66.7%
3 star 33.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Jul 01, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book brings together several important concepts in finance and explains how to implement them using a core of Python and pandas. Some of the key topics included in the books are:Wakari.io - a collaborative data analytics platform that allows to explore data and create analytic scripts in collaboration with IPython Notebooks.Introduction to the Series and DataFrame objectsA chapter on Reshaping, Reorganizing, and Aggregating DataCorrelations of Google trends with stock movements, creating algorithmic trading systemsCalculating options payoffs, prices, and behaviorsConstructing an efficient portfolioAn overview of modern portfolio theory and Computing Value at Risk (VaR)I liked that the provided code is in the form of ipython notebook.Disclaimer: I received this eBook as a complementary copy.
Amazon Verified review Amazon
yatgonewest Aug 30, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I would recommend this book as a good basic intro to the fundamentals of Pandas even if you're not particularly interested in applying it to finance. I have read portions of a few others and this authors style is very concise and to the point on Series and DataFrames, and in particular on indexing of both.
Amazon Verified review Amazon
Al Krinker Oct 07, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I wish I could give it 5 stars, but since this book was poorly edited by tech reviewer that missed many errors, I can't go above 3... The content is great and it def will get you going, but some formulas for example Value at Risk at the very end is incorrect and even in example it is wrong (they forgot the mean!)
Amazon Verified review Amazon
ajk251 Jul 11, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I found this book to be a useful one - it nicely covers all the pandas/finance basics. If your're a bit of a novice in either one, this book provides a nice introduction. It doesn't waste time with a Python introduction or other book-filling topics. It shows how to do all of the most useful operations in pandas as they relate to finance. Then it goes into options, portfolio theory, and applying pandas to a Google Trends project. I particularly liked the section on Zipline, a back-testing library. It was a little clearer than the documentation. The part where Quandl is used is also nice.That said, if you dug around the internet, you could probably cobble these examples together. Also, it doesn't really go into either pandas or finance too deeply. I don't hold those against the book - it can't be all things to all people. The book makes for a nice overview of the relevant topics - but expect an overview.Note: I was asked to give a review of the book by the publisher in exchange for a free ebook (I purchased the book from the publisher).
Amazon Verified review Amazon
Ho Yan Chan May 02, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
ok
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.