finmarketpy

repository·master·Indexed 26 days ago

https://github.com/cuemacro/finmarketpy

A Python library for analyzing market data and backtesting trading strategies. It provides prebuilt templates for backtesting, seasonality investigation, event studies, and risk weighting using volatility targeting. The library integrates with chartpy for plotting and findatapy for market data loading, and supports ArcticDB as a bitemporal data backend.

Tokens
15.4K
Snippets
24
Records
85
Agent score
87%

What's inside finmarketpy

  1. Install FinancePy for option pricing

    master

    If you require option pricing capabilities, you must install financepy. It is highly recommended to install it separately using the --no-deps flag to avoid dependency clashes (specifically with llvmlite).

    Install the required stack first, then install the specific version of financepy recommended for stability.

    pip install numba numpy scipy llvmlite ipython pandas prettytable
    pip install financepy==0.370 --no-deps
  2. Install findatapy in a dedicated Conda environment

    master

    To ensure pip installs packages into the specific environment's site-packages folder rather than the global folder, you must include pip during the environment creation step.

    Follow these steps:

    1. Create the environment with pip included:
      conda create -n cuemacro python=3.6 pip
    2. Activate the environment:
      activate cuemacro
    3. Install findatapy via git:
      pip install git+https://github.com/cuemacro/findatapy.git
    conda create -n cuemacro python=3.6 pip
    activate cuemacro
    pip install git+https://github.com/cuemacro/findatapy.git
  3. Set up a development environment for findatapy

    master

    If you intend to work on the findatapy source code itself, it is recommended to install its dependencies manually and then add the cloned repository to your PYTHONPATH. This keeps your working code separate from the site-packages directory.

    1. Create a development environment:
      conda create -n devcuemacro python=3.6 pip
    2. Activate the environment:
      activate devcuemacro
    3. Install the required dependencies (examples include pandas, twython, pytz, etc.) using pip or conda.
    4. Clone the findatapy repository and add its location to your PYTHONPATH.
    conda create -n devcuemacro python=3.6 pip
    activate devcuemacro
    pip install pandas twython pytz requests numpy pandas_datareader quandl statsmodels multiprocess
  4. Install the full Anaconda distribution in a Conda environment

    master

    To install a Conda instance that includes a large collection of pre-installed libraries (like pandas), use the anaconda meta-package during creation:

    conda create -n devcuemacro python=3.6 anaconda
  5. Set up Open Sans fonts for chartpy

    master

    The chartpy library uses the Open Sans font family by default for matplotlib. To ensure correct rendering:

    1. Download Open Sans from Font Squirrel.
    2. Install the fonts on your operating system (e.g., copy to C:\Windows\Fonts on Windows).
    3. Delete the matplotlib font cache file (e.g., fontList.py3k.cache in C:\Users\<username>\.matplotlib) so it picks up the new font.
  6. Install the Cuemacro Python libraries

    master

    You can install the core Cuemacro libraries using pip. It is recommended to use the Anaconda distribution (specifically Python 3.7) to manage dependencies like NumPy and pandas.

    Installation Commands:

    • chartpy: pip install chartpy
    • findatapy: pip install findatapy
    • finmarketpy: pip install git+https://github.com/cuemacro/finmarketpy.git
    • arctic (MongoDB wrapper): pip install arctic
    pip install chartpy
    pip install findatapy
    pip install git+https://github.com/cuemacro/finmarketpy.git
    pip install arctic
  7. Upgrade finmarketpy and Cuemacro packages without affecting dependencies

    master

    To update finmarketpy, findatapy, and chartpy to their latest versions without triggering updates or changes to your existing environment dependencies, use the --no-deps flag.

    pip install -U --no-deps finmarketpy findatapy chartpy
  8. Install finmarketpy and its dependencies

    master

    To use finmarketpy, you must first install its core dependencies chartpy and findatapy. It is recommended to install the latest versions directly from GitHub.

    After installing the core libraries, install finmarketpy. Note that you will need to configure marketconstants.py (or create marketcred.py) within finmarketpy to set up your market credentials.

    Prerequisites:

    • Python 3.10
    • pandas, numpy, etc.
    • chartpy (for plotting)
    • findatapy (for market data loading)

    Configuration requirements:

    • In chartpy: Edit chartconstants.py to add your Plotly API key.
    • In findatapy: Edit dataconstants.py to add your Quandl API key (or create a datacred.py file in the util folder).
    # 1. Install dependencies from GitHub
    pip install git+https://github.com/cuemacro/chartpy.git
    pip install git+https://github.com/cuemacro/findatapy.git
    
    # 2. Install finmarketpy from GitHub
    pip install git+https://github.com/cuemacro/finmarketpy.git
  9. Configure findatapy using DataCred

    master

    To avoid configuration being overwritten during upgrades, create a datacred.py class in the findatapy/util/ folder. This class allows you to override default settings for data paths, API keys, and database connections.

    Key attributes you can configure include:

    • folder_historic_CSV: Path for historic CSV data.
    • folder_time_series_data: Path for time series data.
    • config_root_folder: Path to your custom configuration folder.
    • quandl_api_key, fred_api_key: API keys for data providers.
    • db_server, db_cache_server, db_cache_port: Database and cache connection settings.
    • write_cache_engine: Set to 'redis' or other supported engines.
    class DataCred(object):
        folder_historic_CSV = "E:/tickdata/historicCSV"
        folder_time_series_data = "C:/timeseriesdata"
    
        config_root_folder = "E:/Remote/yen/conf/"
    
        ###### FOR ALIAS TICKERS
        # config file for time series categories
        time_series_categories_fields = \
            config_root_folder + "conf/time_series_categories_fields.csv"
    
        # we can have multiple tickers files (separated by ";")
        time_series_tickers_list = config_root_folder + "conf/time_series_tickers_list.csv;" + \
                                   config_root_folder + "conf/futures_contracts_tickers.csv"
    
        time_series_fields_list = config_root_folder + "conf/time_series_fields_list.csv"
    
        # config file for long term econ data
        all_econ_tickers = config_root_folder + "conf/all_econ_tickers.csv"
        econ_country_codes = config_root_folder + "conf/econ_country_codes.csv"
        econ_country_groups = config_root_folder + "conf/econ_country_groups.csv"
    
        default_market_data_generator = "marketdatagenerator"
    
        # Quandl settings
        quandl_api_key = "XYZ"
    
        # Twitter settings (you need to set these up on Twitter)
        TWITTER_APP_KEY = "XYZ"
        TWITTER_APP_SECRET = "XYZ"
        TWITTER_OAUTH_TOKEN = "XYZ"
        TWITTER_OAUTH_TOKEN_SECRET = "XYZ"
    
        # FRED API key
        fred_api_key = "XYZ"
    
        # database settings need to be filled in even if you aren't going to use one
        # main database settings
        db_server = '127.0.0.1'
    
        # cache database settings
        db_cache_server = '127.0.0.1'
        db_cache_port = '6379'
        write_cache_engine = 'redis'
    
        # Override multithreading for certain categories of downloads
        override_multi_threading_for_categories = []