Weiming | Mastering Python for Finance | E-Book | www.sack.de
E-Book

E-Book, Englisch, 340 Seiten

Weiming Mastering Python for Finance

Understand, design, and implement state-of-the-art mathematical and statistical applications used in finance with Python
1. Auflage 2024
ISBN: 978-1-78439-787-6
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)

Understand, design, and implement state-of-the-art mathematical and statistical applications used in finance with Python

E-Book, Englisch, 340 Seiten

ISBN: 978-1-78439-787-6
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)



If you are an undergraduate or graduate student, a beginner to algorithmic development and research, or a software developer in the financial industry who is interested in using Python for quantitative methods in finance, this is the book for you. It would be helpful to have a bit of familiarity with basic Python usage, but no prior experience is required.

Weiming Mastering Python for Finance jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


Table of Contents - Python for Financial Applications
- The Importance of Linearity in Finance
- Nonlinearity in Finance
- Numerical Procedures
- Interest Rates and Derivatives
- Interactive Financial Analytics with Python and VSTOXX
- Big Data Analytics with Python
- Algorithmic Trading
- Backtesting
- Excel with Python


Introducing IPython


IPython is an interactive shell with high-performance tools used for parallel and distributed computing. With the IPython Notebook, you can share code, text, mathematical expressions, plots, and other rich media with your target audience.

In this section, we will learn how to get started and run a simple IPython Notebook.

Getting IPython


Depending on how you have installed Python on your machine, IPython might have been included in your Python environment. Please consult the IPython official documentation for the various installation methods most comfortable for you. The official page is available at http://ipython.org.

IPython can be downloaded from https://github.com/ipython. To install IPython, unpack the packages to a folder. From the terminal, navigate to the top-level source directory and run the following command:

$ python setup.py install

Using pip


The tool is a great way to install Python packages automatically. Think of it as a package manager for Python. For example, to install IPython without having to download all the source files, just run the following command in the terminal:

$ pip install ipython

To get pip to work in the terminal, it has to be installed as a Python module. Instructions for downloading and installing pip can be found at https://pypi.python.org/pypi/pip.

The IPython Notebook


The IPython Notebook is the web-based interactive computing interface of IPython used for the whole computation process of developing, documenting, and executing the code. This section covers some of the common features in IPython Notebook that you may consider using for building financial applications.

Here is a screenshot of the IPython Notebook in Windows OS:

Notebooks allow in-browser editing and executing of the code with the outputs attached to the code that generated them. It has the capability of displaying rich media, including images, videos, and HTML components.

Its in-browser editor allows the Markdown language that can provide rich text and commentary for the code.

Mathematical notations can be included with the use of LaTeX, rendered natively by MathJax. With the ability to import Python modules, publication-quality figures can be included inline and rendered using the library.

Notebook documents


Notebook documents are saved with the extension. Each document contains everything related to an interactive session, stored internally in the JSON format. Since JSON files are represented in plain text, this allows notebooks to be version controlled and easily sharable.

Notebooks can be exported to a range of static formats, including HTML, LaTeX, PDF, and slideshows.

Notebooks can also be available as static web pages and served to the public via URLs using (IPython Notebook Viewer) without users having to install Python. Conversion is handled using the service.

Running the IPython Notebook


Once you have IPython successfully installed in the terminal, type the following command:

$ ipython notebook

This will start the IPython Notebook server service, which runs in the terminal. By default, the service will automatically open your default web browser and navigate to the landing page. To access the notebook program manually, enter the URL address in your web browser.

Tip


By default, a notebook runs in port 8888. To infer the correct notebook address, check the log output from the terminal.

The landing page of the notebook web application is called the dashboard, which shows all notebooks currently available in the notebook directory. By default, this directory is the one from which the notebook server was started.

Creating a new notebook


Click on New Notebook from the dashboard to create a new notebook. You can navigate to the File | New menu option from within an active notebook:

Here, you will be presented with the notebook name, a menu bar, a toolbar, and an empty code cell.

The menu bar presents different options that may be used to manipulate the way the notebook functions.

The toolbar provides shortcuts to frequently used notebook operations in the form of icons.

Notebook cells


Each logical section in a notebook is known as a cell. A cell is a multi-line text input field that accepts plain text. A single notebook document contains at least one cell and can have multiple cells.

To execute the contents of a cell, from the menu bar, go to Cell | Run, or click on the Play button from the toolbar, or use the keyboard shortcut + .

Each cell can be formatted as a Code, Markdown, Raw NBConvert, or heading cell:

Code cell


By default, each cell starts off as a code cell, which executes the Python code when you click on the Run button. Cells with a rounded rectangular box and gray background accept text inputs. The outputs of the executed box are displayed in the white space immediately below the text input.

Markdown cell


Markdown cells accept the Markdown language that provides a simple way to format plain text into rich text. It allows arbitrary HTML code for formatting.

Mathematical notations can be displayed with standard LaTeX and AMS-LaTeX (the package). Surround the LaTeX equation with to display inline mathematics, and to display equations in a separate block. When executed, MathJax will render Latex equations with high-quality typography.

Raw NBConvert cell


Raw cells provide the ability to write the output directly and are not evaluated by the notebook.

Heading cells


Cells may be formatted as a heading cell, from level 1 (top level) to level 6 (paragraph). These are useful for the conceptual structure of your document or to construct a table of contents.

Simple exercises with IPython Notebook


Let's get started by creating a new notebook and populating it with some content. We will insert the various types of objects to demonstrate the various tasks.

Creating a notebook with heading and Markdown cells


We will begin by creating a new notebook by performing the following steps:

  1. Click on New Notebook from the dashboard to create a new notebook. If from within an active notebook, navigate to the File | New menu option.
  2. In the input field of the first cell, enter a page title for this notebook. In this example, type in .
  3. From the options toolbar menu, go to Cells | Cell Type and select Heading 1. This will format the text we have entered as the page title. The changes, however, will not be immediate at this time.
  4. From the options toolbar menu, go to Insert | Insert Cell Below. This will create another input cell below our current cell.
  5. In this example, we will insert the following piece of text that contains the Markdown code:
    Text Examples === This is an example of an *italic* text. This is an example of a **bold*** text. This is an example of a list item: - Item #1 - Item #2 - Item #3 --- #heading 1 ##heading 2 ###heading 3 ####heading 4 #####heading 5 ######heading 6
  6. From the toolbar, select Markdown instead of Code.
  7. To run your code, go to Cell | Run All. This option will run all the Python commands and format your cells as required.

    Tip


    When the current cell is executed successfully, the notebook will focus on the next cell below, ready for your next input. If no cell is available, one will be automatically created and will receive the input focus.

This will give us the following output:

Saving notebooks


Go to File and click on Save and Checkpoint. Our notebook will be saved...



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.