All Projects → fmilthaler → Finquant

fmilthaler / Finquant

Licence: mit
A program for financial portfolio management, analysis and optimisation.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Finquant

py-investment
Extensible Algo-Trading Python Package.
Stars: ✭ 19 (-95.19%)
Mutual labels:  finance, financial, investment
DCF
Basic Discounted Cash Flow library written in Python. Automatically fetches relevant financial documents for chosen company and calculates DCF based on specified parameters.
Stars: ✭ 198 (-49.87%)
Mutual labels:  finance, investment
finac
Finac - financial accounting for humans
Stars: ✭ 27 (-93.16%)
Mutual labels:  finance, financial
stocklist
Stock data collection and analysis
Stars: ✭ 27 (-93.16%)
Mutual labels:  finance, financial
Algorithmictrading
This repository contains three ways to obtain arbitrage which are Dual Listing, Options and Statistical Arbitrage. These are projects in collaboration with Optiver and have been peer-reviewed by staff members of Optiver.
Stars: ✭ 157 (-60.25%)
Mutual labels:  analysis, finance
bankster
Money Creation Made Easy
Stars: ✭ 30 (-92.41%)
Mutual labels:  finance, financial
Beibo
🤖 Predict the stock market with AI 用AI预测股票市场
Stars: ✭ 46 (-88.35%)
Mutual labels:  finance, investment
Ta Rs
Technical analysis library for Rust language
Stars: ✭ 248 (-37.22%)
Mutual labels:  finance, financial
GOAi
No description or website provided.
Stars: ✭ 57 (-85.57%)
Mutual labels:  finance, investment
investbook
Оценка эффективности инвестиций с учетом комиссий, налогов (удержанных и ожидающихся), дивидендов и купонов.
Stars: ✭ 83 (-78.99%)
Mutual labels:  finance, investment
simulatePortfolio
class for simulation of stock investing portfolios based on historical data
Stars: ✭ 18 (-95.44%)
Mutual labels:  finance, investment
Trading Signals
Technical indicators to run technical analysis with JavaScript / TypeScript. 📈
Stars: ✭ 118 (-70.13%)
Mutual labels:  analysis, financial
Awesome Ai In Finance
🔬 A curated list of awesome machine learning strategies & tools in financial market.
Stars: ✭ 910 (+130.38%)
Mutual labels:  analysis, financial
Stocksera
Web application that provides alternative data to retail investors
Stars: ✭ 426 (+7.85%)
Mutual labels:  finance, financial
Financedatabase
This is a database of 180.000+ symbols containing Equities, ETFs, Funds, Indices, Futures, Options, Currencies, Cryptocurrencies and Money Markets.
Stars: ✭ 554 (+40.25%)
Mutual labels:  analysis, finance
Riskfolio Lib
Portfolio Optimization and Quantitative Strategic Asset Allocation in Python
Stars: ✭ 305 (-22.78%)
Mutual labels:  finance, investment
Pyportfolioopt
Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
Stars: ✭ 2,502 (+533.42%)
Mutual labels:  finance, investment
Vnpy
基于Python的开源量化交易平台开发框架
Stars: ✭ 17,054 (+4217.47%)
Mutual labels:  finance, investment
dimeshift-desktop
DimeShift desktop application
Stars: ✭ 14 (-96.46%)
Mutual labels:  finance, financial
Django Ledger
A bookkeeping & financial analysis engine for the Django Framework. UNDER ACTIVE DEVELOPMENT & NOT STABLE YET.
Stars: ✭ 253 (-35.95%)
Mutual labels:  finance, financial

pypi pypi travis docs contributors contributions license

FinQuant

FinQuant is a program for financial portfolio management, analysis and optimisation.

This README only gives a brief overview of FinQuant. The interested reader should refer to its documentation.

Table of contents

Motivation

Within a few lines of code, FinQuant can generate an object that holds your stock prices of your desired financial portfolio, analyses it, and can create plots of different kinds of Returns, Moving Averages, Moving Average Bands with buy/sell signals, and Bollinger Bands. It also allows for the optimisation based on the Efficient Frontier or a Monte Carlo run of the financial portfolio within a few lines of code. Some of the results are shown here.

Automatically generating an instance of Portfolio

