Skip to content

Commit

Permalink
Merge pull request #28 from GrupoTuring/docs/sphinx
Browse files Browse the repository at this point in the history
Cria documentação utilizando sphinx
  • Loading branch information
anor4k committed Oct 20, 2020
2 parents 67120e5 + b88c97e commit d04f5f1
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 116 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
69 changes: 69 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../'))

# -- Project information -----------------------------------------------------

project = 'turingquant'
copyright = '2020, Grupo Turing'
author = 'Grupo Turing'

# The full version, including alpha/beta/rc tags
release = '0.1.5'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx_rtd_theme'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'pt_BR'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# Napoleon settings

napoleon_numpy_docstring = False
# napoleon_use_param = False

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
47 changes: 47 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
turingquant
===========

``turingquant`` é uma biblioteca para coleta, análise e backtesting de ativos e estratégias financeiras.
O projeto está em desenvolvimento ativo pelos membros de Finanças Quantitativas do `Grupo Turing <https://github.com/GrupoTuring>`_.

A API de onde obtemos os dados fundamentalistas é a Alpha Vantage e você pode `obter a chave de uso gratuitamente <https://www.alphavantage.co/support/#api-key>`_.
Essa chave será necessária sempre que você utilizar as funções daily e intraday.

``pip install turingquant`` instala a última versão estável.

.. toctree::
:maxdepth: 4
:caption: Contents:

.. automodule:: turingquant
:members:
:undoc-members:
:show-inheritance:

Módulos
-------

.. autosummary::

turingquant.metrics
turingquant.benchmark
turingquant.support

Módulo metrics
==============

.. automodule:: turingquant.metrics
:members:

Módulo benchmark
================

.. automodule:: turingquant.benchmark
:members:

Módulo support
==============

.. automodule:: turingquant.support
:members:

35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="turingquant",
version="0.1.4",
version="0.1.5",
packages=find_packages(),
install_requires=["pandas", "pandas_datareader", "numpy", "matplotlib", "alpha_vantage", "bs4", "plotly", "yfinance"],

Expand Down
34 changes: 21 additions & 13 deletions turingquant/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Módulo para comparação e benchmarking de ativos e retornos."""

import pandas as pd
import plotly.express as px
from datetime import datetime
Expand All @@ -9,13 +11,15 @@ def benchmark(ticker, start: datetime, end: datetime, source='yahoo', plot=True)
Essa função fornece um plot de retorno acumulado de um ativo ao longo de um dado intervalo de tempo, definido pelos parâmetros start e end.
Os dados são coletados da API do yahoo, caso haja dados faltantes, os retornos são contabilizados como nulos.
ticker[str]: recebe o ticker do papel que será obtido
start[datetime]: início do intervalo
Args:
ticker (str): recebe o ticker do papel que será obtido.
start (datetime): início do intervalo.
end (datetime): final do intervalo.
plot (bool): opcional; exibe o gráfico caso `True`.
end[datetime]: final do interval
Returns:
pd.series: uma série de ativos indexados com o tempo com o retorno cumulativo para o período.
plot[bool]: (default = True) se True, realiza o plot
"""

asset = data.DataReader(ticker, data_source=source, start=start, end=end)
Expand All @@ -35,11 +39,13 @@ def benchmark_ibov(start: datetime, end: datetime, source='yahoo', plot=True):
"""
Essa função produz um plot da evolução do Índice Bovespa ao longo de um dado intervalo, definido pelos parâmetros start e end.
start[datetime]: início do intervalo
Args:
start (datetime): início do intervalo.
end (datetime): final do intervalo.
plot (bool): opcional; exibe o gráfico caso `True`.
end[datetime]: final do interval
plot[bool]: (default = True) se True, realiza o plot
Returns:
pd.series: uma série temporal com o retorno acumulado do Ibovespa para o período.
"""

return benchmark('^BVSP', start=start, end=end, source=source, plot=plot)
Expand All @@ -49,11 +55,13 @@ def benchmark_sp500(start: datetime, end: datetime, source='yahoo', plot=True):
"""
Essa função produz um plot da evolução do Índice S&P500 ao longo de um dado intervalo, definido pelos parâmetros start e end.
start[datetime]: início do intervalo
end[datetime]: final do interval
Args:
start (datetime): início do intervalo.
end (datetime): final do intervalo.
plot (bool): opcional; exibe o gráfico caso `True`.
plot[bool]: (default = True) se True, realiza o plot
Returns:
pd.series: uma série temporal com o retorno acumulado do S&P500 para o período.
"""

return benchmark('^GSPC', start=start, end=end, source=source, plot=plot)

0 comments on commit d04f5f1

Please sign in to comment.