StocksMA is a package to facilitate access to financial and economic data of Moroccan stocks.

Overview

StocksMA

Creating easier access to the Moroccan stock market data

Language PyPI Star Badge GitHub license Check Code

What is StocksMA ?

StocksMA is a package to facilitate access to financial and economic data of Moroccan stocks. It tries to cover potentially valuable and interesting data points.

The package include functions to extract price data from Leboursier, financial ratios(income statement, balance sheet, cash flow) from MarketWatch, and profile data from WSJ

Note: Sometimes, some functions may fail to get the data from some sources due to WAF protection.

Installation

Python3 is required.

$ pip install StocksMA

Usage

Import the package

>> import StocksMA as stm

Get all availabale tickers

Show available tickers with the full name of the company Example:

stm.get_tickers()
ADH / Douja Promotion Groupe Addoha
ADI / Alliances Developpement Immobilier S.A.
AFI / Afric Industries S.A.
AFM / AFMA S.A.
.
.
.
WAA / Wafa Assurance S.A.
ZDJ / Zellidja S.A.

Get price data

Get historical OHLCV data for a given symbol(s)

Args:

  • tickers Union[str, List[str]] : List or str of companies names or ticker symbols(e.g. ['maroc telecom', 'MNG'] or 'CIH')
  • start_date str: (YYYY-MM-DD) Starting date to pull data from, limited to a maximum of six year
  • end_date str: (YYYY-MM-DD) Ending date. Defaults to the current local date

Returns:

  • pd.DataFrame: Dataframe of historical OHLCV data

Example:

# Get price data of multiple companies
stm.get_price_data(['CIH','maroc telecom', 'involys'], start_date='2020-11-14', end_date='2022-02-14')
Close High Low Open Volume
Company Date
CIH P 2020-11-16 248.15 248.15 248.00 248.00 8
2020-11-17 250.00 250.00 248.00 248.10 220
2020-11-19 245.20 248.00 245.10 248.00 133
... ... ... ... ... ...
INVOLYS P 2022-02-08 131.95 131.95 131.95 131.95 5
2022-02-09 131.95 131.95 131.90 131.95 100
2022-02-11 131.90 131.90 131.00 131.00 4

[840 rows x 5 columns]

# Get price data of single company
stm.get_price_data('involys', start_date='2020-11-14', end_date='2022-02-14')
Open High Low Close Volume
Company Date
INVOLYS P 2020-11-16 119.50 121.00 119.50 121.00 11
2020-11-17 118.60 121.00 118.60 121.00 22
2020-11-19 121.00 121.00 121.00 121.00 1
... ... ... ... ... ...
2022-02-09 131.95 131.95 131.90 131.95 100
2022-02-11 131.00 131.90 131.00 131.90 4

[253 rows x 5 columns]


Get session information

Get data related to the current trading session of a given symbol