finquant.portfolio.build_portfolio is a function that eases the creating of your portfolio. See below for one of several ways of using build_portfolio.

from finquant.portfolio import build_portfolio
names = ['GOOG', 'AMZN', 'MCD', 'DIS']
start_date = '2015-01-01'
end_date = '2017-12-31'
pf = build_portfolio(names=names,
                    start_date=start_date,
                    end_date=end_date)

pf is an instance of finquant.portfolio.Portfolio, which contains the prices of the stocks in your portfolio. Then...

pf.data.head(3)

yields

              GOOG    AMZN        MCD        DIS
Date
2015-01-02  524.81  308.52  85.783317  90.586146
2015-01-05  513.87  302.19  84.835892  89.262380
2015-01-06  501.96  295.29  84.992263  88.788916

Portfolio properties

Nicely printing out the portfolio's properties

pf.properties()

Depending on the stocks within your portfolio, the output looks something like the below.

----------------------------------------------------------------------
Stocks: GOOG, AMZN, MCD, DIS
Time window/frequency: 252
Risk free rate: 0.005
Portfolio expected return: 0.266
Portfolio volatility: 0.156
Portfolio Sharpe ratio: 1.674

Skewness:
       GOOG      AMZN      MCD       DIS
0  0.124184  0.087516  0.58698  0.040569

Kurtosis:
       GOOG      AMZN       MCD       DIS
0 -0.751818 -0.856101 -0.602008 -0.892666

Information:
   Allocation  Name
0        0.25  GOOG
1        0.25  AMZN
2        0.25   MCD
3        0.25   DIS
----------------------------------------------------------------------

Cumulative Return

pf.comp_cumulative_returns().plot().axhline(y = 0, color = "black", lw = 3)

yields

Band Moving Average (Buy/Sell Signals)

from finquant.moving_average import compute_ma, ema
# get stock data for disney
dis = pf.get_stock("DIS").data.copy(deep=True)
spans = [10, 50, 100, 150, 200]
ma = compute_ma(dis, ema, spans, plot=True)

yields

Bollinger Band

from finquant.moving_average import plot_bollinger_band
# get stock data for disney
dis = pf.get_stock("DIS").data.copy(deep=True)
span=20
plot_bollinger_band(dis, sma, span)

yields

Portfolio Optimisation

# performs and plots results of Monte Carlo run (5000 iterations)
opt_w, opt_res = pf.mc_optimisation(num_trials=5000)
# plots the results of the Monte Carlo optimisation
pf.mc_plot_results()
# plots the Efficient Frontier
pf.ef_plot_efrontier()
# plots optimal portfolios based on Efficient Frontier
pf.ef.plot_optimal_portfolios()
# plots individual plots of the portfolio
pf.plot_stocks()

Installation

As it is common for open-source projects, there are several ways to get hold of the code. Choose whichever suits you and your purposes best.

Dependencies

FinQuant depends on the following Python packages:

  • python>=3.5.0
  • numpy>=1.15
  • pandas>=0.24
  • matplotlib>=1.5.1
  • quandl>=3.4.5
  • yfinance>=0.1.43
  • scipy>=1.2.0
  • pytest>=2.8.7

From PyPI

FinQuant can be obtained from PyPI

pip install FinQuant

From GitHub

Get the code from GitHub:

git clone https://github.com/fmilthaler/FinQuant.git

Then inside FinQuant run:

python setup.py install

Alternatively, if you do not wish to install FinQuant, you can also download/clone it as stated above, and then make sure to add it to your PYTHONPATH.

Portfolio Management

This is the core of FinQuant. finquant.portfolio.Portfolio provides an object that holds prices of all stocks in your portfolio, and automatically computes the most common quantities for you. To make FinQuant an user-friendly program, that combines data analysis, visualisation and optimisation, the object provides interfaces to the main features that are provided in the modules in ./finquant/.

To learn more about the object, please read through the documentation, docstring of the module/class, and/or have a look at the examples.

finquant.portfolio.Portfolio also provides a function build_portfolio which is designed to automatically generate an instance of Portfolio for the user's convenience. For more information on how to use build_portfolio, please refer to the documentation, its docstring and/or have a look at the examples.

Returns

Daily returns of stocks are often computed in different ways. FinQuant provides three different ways of computing the daily returns in finquant.returns:

  1. The cumulative return:
  2. Percentage change of daily returns:
  3. Log Return:

