Files
OpenBB/website/content/sdk/data-available/quantitative-analysis.md
James Maslek 747c53512d Release/3.2.4 (#5696)
* test

* ultima description (#5541)

* Updating showcase page (#5543)

* updating showcase page

* use sdk instead

* add new bot command autopost docs (#5530)

add new bot command autopost docs to docs.openbb.co

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Hotfix/ultima improvements (#5553)

* tweaks for monetization

* fix linting issue

* fix: Modify 'load' behavior to append data to existing sheet (#5503)

* fix: Modify 'load' behavior to append data to existing sheet

Details:
- Added logic to detect existing sheet and append data if present.
- There is no direct way to append on the sheet, so I am reading the sheet to get the last row number and then writing after that row number.

Resolves: #5472

* Fixed 'worksheet not found' error during export to an existing sheet

* Changes:
* Now if the sheet exists in the xlsx file it will ask the user if he
  wants to replace/append/create new sheet

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>

* added platform API integration test to Nightly build (#5571)

* Add columns to `stocks/search` (#5565)

* Add columns to `stocks/search`

isin, cusip, figi, composite_figi, shareclass_figi

* Update test_search[False].txt

* Update test_search[True].txt

* Delete tests/openbb_terminal/stocks/cassettes/test_stocks_helper/test_search.yaml

* Create test_search.yaml

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>

* updating ultima urls (#5587)

* fix: A value is trying to be set on a copy of a slice from a DataFrame #5582 (#5591)

* Update README.md (#5598)

* Hotfix/econometrics export filename fix (#5508)

* fix: Modify 'load' behavior to append data to existing sheet

Details:
- Added logic to detect existing sheet and append data if present.
- There is no direct way to append on the sheet, so I am reading the sheet to get the last row number and then writing after that row number.

Resolves: #5472

* Added --export option for exporting to a desired file in /econometrics menu

* Added a -f/--file option to provide the filename for export.
Made -t/--type and -f/--file mutually exclusive.
If -f is not given, -t is required and the filename will be generated based on the time and module.

* Revert `helper_funcs.py` to original state

* Made some arguments not required.

* Minor changes asked by @deeleeramone

* No sheet name

* black

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>

* FIX #5600 Updated the Twitter logo to X logo (#5601)

* Change Ultima paragraph (#5624)

* change ultima paragraph

* remove old paragraph

* Update CONTRIBUTING.md (#5623)

* mobile line-brake fixed (#5604)

In the mobile view (media max 400px ), the text line "Installation >>" appears broken into smaller segments.

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Docs/terminalpro and improvement (#5622)

* add first iteration of content for Terminal Pro

* Update index.md

* Update dashboards.md

* Update folders.md

* Update grouping.md

* Update report.md

* Update templates.md

* Update quick-start.md

* Update index.md

* Update index.md

* Update home.md

* Update news.md

* Update index.md

* Update index.md

* Update index.md

* Update data-provider.md

* Update chat-with-widget.md

* Update data-manipulation.md

* Update forecasting.md

* fix: images self closing tags

* fix: only pro visitors can see pro

* inter font

* improve SEO content and restructuring

* add new package for toggle on tutorials

* move folder around

* improve main page of each prod

* small updates and improvements

* fix logo above

* small improvement in headtitle for portfolio funcs

* fix typos from OpenAI's GPT-4

* fix _category_ json

* remove generic SEO words

* add script that generates SEO for documentation

* add missing file

* remove sdk warning message

* fix links for andrew

---------

Co-authored-by: jose-donato <zmcdonato@gmail.com>
Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com>
Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>

* Add light blue banner, blue when clicking sidebar + fix link in docusaurus.config.js (#5627)

* typo

* pro docs tab coloring

* sidebar selection blue

* redirecting missing

* fix docs (#5646)

* Fix the redirect for intro to the correct url for docs (#5658)

* fix the redirect for intro to the correct url for docs

* fix code linting

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Improve Pro documentation further (#5641)

* small improvement

* Fix TutorialVideo for mobile view

* main page terminal pro docs

* jose whelp

* placeholder index file that needs to be removed

* fix: fixes sidebar, removes unused index.md

* update link to api keys

* update api keys link

* fix hyperlinks in terminal helper

* fix a few more links

* fix some more links

* linter

* black linter

* improve main docs page for each product

* small refactor

* header to take to main page of product

* run OpenAI script to generate SEO for pro content

---------

Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com>

* Update folders.md

* Update integrate-your-own-backend.md

* Update index.md

* Update settings.md (#5665)

* fix front matter (#5667)

* #5633 adding comma every 1000 (#5652)

* #5633 adding comma every 1000

* pylint

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>

* Hotfix/reports model render report sanitize inputs (#5669)

* Adding more robust special character handling to create_output_path().Addresses https://github.com/OpenBB-finance/OpenBBTerminal/issues/5299

* Running black linter on code to conform to OBB style guides.

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>

* hotfix/fix-gov-histcont: Fix #5650 - /stocks/gov/histcont (#5676)

* fix histcont

* some cleanup

* remove sort line

* 12-31 not 12-12

* columns_keep_types

* remove space in regex (#5675)

* Pin openai (#5685)

* Clarified stocks/ta empty recom object message (#5468)

* Clarified stocks/ta empty recom object message

* black

* lint

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* improved market cap value extraction (#5169)

* improved market cap value extraction

* pylint

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* 3.2.3->3.2.4

* Changelogs

* new changelog

---------

Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: Andrew <andrew.kenreich@gmail.com>
Co-authored-by: Adi Sai <adithya.sairam1@gmail.com>
Co-authored-by: Sandip Saha <sandipsmoto@gmail.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Luqman <luqazino@gmail.com>
Co-authored-by: Adwait <111136306+AdwaitSalankar@users.noreply.github.com>
Co-authored-by: Abhishek Amar <66067391+abhishek-amar@users.noreply.github.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: professssor <62937125+professssor@users.noreply.github.com>
Co-authored-by: Farookh Zaheer Siddiqui <129654632+FarukhS52@users.noreply.github.com>
Co-authored-by: MAX SHESTOV <57421753+maxxsh@users.noreply.github.com>
Co-authored-by: jose-donato <zmcdonato@gmail.com>
Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com>
Co-authored-by: Mohamad Fadil <fadil.parves@gmail.com>
Co-authored-by: Ramazan <guvencramazan@outlook.com>
Co-authored-by: joshuabuildsthings <joshuabuildsthings@users.noreply.github.com>
Co-authored-by: wojda <114031148+polooner@users.noreply.github.com>
Co-authored-by: Bim Phomthong <118195204+bimbolimbo@users.noreply.github.com>
2023-11-09 15:48:33 -05:00

8.9 KiB
Vendored
Raw Blame History

title, description, keywords
title description keywords
Quantitative Analysis The page provides a comprehensive guide on how to use the 'qa' module of the Terminal's Quantitative Analysis menu for SDK environment. It contains detailed information about the grouping of functions into categories, examples on their usage, and how they provide users more ways to interact with the function library.
Quantitative Analysis
SDK Environment
Library of Functions
Code Completion
Statistics
Risk Management
API Integration
Data Relation
Nasdaq Data Link API
Risk-Adjusted Return
openbb.qa

import HeadTitle from '@site/src/components/General/HeadTitle.tsx';

The qa module is the Terminal's Quantitative Analysis menu for the SDK environment. It provides users with more ways to interact with the library of functions, and provides cross-disciplinary utility. To activate the code completion for the menu, enter . after, openbb.qa.

How to Use

The functions of the qa module are grouped into categories, listed below along with a short description.

Path Type Description
openbb.qa.acf Plot Plots Auto and Partial Correlation of Returns and Change in Returns
openbb.qa.bw Plot Box and Whisker Plot
openbb.qa.calculate_adjusted_var Risk Calculates VaR, adjusted for skew and kurtosis (Cornish-Fisher-Expansion)
openbb.qa.cdf Plot Plots the Cumulative Distribution Function
openbb.qa.cusum Plot Plots the Cumulative Sum Algorithm
openbb.qa.decompose Plot Decomposition in Cyclic-Trend, Season & Residuals of Prices
openbb.qa.es Statistics Expected Shortfall per percentile
openbb.qa.kurtosis Rolling Metrics Rolling Kurtosis of Distribution of Prices
openbb.qa.line Plot Customizable Line Plot, With Annotations
openbb.qa.normality Statistics Normality Statistics and Tests
openbb.qa.omega Risk Omega Ratio (Risk/Return Performance Measure)
openbb.qa.quantile Rolling Metrics Rolling Median and Quantile of Prices
openbb.qa.qqplot Plot QQ Plot for Data Against Normal Quantiles
openbb.qa.rolling Rolling Metrics Rolling Mean and Standard Deviation of Prices
openbb.qa.sharpe Risk Sharpe Ratio (Measure of Risk-Adjusted Return)
openbb.qa.skew Rolling Metrics Rolling Skewness of Distribution of Prices
openbb.qa.sortino Risk Sortino Ratio Risk Adjustment Metric
openbb.qa.spread Rolling Metrics Rolling Variance and Standard Deviation of Prices
openbb.qa.summary Statistics A Brief Summary of Statistics for the DataFrame
openbb.qa.unitroot Statistics Normality Statistics and Tests
openbb.qa.var Risk Value at Risk

Examples

Import Statements

The examples below will assume that the following statements are included in the first block of code:

import quandl
import pandas as pd
from openbb_terminal.sdk import openbb
from openbb_terminal import config_terminal as cfg

# %matplotlib inline (uncomment if using a Jupyter environment)

Get Data

This example collects data from Nasdaq Data Link, and requires registering for a free API key. Qunadl is the Python client for the Nasdaq Data Link API.

shiller_pe_rdiff = quandl.get('MULTPL/SHILLER_PE_RATIO_MONTH', collapse = 'monthly', transform = 'rdiff', api_key = cfg.API_KEY_QUANDL)
shiller_pe_rdiff.rename(columns={'Value':'P/E % Change'}, inplace = True)
shiller_pe_ratio = quandl.get('MULTPL/SHILLER_PE_RATIO_MONTH', collapse = 'monthly', api_key = cfg.API_KEY_QUANDL)
shiller_pe_ratio.rename(columns={'Value':'P/E Ratio'}, inplace = True)

sp500_inf_adj = quandl.get('MULTPL/SP500_INFLADJ_MONTH', collapse = 'monthly', api_key = cfg.API_KEY_QUANDL)
sp500_inf_adj.rename(columns = {'Value': 'S&P Inflation-Adjusted Value'}, inplace = True)
sp500_inf_adj_rdiff = quandl.get('MULTPL/SP500_INFLADJ_MONTH', collapse = 'monthly', transform = 'rdiff', api_key = cfg.API_KEY_QUANDL)
sp500_inf_adj_rdiff.rename(columns = {'Value':'S&P 500 % Change'}, inplace = True)

shiller_pe = shiller_pe_ratio.join(shiller_pe_rdiff)
sp500_inf_adj = sp500_inf_adj.join(sp500_inf_adj_rdiff)

sp500_df = sp500_inf_adj.join(shiller_pe)

sp500_df
Date S&P Inflation-Adjusted Value S&P 500 % Change P/E Ratio P/E % Change
2022-08-31 00:00:00 3955 0.0092504 29.64 0.022069
2022-09-30 00:00:00 3585.62 -0.0933957 26.84 -0.0944669
2022-10-31 00:00:00 3871.98 0.0798635 28.53 0.0629657
2022-11-30 00:00:00 3856.1 -0.00410126 28.37 -0.00560813

This particular data series contains 150 years of monthly values. It is among the longest uninterrupted timeseries available in the public domain, and it is cited frequently in macroeconomic research.

Summary

Get a summary of statistics for each column with qa.summary:

openbb.qa.summary(sp500_df)
S&P Inflation-Adjusted Value S&P 500 % Change P/E Ratio P/E % Change
count 1823 1822 1822 1821
mean 697.396 0.0028703 16.9914 0.00137084
std 834.501 0.0424378 7.07094 0.0412196
min 80.31 -0.264738 4.78 -0.268992
10% 152.404 -0.0447494 9.31 -0.0449735
25% 203.47 -0.0172803 11.7 -0.0183028
50% 309.83 0.00553122 15.895 0.00446999
75% 778.42 0.0260009 20.5575 0.0246575
90% 1907.87 0.04505 26.467 0.0426357
max 4786.79 0.514085 44.19 0.511986
var 696392 0.00180097 49.9982 0.00169906

Spread

Add the variance and standard deviation, over a specified window (three-months), to the DataFrame:

std,variance = openbb.qa.spread(data = sp500_df['S&P 500 % Change'], window = 3)
std.rename(columns = {'STDEV_3':'Three-Month Standard Deviation'}, inplace = True)
variance.rename(columns = {'VAR_3': 'Three-Month Variance'}, inplace =True)
sp500_df = sp500_df.join([std,variance])
sp500_df.rename_axis('date', inplace = True)
sp500_df.tail(2)
date S&P Inflation-Adjusted Value S&P 500 % Change P/E Ratio P/E % Change Three-Month Standard Deviation Three-Month Variance
2022-10-31 00:00:00 3871.98 0.0798635 28.53 0.0629657 0.0871217 0.00759019
2022-11-30 00:00:00 3856.1 -0.00410126 28.37 -0.00560813 0.0866432 0.00750705

The rolling mean average and standard deviation is calculated with the rolling command. Adding, _chart, to this will return an inline chart within a Jupyter Notebook. For the example below, window, 60, represents a five-year period.

Rolling

openbb.qa.rolling_chart(sp500_df, target = 'P/E Ratio', window = 60, symbol = '')

openbb.qa.rolling_chart

Unit Root Test

Perform a unit root test with unitroot:

help(openbb.qa.unitroot)

        Parameters
        ----------
        data : pd.DataFrame
            DataFrame of target variable
        fuller_reg : str
            Type of regression of ADF test. Can be ‘c’,’ct’,’ctt’,’nc’ 'c' - Constant and t - trend order
        kpss_reg : str
            Type of regression for KPSS test.  Can be ‘c’,’ct'

        Returns
        -------
        pd.DataFrame
            Dataframe with results of ADF test and KPSS test

openbb.qa.unitroot(sp500_df['P/E % Change'])
ADF KPSS
Test Statistic -10.7075 0.34061374135067696
P-Value 3.3972e-19 0.1
NLags 20 2
Nobs 1800
ICBest -6491.14