finmarketpy is a Python based library that enables you to analyze market data and also to backtest trading strategies using a simple to use API, which has prebuilt templates for you to define backtest. Included in the library
- Prebuilt templates for backtesting trading strategies
- Display historical returns for trading strategies
- Investigate seasonality of trading strategies
- Conduct market event studies around data events
- In built calculator for risk weighting using volatility targeting
- Written in object oriented way to make code more reusable
Contributors for the project are very much welcome, see below!
I had previously written the open source PyThalesians financial library (which has been merged with this - so can focus on maintaining one set of libraries). This new finmarketpy library has
- Similar functionality to the trading part of pythalesians
- Rewritten the API to make it much cleaner and easier to use, as well as having many new features.
- finmarketpy requires the libraries, which I've written chartpy (for charts) and findatapy (for loading market data) to function
- By splitting up into smaller more specialised libraries, it should make it easier for contributors
- Using findatapy, you can download market data easily from Bloomberg, Quandl, Yahoo etc
- Using chartpy, you can choose to have results displayed in matplotlib, plotly or bokeh by changing single keyword!
Points to note:
- Please bear in mind at present finmarketpy is under continual development. The API is heavily documented, but we are looking to add more general documentation.
- Uses Apache 2.0 licence
Calculate the cumulative returns of a trading strategy historically (see finmarketpy_examples/tradingmodelfxtrend_example.py)
Plot the leverage of the strategy over time
Plot the individual trade returns
Calculate seasonality of any asset: here we show gold and FX volatility seasonality (see examples/seasonality_examples.py)
Calculate event study around events for asset (see examples/events_examples.py)
Major requirements
- Required: Python 3.6
- Required: pandas 0.24.2, numpy etc.
- Required: findatapy for downloading market data (https://github.com/cuemacro/findatapy)
- Required: chartpy for funky interactive plots (https://github.com/cuemacro/chartpy)
For detailed installation instructions for finmarketpy and its associated Python libraries go to https://github.com/cuemacro/finmarketpy/blob/master/INSTALL.md (which includes details on how to setup your entire Python environment).
Also take a look at https://github.com/cuemacro/teaching/blob/master/pythoncourse/installation/installing_anaconda_and_pycharm.ipynb from my Python for finance workshop course, where I keep notes specifically about setting up your Anaconda environment for data science (including for findatapy/chartpy/finmarketpy), including YAML files etc.
You can install the library using the below (better to get the newest version from repo, as opposed to releases).
After installation:
- Make sure you edit the marketconstants.py file (or you can create a marketcred.py file to overwrite the settings)
pip install git+https://github.com/cuemacro/finmarketpy.git
But beforehand please make sure you have already installed both chartpy, findatapy and any other dependencies. In chartpy you will need to change the chartconstants.py file (to add Plotly API key) and for findatapy, you will also need to change the dataconstants.py file to add the Quandl API (and possibly change other configuration settings there or add a datacred.py file in the util folder, alternatively you will be prompted on your first run to input the API key which will be installed).
pip install git+https://github.com/cuemacro/chartpy.git
pip install git+https://github.com/cuemacro/findatapy.git
Contributors are always welcome for finmarketpy, findatapy and chartpy. If you'd like to contribute, have a look at Planned Features for areas we're looking for help on. Or if you have any ideas for improvements to the libriares please let us know too!
In finmarketpy/examples you will find several examples, including some simple trading models
- 0.11.3 - finmarketpy (04 Dec 2019)
- 0.11.1 - finmarketpy (23