Args:

  • company str: Company name or ticker symbol(e.g. 'maroc telecom', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of session data

Example:

stm.get_session_info('involys')
Name Name_2 ISIN Number of Shares Close Previous Close Market Cap Quotation Datetime Change Volume Change Volume in Shares Volume Open Low High
1 INVOLYS P INVOLYS MA0000011579 382716 109.950 109.95 42079624.20 18/03/2022 à 15:16 0.00 0.00 5387 49 109.400 109.400 109.950

Get intraday price data

Get intraday price data of a given symbol

Args:

  • company str: Company name or ticker symbol(e.g. 'maroc telecom', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of intraday price data

Example:

stm.get_data_intraday('CIH')
prices
Datetime
2022-03-18 09:30:00 130.20
2022-03-18 10:02:00 131.00
2022-03-18 10:06:00 131.00
2022-03-18 10:07:00 131.00
2022-03-18 10:17:00 131.15
2022-03-18 10:24:00 131.15
2022-03-18 10:30:00 131.15
2022-03-18 10:41:00 131.40
2022-03-18 11:07:00 131.40
2022-03-18 11:15:00 131.40
2022-03-18 12:24:00 131.45
2022-03-18 12:31:00 131.40
2022-03-18 13:25:00 131.20
2022-03-18 14:48:00 131.25
2022-03-18 15:07:00 131.40
2022-03-18 15:19:00 131.25
2022-03-18 15:30:00 131.40

Get Ask Bid data

Get ask bid data of a given symbol

Args:

  • company str: Company name or ticker symbol(e.g. 'maroc telecom', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of ask bid data

Example:

stm.get_ask_bid('CIH')
bidValue bidQte askValue askQte bidOrder askOrder
0 340.1 3 350.0 248 1 2
1 340.0 950 352.0 702 2 1
2 337.1 4 354.5 10 1 1
3 336.2 10 354.9 3 1 1
4 335.0 10 355.0 290 1 2
5 334.0 4 356.0 200 1 2
6 332.0 6 357.9 2 2 1
7 330.5 10 358.0 482 1 2
8 330.0 274 359.0 59 3 1
9 321.5 300 359.4 20 1 1

Get balance sheet

Get balance sheet data of a given symbol

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')
  • frequency str: Display either quarter or annual data. Defaults to "annual".

Returns:

  • pd.DataFrame: Dataframe of balance sheet data

Example:

# Annual balance sheet
stm.get_balance_sheet('ATW', frequency='annual')
2017 2018 2019 2020 2021
Item
Assets Total Cash & Due from Banks 18.22B 18.54B 24.73B 26.33B 25.74B
Cash & Due from Banks Growth - 1.71% 33.42% 6.48% -2.26%
Investments - Total 116.38B 119.86B 123.75B 137.55B 158.73B
Investments Growth - 2.99% 3.25% 11.15% 15.40%
Trading Account Securities - - 54.32B 58.67B 69.91B
... ... ... ... ... ...
Liabilities & Shareholders' Equity Total Shareholders' Equity / Assets 8.40% 8.73% 8.94% 8.41% 8.80%
Return On Average Total Equity - - - - 10.26%
Accumulated Minority Interest 6.44B 5.95B 6.3B 6.49B 7.34B
Total Equity 46.06B 50.47B 53.93B 54.29B 59.79B
Liabilities & Shareholders' Equity 471.47B 509.93B 532.6B 568.11B 596.33B

[74 rows x 5 columns]

# Quarter balance sheet
stm.get_balance_sheet('ATW', frequency='quarter')
30-Jun-2021 30-Sep-2021 31-Dec-2020 31-Dec-2021 31-Mar-2021
Item
Assets Total Cash & Due from Banks 23.41B 20.2B 26.33B 25.74B 22.79B
Cash & Due from Banks Growth 2.74% -13.73% - 27.43% -13.47%
Investments - Total 148.98B 155.57B 137.55B 158.73B 141.76B
Investments Growth 5.10% 4.42% - 2.04% 3.06%
Trading Account Securities 63.98B 64.94B 58.67B 69.91B 61.8B
... ... ... ... ... ...
Liabilities & Shareholders' Equity Total Shareholders' Equity / Assets 8.47% 8.73% 8.41% 8.80% 8.48%
Return On Average Total Equity - - - 10.26% -
Accumulated Minority Interest 6.88B 7.13B 6.49B 7.34B 6.69B
Total Equity 56B 58.29B 54.29B 59.79B 54.45B
Liabilities & Shareholders' Equity 579.79B 586.09B 568.11B 596.33B 562.95B

[74 rows x 5 columns]


Get income statement

Get income statement data of a given symbol

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')
  • frequency str: Display either quarter or annual data. Defaults to "annual".

Returns:

  • pd.DataFrame: Dataframe of income statement data

Example:

# Annual income statement
stm.get_income_statement('IAM', frequency='annual')
Item 2017 2018 2019 2020 2021
Sales/Revenue 34.96B 36.03B 36.52B 36.77B 35.79B
Sales Growth - 3.06% 1.35% 0.69% -2.66%
Cost of Goods Sold (COGS) incl. D&A 15.69B 15.72B 16.19B 15.93B 15.05B
COGS Growth - 0.24% 2.95% -1.57% -5.56%
COGS excluding D&A 9.08B 8.9B 8.77B 8.42B 7.99B
Non Operating Income/Expense (57M) 201M (49M) (1.49B) (165M)
... ... ... ... ... ...
Equity in Affiliates (Pretax) - - - - -
Interest Expense 586M 642M 756M 888M 826M
Interest Expense Growth - 9.56% 17.76% 17.46% -6.98%
EBITDA 17.03B 17.87B 15.65B 19.53B 18.63B
EBITDA Growth - 4.93% -12.44% 24.80% -4.62%
EBITDA Margin - - - - 52.05%
# Quarter income statement
stm.get_income_statement('IAM', frequency='quarter')
Item 31-Dec-2019 30-Jun-2020 31-Dec-2020 30-Jun-2021 31-Dec-2021
Sales/Revenue 18.67B 18.32B 18.45B 17.78B 18.01B
Sales Growth - -1.87% 0.67% -3.61% 1.29%
Cost of Goods Sold (COGS) incl. D&A 11.53B 4.92B 7.74B 7.9B 7.57B
COGS Growth - -57.33% 57.23% 2.02% -4.08%
COGS excluding D&A 4.42B 4.16B 4.26B 4.09B 3.91B
Depreciation & Amortization Expense 7.12B 759M 3.48B 3.81B 3.67B
... ... ... ... ... ...
EBITDA 9.49B 6.6B 9.66B 9.37B 9.68B
EBITDA Growth - -30.48% 46.52% -3.07% 3.38%
EBITDA Margin - - - - 53.76%

Get cash flow

Get cash flow data of a given symbol

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')
  • frequency str: Display either quarter or annual data. Defaults to "annual".

Returns:

  • pd.DataFrame: Dataframe of cash flow data

Example:

# Annual cash flow
stm.get_cash_flow('IAM', frequency='annual')
2017 2018 2019 2020 2021
Item
Operating Activities Net Income before Extraordinaries 10.31B 11.05B 8.23B 12.02B 11.57B
Net Income Growth - 7.20% -25.52% 46.01% -3.70%
Depreciation, Depletion & Amortization 6.61B 6.82B 7.42B 7.51B 7.06B
... ... ... ... ... ...
Net Operating Cash Flow 14.13B 13.95B 14.81B 10.48B 12.87B
Net Operating Cash Flow Growth - -1.32% 6.22% -29.28% 22.80%
Net Operating Cash Flow / Sales 40.42% 38.71% 40.57% 28.49% 35.95%
Investing Activities Capital Expenditures (8.37B) (8.08B) (7.95B) (4.14B) (5.29B)
Capital Expenditures Growth - 3.52% 1.56% 47.91% -27.75%
Capital Expenditures / Sales -23.94% -22.41% -21.77% -11.26% -14.78%
... ... ... ... ... ...
Net Investing Cash Flow (8.07B) (8.37B) (8.83B) (4.23B) (5.31B)
Net Investing Cash Flow Growth - -3.77% -5.42% 52.03% -25.42%
Net Investing Cash Flow / Sales -23.07% -23.23% -24.17% -11.51% -14.83%
Financing Activities Cash Dividends Paid - Total (5.6B) (5.73B) (6B) (4.87B) (3.53B)
Common Dividends (5.6B) (5.73B) (6B) (4.87B) (3.53B)
Preferred Dividends - - - - -
... ... ... ... ... ...
Free Cash Flow 5.76B 5.87B 6.87B 6.34B 7.58B
Free Cash Flow Growth - 1.89% 16.91% -7.72% 19.57%
Free Cash Flow Yield - - - - 3.30
# Quarter cash flow
stm.get_cash_flow('IAM', frequency='quarter')
31-Dec-2019 30-Jun-2020 31-Dec-2020 30-Jun-2021 31-Dec-2021
Item
Operating Activities Net Income before Extraordinaries 2.37B 5.84B 6.18B 5.56B 6.02B
Net Income Growth - 146.35% 5.93% -10.11% 8.26%
Depreciation, Depletion & Amortization 3.81B (759M) 8.27B 3.81B 3.25B
... ... ... ... ... ...
Net Operating Cash Flow 8.95B 1.86B 8.62B 5.81B 7.05B
Net Operating Cash Flow Growth - -79.27% 364.44% -32.56% 21.31%
Net Operating Cash Flow / Sales 47.94% 10.13% 46.73% 32.69% 39.16%
Investing Activities Capital Expenditures (3.73B) (2.29B) (1.85B) (2.74B) (2.55B)
Capital Expenditures Growth - 38.69% 18.93% -47.57% 6.65%
Capital Expenditures / Sales -19.98% -12.48% -10.05% -15.39% -14.18%
... ... ... ... ... ...
Net Investing Cash Flow (3.56B) (2.4B) (1.84B) (2.76B) (2.55B)
Net Investing Cash Flow Growth - 32.71% 23.40% -50.11% 7.37%
Net Investing Cash Flow / Sales -19.08% -13.08% -9.95% -15.50% -14.18%
Financing Activities Cash Dividends Paid - Total (271M) - (4.87B) - (3.53B)
Common Dividends (271M) - (4.87B) - (3.53B)
Preferred Dividends - - - - -
... ... ... ... ... ...
Free Cash Flow 5.22B (431M) 6.77B 3.08B 4.5B
Free Cash Flow Growth - -108.25% 1,669.84% -54.52% 46.18%
Free Cash Flow Yield - - - - 3.30

Get quote table

Get important data about a given symbol

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of data about the ticker

Example:

stm.get_quote_table('ATW')
Key Data Value
0 Open 473.00
1 Day Range 464.00 - 473.00
2 52 Week Range N/A
3 Market Cap 93.69B
4 Shares Outstanding 215.14M
5 Public Float 69.09M
6 Beta N/A
7 Rev. per Employee 1.933M
8 P/E Ratio 18.04
9 EPS 25.72
10 Yield 3.23%
11 Dividend 6.75
12 Ex-Dividend Date Jul 5, 2021
13 Short Interest N/A
14 % of Float Shorted N/A
15 Average Volume 160.21K

Get market status

Get status of the Moroccan market Returns:

  • str: Status of the market(Open/Closed)

Example:

stm.get_market_status()
Closed

Get company officers

Get company officers of a given symbol

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of names and roles of the officers

Example:

stm.get_company_officers('MNG')
Name Role
0 Imad Toumi Chairman & Chief Executive Officer
1 Mouna Mahfoud Executive Director-Finance
2 Naoual Zine General Manager-Reminex & Projects
3 Lhou Maacha Executive Director-Exploration
4 Youssef el Hajjam General Manager-Bases Metal Operations
5 Karim Khettouch Director
6 Samir Oudghiri Idrissi Director
7 Bassim Jaï Hokimi Director
8 Hassan Ouriagli Director
9 Amina Benkhadra Director
10 Noufissa Kessar Director
11 Mohamed Amine Afsahi Executive Director-Marketing & Commercial
12 Laila Karam Investor Relations Contact
13 Zakaria Rbii Executive Director-HR, Communication & Develop...
14 Frédéric Bernard Tona Independent Director

Get company information

Get information related to the company's location, adresse...

Args:

  • company str: Ticker symbol(e.g. 'IAM', 'MNG')

Returns:

  • pd.DataFrame: Dataframe of information related to the company (e.g. Name, Adresse, Phone...)

Example:

stm.get_company_info('MNG')
Item Value
0 Name Managem
1 Adresse Twin Center, Tower A Angle Boulevards Zerktoun...
2 Phone +212 522 956-565
3 Industry General Mining
4 Sector Basic Materials/Resources
5 Description Managem SA engages in mining and hydrometallur...

License

This project is licensed under the terms of the MIT license.

Owner
Salah Eddine LABIAD
Data Science student and Cybersecurity enthusiast.
Salah Eddine LABIAD
Pywonderland - A tour in the wonderland of math with python.

A Tour in the Wonderland of Math with Python A collection of python scripts for drawing beautiful figures and animating interesting algorithms in math

Zhao Liang 4.1k Jan 03, 2023
code for "AttentiveNAS Improving Neural Architecture Search via Attentive Sampling"

code for "AttentiveNAS Improving Neural Architecture Search via Attentive Sampling"

Facebook Research 94 Oct 26, 2022
PyTorch code for the paper "FIERY: Future Instance Segmentation in Bird's-Eye view from Surround Monocular Cameras"

FIERY This is the PyTorch implementation for inference and training of the future prediction bird's-eye view network as described in: FIERY: Future In

Wayve 406 Dec 24, 2022
robomimic: A Modular Framework for Robot Learning from Demonstration

robomimic [Homepage]   [Documentation]   [Study Paper]   [Study Website]   [ARISE Initiative] Latest Updates [08/09/2021] v0.1.0: Initial code and pap

ARISE Initiative 178 Jan 05, 2023
A MNIST-like fashion product database. Benchmark

Fashion-MNIST Table of Contents Why we made Fashion-MNIST Get the Data Usage Benchmark Visualization Contributing Contact Citing Fashion-MNIST License

Zalando Research 10.5k Jan 08, 2023
This project provides the code and datasets for 'CapSal: Leveraging Captioning to Boost Semantics for Salient Object Detection', CVPR 2019.

Code-and-Dataset-for-CapSal This project provides the code and datasets for 'CapSal: Leveraging Captioning to Boost Semantics for Salient Object Detec

lu zhang 48 Aug 19, 2022
✨✨✨An awesome open source toolbox for stereo matching.

OpenStereo This is an awesome open source toolbox for stereo matching. Supported Methods: BM SGM(T-PAMI'07) GCNet(ICCV'17) PSMNet(CVPR'18) StereoNet(E

Wang Qingyu 6 Nov 04, 2022
Face Transformer for Recognition

Face-Transformer This is the code of Face Transformer for Recognition (https://arxiv.org/abs/2103.14803v2). Recently there has been great interests of

Zhong Yaoyao 153 Nov 30, 2022
Official PyTorch implementation of Retrieve in Style: Unsupervised Facial Feature Transfer and Retrieval.

Retrieve in Style: Unsupervised Facial Feature Transfer and Retrieval PyTorch This is the PyTorch implementation of Retrieve in Style: Unsupervised Fa

60 Oct 12, 2022
[ICCV 2021] HRegNet: A Hierarchical Network for Large-scale Outdoor LiDAR Point Cloud Registration

HRegNet: A Hierarchical Network for Large-scale Outdoor LiDAR Point Cloud Registration Introduction The repository contains the source code and pre-tr

Intelligent Sensing, Perception and Computing Group 55 Dec 14, 2022
Using pretrained language models for biomedical knowledge graph completion.

LMs for biomedical KG completion This repository contains code to run the experiments described in: Scientific Language Models for Biomedical Knowledg

Rahul Nadkarni 41 Nov 30, 2022
[CVPR 2021] Exemplar-Based Open-Set Panoptic Segmentation Network (EOPSN)

EOPSN: Exemplar-Based Open-Set Panoptic Segmentation Network (CVPR 2021) PyTorch implementation for EOPSN. We propose open-set panoptic segmentation t

Jaedong Hwang 49 Dec 30, 2022
OpenMMLab Video Perception Toolbox. It supports Video Object Detection (VID), Multiple Object Tracking (MOT), Single Object Tracking (SOT), Video Instance Segmentation (VIS) with a unified framework.

English | 简体中文 Documentation: https://mmtracking.readthedocs.io/ Introduction MMTracking is an open source video perception toolbox based on PyTorch.

OpenMMLab 2.7k Jan 08, 2023
😊 Python module for face feature changing

PyWarping Python module for face feature changing Installation pip install pywarping If you get an error: No such file or directory: 'cmake': 'cmake',

Dopevog 10 Sep 10, 2021
[Official] Exploring Temporal Coherence for More General Video Face Forgery Detection(ICCV 2021)

Exploring Temporal Coherence for More General Video Face Forgery Detection(FTCN) Yinglin Zheng, Jianmin Bao, Dong Chen, Ming Zeng, Fang Wen Accepted b

57 Dec 28, 2022
A no-BS, dead-simple training visualizer for tf-keras

A no-BS, dead-simple training visualizer for tf-keras TrainingDashboard Plot inter-epoch and intra-epoch loss and metrics within a jupyter notebook wi

Vibhu Agrawal 3 May 28, 2021
RADIal is available now! Check the download section

Latest news: RADIal is available now! Check the download section. However, because we are currently working on the data anonymization, we provide for

valeo.ai 55 Jan 03, 2023
使用yolov5训练自己数据集(详细过程)并通过flask部署

使用yolov5训练自己的数据集(详细过程)并通过flask部署 依赖库 torch torchvision numpy opencv-python lxml tqdm flask pillow tensorboard matplotlib pycocotools Windows,请使用 pycoc

HB.com 19 Dec 28, 2022
Collection of generative models, e.g. GAN, VAE in Pytorch and Tensorflow.

Generative Models Collection of generative models, e.g. GAN, VAE in Pytorch and Tensorflow. Also present here are RBM and Helmholtz Machine. Note: Gen

Agustinus Kristiadi 7k Jan 02, 2023
This is an official implementation for "SimMIM: A Simple Framework for Masked Image Modeling".

Project This repo has been populated by an initial template to help get you started. Please make sure to update the content to build a great experienc

Microsoft 674 Dec 26, 2022