In addition to those, the module provides the function historical_mean_return(data, freq=252), which computes the historical mean of the daily returns over a time period freq.

Moving Averages

The module finquant.moving_average allows the computation and visualisation of Moving Averages of the stocks listed in the portfolio is also provided. It entails functions to compute and visualise the

  • sma: Simple Moving Average, and
  • ema: Exponential Moving Average.
  • compute_ma: a Band of Moving Averages (of different time windows/spans) including Buy/Sell signals
  • plot_bollinger_band: a Bollinger Band for
    • sma,
    • ema.

Portfolio Optimisation

Efficient Frontier

An implementation of the Efficient Frontier (finquant.efficient_frontier.EfficientFrontier) allows for the optimisation of the portfolio for

  • minimum_volatility Minimum Volatility,
  • maximum_sharpe_ratio Maximum Sharpe Ratio
  • efficient_return Minimum Volatility for a given expected return
  • efficient_volatility Maximum Sharpe Ratio for a given target volatility

by performing a numerical solve to minimise/maximise an objective function.

Often it is useful to visualise the Efficient Frontier as well as the optimal solution. This can be achieved with the following methods:

  • plot_efrontier: Plots the Efficient Frontier. If no minimum/maximum Return values are provided, the algorithm automatically chooses those limits for the Efficient Frontier based on the minimum/maximum Return values of all stocks within the given portfolio.
  • plot_optimal_portfolios: Plots markers of the portfolios with the Minimum Volatility and Maximum Sharpe Ratio.

For reasons of user-friendliness, interfaces to these functions are provided in finquant.portfolio.Portfolio. Please have a look at the documentation.

Monte Carlo

Alternatively a Monte Carlo run of n trials can be performed to find the optimal portfolios for

  • minimum volatility,
  • maximum Sharpe ratio

The approach branded as Efficient Frontier should be the preferred method for reasons of computational effort and accuracy. The latter approach is only included for the sake of completeness, and creation of beautiful plots.

Examples

For more information about the project and details on how to use it, please look at the examples provided in ./example.

Note: In the below examples, pf refers to an instance of finquant.portfolio.Portfolio, the object that holds all stock prices and computes its most common quantities automatically. To make FinQuant a user-friendly program, that combines data analysis, visualisation and optimisation, the object also provides interfaces to the main features that are provided in the modules in ./finquant/ and are discussed throughout this README.

Building a portfolio with data from web

./example/Example-Build-Portfolio-from-web.py: Shows how to use FinQuant to build a financial portfolio by downloading stock price data through the Python package quandl/yfinance.

Building a portfolio with preset data

./example/Example-Build-Portfolio-from-file.py: Shows how to use FinQuant to build a financial portfolio by providing stock price data yourself, e.g. by reading data from disk/file.

Analysis of a portfolio

./example/Example-Analysis.py: This example shows how to use an instance of finquant.portfolio.Portfolio, get the portfolio's quantities, such as

  • Expected Returns,
  • Volatility,
  • Sharpe Ratio.

It also shows how to extract individual stocks from the given portfolio. Moreover it shows how to compute and visualise:

  • the different Returns provided by the module finquant.returns,
  • Moving Averages, a band of Moving Averages, and a Bollinger Band.

Optimisation of a portfolio

./example/Example-Optimisation.py: This example focusses on the optimisation of a portfolio. To achieve this, the example shows the usage of finquant.efficient_frontier.EfficientFrontier for optimising the portfolio, for the

  • Minimum Volatility
  • Maximum Sharpe Ratio
  • Minimum Volatility for a given target Return
  • Maximum Sharpe Ratio for a given target Volatility.

Furthermore, it is also shown how the entire Efficient Frontier and the optimal portfolios can be computed and visualised. If needed, it also gives an example of plotting the individual stocks of the given portfolio within the computed Efficient Frontier.

Also, the optimisation of a portfolio and its visualisation based on a Monte Carlo is shown.

Finally, FinQuant's visualisation methods allow for overlays, if this is desired. Thus, with only the following few lines of code, one can create an overlay of the Monte Carlo run, the Efficient Frontier, its optimised portfolios for Minimum Volatility and Maximum Sharpe Ratio, as well as the portfolio's individual stocks.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].