Introduction
Quantiacs provides a powerful data API that grants access to historical stock market data, enabling traders and researchers to develop, test, and deploy trading algorithms. This guide will cover the structure of Quantiacs stock data, how to retrieve it, and how to leverage it for quantitative trading strategies. We will explore the API architecture, provide code examples, and outline best practices for effective use.
Understanding Quantiacs Stock Data
Data Structure
Quantiacs offers extensive stock market data, including:
- Adjusted Close Prices
- Open, High, Low, Close Prices
- Volume Data
- Fundamentals
- Technical Indicators
The data is structured as a Pandas DataFrame, making it convenient for analysis and backtesting.
Architecture Overview
The data architecture follows a streamlined flow:
Quantiacs Data Servers → REST API → Python Client → Pandas DataFrame
The API fetches data from Quantiacs’ servers and provides it in a structured DataFrame format for easy manipulation.
Installation and Setup
Before using the API, ensure you have the quantiacs-toolbox
installed:
pip install quantiacs-toolbox
Then, import the necessary modules in your Python script:
import quantiacsToolbox as qtb
import pandas as pd
Retrieving Stock Data
You can fetch stock data using the loadData
function:
data = qtb.loadData(marketList=['AAPL'], dataSet='daily', startDate='2020-01-01', endDate='2024-01-01')
print(data.keys())
The retrieved dataset contains:
CLOSE
OPEN
HIGH
LOW
VOLUME
Each key maps to a Pandas DataFrame for further analysis.
Example: Fetching Multiple Stocks
stocks = ['AAPL', 'GOOG', 'MSFT']
data = qtb.loadData(marketList=stocks, dataSet='daily', startDate='2020-01-01', endDate='2024-01-01')
Data Analysis with Pandas
Once the data is loaded, you can perform exploratory analysis:
import matplotlib.pyplot as plt
aapl_close = data['CLOSE']['AAPL']
aapl_close.plot(title='AAPL Close Price')
plt.show()
This script will generate a plot of Apple’s closing prices over time.
Building a Simple Trading Strategy
Let’s build a basic moving average crossover strategy using Quantiacs data.
def myTradingSystem(data):
prices = data['CLOSE']
short_ma = prices.rolling(window=20).mean()
long_ma = prices.rolling(window=50).mean()
signal = (short_ma > long_ma).astype(int) - (short_ma < long_ma).astype(int)
return signal
Run a backtest using:
qtb.runts(myTradingSystem)
Conclusion
Quantiacs provides a rich API for stock market data, making it ideal for backtesting and live trading strategies. This guide covered the basics of data retrieval, analysis, and strategy development. As you explore further, you can integrate advanced indicators and machine learning models for more sophisticated trading algorithms.
For more details, visit the Quantiacs Documentation.