Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build prortfolios

Related tags

Miscellaneousikaros
Overview

Ikaros

Ikaros is a free financial library built in pure python that can be used to get information for single stocks, generate signals and build portfolios

How to use

Stock

The Stock object is a representation of all information what is available for a given security. For example for AAPL we scrape information from -

  1. https://finviz.com/quote.ashx?t=AAPL
  2. https://www.zacks.com/stock/research/AAPL/earnings-announcements

We also use the Yahoo Finance Library: yahooquery (GitHub link - https://github.com/dpguthrie/yahooquery ) to get fundamental data and price data.

>>>> from Stock import Stock
>>>> aapl = Stock('AAPL')
>>>> aapl.financial_data
             AccountsPayable  ...  WorkingCapital
ReleaseDate                   ...                
2020-01-28      4.511100e+10  ...    6.107000e+10
2020-04-30      3.242100e+10  ...    4.765900e+10
2020-07-30      3.532500e+10  ...    4.474700e+10
2020-10-29      4.229600e+10  ...    3.832100e+10
2021-01-27      6.384600e+10  ...    2.159900e+10

[5 rows x 129 columns]

>>>> aapl['PriceClose']
date
2018-02-15     41.725037
2018-02-16     41.589962
2018-02-20     41.450069
2018-02-21     41.261936
2018-02-22     41.606850
   
2021-02-08    136.910004
2021-02-09    136.009995
2021-02-10    135.389999
2021-02-11    135.130005
2021-02-12    135.369995
Name: PriceClose, Length: 754, dtype: float6

Mix and match market data with fundamental data directly. Ikaros uses the earnings calendar from Zacks to get an accurate Point in time, timeseries from fundamental data.

>>>> aapl['PriceClose'] / aapl['TotalRevenue']
date
2018-02-15             NaN
2018-02-16             NaN
2018-02-20             NaN
2018-02-21             NaN
2018-02-22             NaN
    
2021-02-08    1.228565e-09
2021-02-09    1.220488e-09
2021-02-10    1.214925e-09
2021-02-11    1.212592e-09
2021-02-12    1.214745e-09
Length: 754, dtype: float64

Ikaros also caches the data webscraped into readable csv files. If you want to save the data in a custom location, ensure that the enviornment variable IKAROSDATA is set on your operating system.

Signal

The Signal Library is repository of functions that provide useful insights into stocks. We have a limited number of signals so far but stay tuned! for more

>>>> from Signals import Quick_Ratio_Signal
>>>> ford = Stock('F')
>>>> Quick_Ratio_Signal(ford)
date
2018-02-15         NaN
2018-02-16         NaN
2018-02-20         NaN
2018-02-21         NaN
2018-02-22         NaN
  
2021-02-08    1.089966
2021-02-09    1.089966
2021-02-10    1.089966
2021-02-11    1.089966
2021-02-12    1.089966
Length: 754, dtype: float64

>>>> from SignalTransformers import Z_Score
>>>> Z_Score(Quick_Ratio_Signal(ford), window = 21) # Computes the rolling 21 day Z-score
date
2018-02-15         NaN
2018-02-16         NaN
2018-02-20         NaN
2018-02-21         NaN
2018-02-22         NaN
  
2021-02-08    4.248529
2021-02-09    2.924038
2021-02-10    2.320201
2021-02-11    1.949359
2021-02-12    1.688194
Length: 754, dtype: float64

Portfolio

Finally, use the signals and stock objects to construct Portfolios yourself. Currently we have

  1. Pair Trading Portfolio for 2 Stocks and a Signal
  2. Single Signal Portfolio for multiple Sotcks given a Signal
  3. A basic implementation of the Black Litterman Model

For a PairTradingPortfolio, lets look at GM and Ford and compare the two based on the Quick Ratio

>>>> from Stock import Stock
>>>> from Signals import Quick_Ratio_Signal
>>>> from Portfolio import PairTradingPortfolio
>>>> ford = Stock('F')
>>>> gm = Stock('GM')
>>>> ptp = PairTradingPortfolio(stock_obj1=ford, stock_obj2=gm, signal_func=Quick_Ratio_Signal)
>>>> ptp.relative_differencing() # The weights are set based on the rolling z-score of the difference of the signals for the 2 stocks
>>>> ptp.get_returns()
date
2018-02-15         NaN
2018-02-16         NaN
2018-02-20         NaN
2018-02-21         NaN
2018-02-22         NaN
  
2021-02-08   -0.033217
2021-02-09    0.037791
2021-02-10    0.005568
2021-02-11   -0.001001
2021-02-12   -0.001700
Length: 754, dtype: float64
>>>> ptp.stock_obj1_wght_ts # Get the weight of Stock 1 ( Weight of stock 2 is just -1 times weight of stock 1)
Out[9]: 
date
2018-02-15         NaN
2018-02-16         NaN
2018-02-20         NaN
2018-02-21         NaN
2018-02-22         NaN
  
2021-02-08    0.814045
2021-02-09    0.818967
2021-02-10    0.823901
2021-02-11    0.909396
2021-02-12    0.910393
Length: 754, dtype: float64

For a SingleSignalPortfolio, lets look at FaceBook, Microsfot and Apple and compare them based on the Price to Sales Ratio.

>>>> from Stock import Stock
>>>> from Signals import Price_to_Sales_Signal
>>>> from Portfolio import SingleSignalPortfolio
>>>> from SignalTransformers import Z_Score
>>>> fb = Stock('FB')
>>>> msft = Stock('MSFT')
>>>> aapl = Stock('AAPL')
>>>> signal_func = lambda stock_obj : Z_Score(Price_to_Sales_Signal(stock_obj), window=42) # Use a rolling Z score over 42 days rather than the raw ratio
>>>> ssp.relative_ranking() # Rank the stock from -1 to +1, in this case we have 3 stocks it will be {-1, 0, 1}, if we have 4 sotck it would be {-1, -0.33, 0.33, 1}
>>>> ssp.weight_df
             FB  MSFT  AAPL
date                       
2018-02-15  0.0   0.0   0.0
2018-02-16  0.0   0.0   0.0
2018-02-20  0.0   0.0   0.0
2018-02-21  0.0   0.0   0.0
2018-02-22  0.0   0.0   0.0
        ...   ...   ...
2021-02-08  0.0   1.0  -1.0
2021-02-09  0.0   1.0  -1.0
2021-02-10  0.0   1.0  -1.0
2021-02-11  0.0   1.0  -1.0
2021-02-12  0.0   1.0  -1.0

[754 rows x 3 columns]
>>>> ssp.get_returns() # Initial values are 0 since signal is not available at the start for any of the stocks
date
2018-02-15    0.000000
2018-02-16    0.000000
2018-02-20    0.000000
2018-02-21    0.000000
2018-02-22    0.000000
  
2021-02-08    0.000018
2021-02-09    0.011935
2021-02-10    0.000661
2021-02-11    0.008798
2021-02-12    0.000269
Length: 754, dtype: float64

For a SimpleBlackLitterman, we can provide multiple stocks and multiple signals. Let us try to look at Ford, GM and Toyota based on the Price to Sales and Quick Ratio

>>>> from datetime import datetime
>>>> from Stock import Stock
>>>> from Signals import Quick_Ratio_Signal, Price_to_Sales_Signal
>>>> from Portfolio import SimpleBlackLitterman
>>>> from SignalTransformers import Z_Score
>>>> ford = Stock('F')
>>>> gm = Stock('GM')
>>>> toyota = Stock('TM')
>>>> signal_func1 = lambda stock_obj: Quick_Ratio_Signal(stock_obj) # Use the Raw quick Ratio
>>>> signal_func2 = lambda stock_obj: Z_Score(-1*Price_to_Sales_Signal(stock_obj), window=63) # Use the moving 63 Z score for Price to Sales. -1 to Flip the signal
>>>> signal_view_ret_arr = [0.02, 0.01] # Expected returns from each signal. Typically denoted as Q
>>>> sbl = SimpleBlackLitterman(stock_arr=[ford, gm, toyota], signal_func_arr=[signal_func1, signal_func2], signal_view_ret_arr=signal_view_ret_arr)
>>>> dt = datetime(2021, 2, 12).date()
>>>> sbl.weights_df # Weights based on MarketCap
                   F        GM        TM
date                                    
2020-02-07  0.059205  0.085642  0.855153
2020-02-10  0.059145  0.087673  0.853182
2020-02-11  0.059010  0.088974  0.852016
2020-02-12  0.059782  0.089820  0.850399
2020-02-13  0.060360  0.090068  0.849572
             ...       ...       ...
2021-02-08  0.075640  0.127209  0.797151
2021-02-09  0.077582  0.124607  0.797810
2021-02-10  0.073859  0.117810  0.808331
2021-02-11  0.073232  0.116954  0.809814
2021-02-12  0.072642  0.116230  0.811128

[257 rows x 3 columns]
>>>> sbl.var_covar_ts[dt] # Variance Covariance Martix computed based on rolling 126 days of returns, var_covar_ts is a dict of dataframes. Typically denoted as Sigma
           F        GM        TM
F   0.140825  0.085604  0.021408
GM  0.085604  0.197158  0.020909
TM  0.021408  0.020909  0.044832
>>>> sbl.implied_returns_df # Implied Returns for each day. This is often denoted as Pi
                   F        GM        TM
2020-02-10  0.012125  0.016345  0.014762
2020-02-11  0.012131  0.016199  0.014818
2020-02-12  0.011994  0.016279  0.014773
2020-02-13  0.012199  0.016374  0.014645
2020-02-14  0.011042  0.014466  0.013649
             ...       ...       ...
2021-02-08  0.038776  0.047958  0.037335
2021-02-09  0.039060  0.049541  0.037451
2021-02-10  0.038827  0.048351  0.037453
2021-02-11  0.036424  0.045034  0.040050
2021-02-12  0.037661  0.046260  0.040319

[256 rows x 3 columns]
>>>> sbl.link_mat_ts[dt] # The link matrix on a given day. link_mat_ts is a dict of dataframes. Typically denoted as Sigma
            F   GM   TM
signal_0  1.0 -1.0  0.0
signal_1 -1.0  0.0  1.0
>>>> sbl.view_var_covar_ts[dt] # The View variance covariance matrix on a given day. view_var_covar_ts is a dict of dataframes. Typically denoted as Omega
          signal_0  signal_1
signal_0  0.166775 -0.043777
signal_1 -0.043777  0.142840
>>>> sbl.black_litterman_weights_df # The Black litterman weights over time, based on the changing views
                   F        GM        TM
2020-05-07  0.077305  0.127350  0.795345
2020-05-08  0.077354  0.130177  0.792469
2020-05-11  0.077862  0.132684  0.789454
2020-05-12  0.065264  0.071459  0.863277
2020-05-13  0.114959  0.074012  0.811028
             ...       ...       ...
2021-02-08  0.116730  0.123745  0.759526
2021-02-09  0.116043  0.127209  0.756747
2021-02-10  0.149960  0.232889  0.617152
2021-02-11  0.109802 -0.032208  0.922406
2021-02-12  0.107529 -0.033443  0.925915
Owner
Salma Saidane
Salma Saidane
Using graph_nets for pion classification and energy regression. Contributions from LLNL and LBNL

nbdev template Use this template to more easily create your nbdev project. If you are using an older version of this template, and want to upgrade to

3 Nov 23, 2022
Object-data mapper and advanced query manager for non relational databases

Object data mapper and advanced query manager for non relational databases. The data is owned by different, configurable back-end databases and it is

Luca Sbardella 121 Aug 11, 2022
Python Service for MISP Feed Management

Python Service for MISP Feed Management This set of scripts is designed to offer better reliability and more control over the fetching of feeds into M

Chris 7 Aug 24, 2022
Coded in Python 3 - I make for education, easily clone simple website.

Simple Website Cloner - Single Page Coded in Python 3 - I make for education, easily clone simple website. How to use ? Install Python 3 first. Instal

Phạm Đức Thanh 2 Jan 13, 2022
Цифрова збрoя проти xуйлoвської пропаганди.

Паляниця Цифрова зброя проти xуйлoвської пропаганди. Щоб негайно почати шкварити рашистські сайти – мерщій у швидкий старт! ⚡️ А коли ворожі сервери в

8 Mar 22, 2022
Student Management System Built With Python

Student-Management-System Group Members 19BCE183 - Patel Sarthak 19BCE195 - Patel Jinil 19BCE220 - Rana Yash Project Description In our project Studen

Sarthak Patel 6 Oct 20, 2022
A Regex based linter tool that works for any language and works exclusively with custom linting rules.

renag Documentation Available Here Short for Regex (re) Nag (like "one who complains"). Now also PEGs (Parsing Expression Grammars) compatible with py

Ryan Peach 12 Oct 20, 2022
An improved version of the common ˙pacman -S˙

BetterPacmanLook An improved version of the common pacman -S. Installation I know that this is probably one of the worst solutions and i will be worki

1 Nov 06, 2021
A basic layout of atm working of my local database

Software for working Banking service 😄 This project was developed for Banking service. mysql server is required To have mysql server on your system u

satya 1 Oct 21, 2021
BloodCheck enables Red and Blue Teams to manage multiple Neo4j databases and run Cypher queries against a BloodHound dataset.

BloodCheck BloodCheck enables Red and Blue Teams to manage multiple Neo4j databases and run Cypher queries against a BloodHound dataset. Installation

Mr B0b 16 Nov 05, 2021
Parametric Bottle in CADQuery

Parametric Bottle using CADQuery The proposed code makes it possible to generate different types and sizes of 3D bottles in order to train Pixel2mesh

Ayoub EL HOUDRI 1 May 22, 2022
An easy python calculator for those who want's to know how if statements, loops, and imports works give it a try!

A usefull calculator for any student or anyone who want's to know how to build a simple 2 mode python based calculator.

Antonio Sánchez 1 Jan 06, 2022
A simple string parser based on CLR to check whether a string is acceptable or not for a given grammar.

A simple string parser based on CLR to check whether a string is acceptable or not for a given grammar.

Bharath M Kulkarni 1 Dec 15, 2021
Create Arrays (Working with For Loops)

DSA with Python Create Arrays (Working with For Loops) CREATING ARRAYS WITH USER INPUT Array is a collection of items stored at contiguous memory loca

1 Feb 08, 2022
Bootcamp de Introducción a la Programación. Módulo 6: Matemáticas Discretas

Módulo 6: Matemáticas Discretas Última actualización: 12 de marzo Irónicamente, las matemáticas discretas son las matemáticas que lo cuentan todo. Si

Cynthia Castillo 34 Sep 29, 2022
Consulta cpf fds

Consulta-cpf Consulta cpf fds Instalação: apt-get update -y

Moleey 1 Nov 24, 2021
Oregon State University grade distributions from Fall 2018 through Summer 2021

Oregon State University Grades Oregon State University grade distributions from Fall 2018 through Summer 2021 obtained through a Freedom Of Informatio

Melanie Gutzmann 5 May 02, 2022
Click2call for asterisk with python

Click2call para Asterisk com Python Este projeto disponibiliza uma API construíd

Benedito Marques 1 Jan 17, 2022
personal dotfiles for rolling release linux distros

dotfiles Screenshots: Directions: Deploy my dotfiles with yadm Packages from arch listed in .installed-packages Information on osu! see ~/Games/osu!/.

-pacer- 0 Sep 18, 2022
Python Control Systems Library

The Python Control Systems Library is a Python module that implements basic operations for analysis and design of feedback control systems.

Control Systems Library for Python 1.3k Jan 06, 2023