Zipline and PyFolio

Zipline and PyFolio abstract away the complexities of the backtesting and performance/risk analysis aspects of algorithmic trading strategies. Backtesting should include all relevant factors, such as slippage and trading costs. Zipline is one of the most advanced open source Python libraries for algorithmic trading backtesting engines. PyFolio is an open-source Python performance and risk analysis…

Financial Market Data Access in Python

Exploring the yahoofinancials Python library The yahoofinancials Python library provides free access to the market data available from Yahoo Finance, whose provider is ICE Data Services. It provides access to historical and, for most assets, also real-time pricing data for the following: Single-ticker retrieval Convert the nested JSON to a pandas’ DataFrame Real-time data retrieval…

Data Manipulation and Analysis with pandas

The name pandas is derived from panel data, an econometrics term for a multidimensional structured dataset. Introducing pandas Series, pandas DataFrames, and pandas Indexes pandas.Series The pandas.Series data structure represents a one-dimensional series of homogeneous values (integer values, string values, double values, and so on). Series are a type of list and can contain only…

High-Speed Scientific Computing Using NumPy

Creating NumPy ndarrays Creating 1D ndarrays Inspect the type of the array Creating 2D ndarrays Creating any-dimension ndarrays Creating an ndarray with np.zeros(…) Creates an ndarray populated with all 0s Creating an ndarray with np.ones(…) Each value is assigned a value of 1 Creating an ndarray with np.identity(…) Creating an ndarray with np.arange(…) Creating an…

Exploratory Data Analysis in Python

The objective of exploratory data analysis (EDA) is to load data into structures most suitable for further analysis to identify and rectify any wrong/bad data and get basic insight into the data — the types of fields there are; whether they are categorical or not; how many missing values there are; how the fields are…

A Basic Python main()

In some python scripts, you may see a function definition and a conditional statement that looks like the example below: In this code, there is a function called main() that prints the phrase “Hello World!” when the Python interpreter executes it. There is also a conditional (or if) statement that checks the value of __name__…

Regular Expressions Based on Syntax Used by Perl

Symbol(s) Meaning Example Example Matches * Matches the preceding character, subexpression, or bracketed character, 0 or more times a*b* aaaaaaaa, aaaaabbbb, bbbbbbb + Matches the preceding character, subexpression, or bracketed character, 1 or more times a+b+ aaaaaab, aaaabbbbb, abbbbbbb [] Matches any character within the brackets (i.e., “Pick any one of these things”) [A-Z]* APPLE,…