Coder Social home page Coder Social logo

joaopm33 / fundspy Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 9.0 474 KB

Download brazillian investment funds and their benchmarks data from CVM and analyze their performance with pre-built functions.

Home Page: https://joaopm33.github.io/fundspy/docs/fundspy.html

License: MIT License

Python 100.00%
investment-funds performance-metrics database target-funds volatility investimentos sharpe-ratio cvm investimento fundos

fundspy's Introduction

fundspy

Version CodeFactor Status License Repo size Stars Issues Last commit

This python based project helps you to extract and analyze data related to brazilian investment funds. It has functions to start and update a SQLite database containing cadastral information and daily quotas of all investment funds in brazil since 2005, as well as the ibovespa index and selic (the base interest rate of the brazilian economy).

There are also functions to help you calculate important performance metrics for the investment funds, such as returns, volatility, correlation with indexes, beta, alpha, sharpe ratio, sortino ratio and capture ratios.

Documentation and Examples

  • You can access the functions documentation here.
  • Theres also a Notebook with use examples of all performance metrics functions here.

Getting Started

You will need python 3.5 (at least) for running this project.

Installing

To install the package, open a terminal and execute the command:

pip install fundspy

Main Functionalities

The main use cases this library covers are starting a investment funds database, updating it and calculating performance metrics with pre built functions.

Building the database

To start the database you will have to execute the "start_db" function. You can do this by creating a file "start_db.py" in your local directory and pasting the following code inside it (or just download it here):

from fundspy.fundspy import cvm_informes, start_db
start_db(db_dir = 'investments_database.db', start_year = 2005, target_funds = [])

and then executing the file from your terminal:

python start_db.py

This will create a ~6Gb SQLite database in your disk named "investments_database.db", so be sure to have enough free space.

You can also change the start_db function parameters. To get a smaller subset of the available data, use the parameters:

  • start_year to set the minimal year used as filter.
  • target_funds to pass a list of target funds CNPJs (unique ids).

This can save you a lot of disk space, but will of course reduce the amount of data you get.

start_db(db_dir = 'investments_database.db', 
         start_year = 2005, 
         target_funds = [])

Updating the database

Once you want to extract new data and update your database, create a file "update_db.py" in your local directory and paste the following code inside it (or just download it here):

from fundspy.fundspy import cvm_informes, update_db
update_db(db_dir = r'investments_database.db')

run the "update_db.py" file from your terminal:

python update_db.py

This function will collect the data available between the last database update and the current date. If you defined a subset of target funds in the target_funds = [] parameter when starting the databased, it will also be considered when updating the database.

Obs: If you changed the default db_dir = r'investments_database.db' parameter when starting the database, make sure to add it to the "update_db" function as well.

Calculating performance metrics for the investment funds

This package contains pre-built performance metrics for investment funds analysis:

  • returns function - Calculates the % returns for the given assets both in rolling windows or for the full available period (you also get the CAGR in this option).
  • cum_returns function - Calculates the cumulative % returns for the given assets.
  • drawdown function - Calculates the drawdown (the % the asset is down from its all-time-high) for the givens assets.
  • volatility function - Calculates the annualized volatillity (standard deviation of returns with degree of freedom = 0) for givens assets returns both in rolling windows or for the full available period.
  • corr_benchmark function - Calculates the correlation between assets and a given benchmark both in rolling windows or for the full available period.
  • beta function - Calculates the beta (measure of the volatility of an asset compared to the market, usually represented by an index benchmark) for the given assets.
  • alpha function - Calculates the alpha (measure of the excess of return of an asset compared to the market, usually represented by an index benchmark) for the given assets.
  • sharpe function - Calculates the sharpe ratio (average return earned in excess of the risk-free rate per unit of volatility) for the given assets.
  • sortino function - Calculates the sortino ratio (average return earned in excess of the risk-free rate per unit of negative volatility) for the given assets.
  • capture_ratio function - Calculates the capture ratios (measure of assets performance relative to its benchmark in bull and bear markets windows) for the given assets.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

fundspy's People

Contributors

joaopm33 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fundspy's Issues

Change database cleaning method when updating it.

Data from the CVM source can be corrected after the first release.

The current database updating method only extracts data with dates after the last database update (log table).

The updating method should extract all available data and then remove duplicate values (same fund, same date), keeping the last (most recent) record.

This will probably make the updating method more expensive in execution time (specially in large .db files), but improve data quality.

improve list parameters for functions

Put default parameter as none and initializing a empty list inside the scope of the functions. This will make the api uglier, but defining the empty list (mutable object) in the arguments of the function makes it a global variable (initialized only once). This can generate bugs.

Add parameter to start database function

  • Add a parameter to delimit the start and end dates to the database generator
  • Add parameter do target specific funds in the database generator
    These changes will make possible for users with specific data targets to generate smaller databases according to their needs.

Change ibovespa index datasource

investpy (investing.com) only provides data for the index starting from 2008. CVM data starts in 2005.

Maybe theres a feasable ibovespa free source with data from earlier on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.