fecon235

repository·master·Indexed 22 days ago

https://github.com/rsvp/fecon235

A collection of Jupyter notebooks and high-level Python interfaces for financial economics research. It integrates scientific libraries like numpy, pandas, statsmodels, scipy, and matplotlib to simplify data retrieval from FRED, Quandl, and pandas_datareader, as well as data munging, econometric analysis, mathematical optimization, and visualization. The project utilizes the fecon236 package for core logic and provides a Docker image for a fully-configured environment.

Tokens
11.3K
Snippets
14
Records
67
Agent score
79%

What's inside fecon235

  1. Overview of fecon235 capabilities

    master

    The fecon235 repository provides a high-level interface for financial economics within the Python ecosystem. It integrates complex packages like numpy, pandas, statsmodels, scipy, and matplotlib to perform the following tasks:

    • Data Retrieval: Accessing historical and current economic/financial data from hosts like FRED (Federal Reserve Economic Data) and Quandl (for specialized data like futures prices). Stock, mutual fund, and ETF data is retrieved via pandas_datareader.
    • Data Munging: Handling time-series alignment and resampling across incompatible formats.
    • Econometric Analysis: Implementing techniques from time-series analysis and statistical machine learning.
    • Mathematical Optimization: Abstracting operators for tasks like linear algebra in portfolio analysis.
    • Visualization: Graphical representation of economic data.
    • Reproducible Research: Providing open, collaborative notebooks in the nb directory.
  2. Core data sources in fecon235

    master

    The project relies on several key data providers:

    • FRED (Federal Reserve Economic Data): The primary source for US economic data, accessed directly online.
    • Quandl API: Used for specialized data, such as futures prices.
    • pandas_datareader: Used to retrieve data for stocks, mutual funds, and ETFs from various available sources.
  3. Use the fecon235 Docker image

    master

    For an instant, fully-configured environment containing all necessary dependencies for running interactive notebooks and programs, use the official Docker image.

    Run the following command to pull the image:

    docker pull rsvp/fecon235
  4. Get started with fecon235 notebooks and modules

    master

    The fecon235 project provides computational data tools for financial economics through Jupyter notebooks and Python modules.

    • Setup: Refer to the README.md in the main repository for setup instructions.
    • Core Module: The fecon235.py module unifies the essential modules. Detailed import information is available at https://git.io/fecon-intro.
    • Learning by Example: The best way to learn is to interactively work with notebooks in the nb directory (https://git.io/fecon235nb).
    • Customization: The lib directory contains Python modules that serve as templates for accessing pandas, numpy, and matplotlib if you need to extend the high-level commands.
  5. Retrieve financial stock data using 'stock slang'

    master

    To retrieve financial data (sourced from Yahoo Finance with a fallback to Google Finance), use the "stock slang" format: s4symbol, where symbol is the ticker in all lower-case.

    Example: To retrieve the SPY ETF, use s4spy. The returned data is a pandas DataFrame. For more details, see the lib/yi_stocks.py module.

  6. Explore fecon235 Jupyter Notebooks

    master

    The nb directory contains a collection of Jupyter notebooks that demonstrate practical applications of the library. While GitHub can render these notebooks for viewing, they are not executable in the browser. To execute them and retrieve live data, you must run them in a local Python environment or the provided Docker container.

    Key examples include:

  7. Get started with fecon235

    master

    To begin using fecon235 for financial economics research, you can follow these paths:

    1. Learning Resources: For economists transitioning to Python, refer to Quantitative Economics by Thomas Sargent.
    2. Installation: Detailed installation instructions and external dependency information are available at https://git.io/econ.
    3. Legacy Notebooks: If you are using notebooks created before 2016, follow the import style documented at https://git.io/fecon-intro.
    4. Docker (Recommended for quick setup): You can instantly run a fully-configured environment with interactive notebooks by pulling the official Docker image.
    docker pull rsvp/fecon235
  8. Evaluate the value of alternative data sets for financial markets

    master

    When developing a case for the value of alternative data (e.g., for selling to hedge funds or banks), evaluate the data based on four primary dimensions: Predictive Properties, Exclusivity, Complexity, and Content Consistency.

    1. Predictive Properties

    The most critical factor is whether the data has predictive power for financial markets (volume, volatility, returns). To prove value, you must demonstrate:

    • Usage Context: Determine if the data is for Trading (fast-moving, sub-second to days) or Investing (infrequent updates, weeks to months).
    • Historical Depth: Trading data typically requires $\le$ 2 years of history; Investment data often requires spanning multiple economic cycles.
    • Macro vs Micro: Identify if the data drives microstructure (instrument-specific) or macro trends (e.g., US GDP).
    • Liquidity: Ensure there is sufficient liquidity to enter and, crucially, exit positions based on the signals.
    • Alpha/Sharpe Ratio: Quantify the excess return (alpha) and risk-adjusted return (Sharpe ratio).

    2. Exclusivity

    Balance the premium commanded by exclusivity against the risks of scarcity:

    • Direct Substitutes: Other geolocation services or similar data providers.
    • Indirect Substitutes: Satellite imagery, credit/debit card history, or aggregations of raw data.
    • Market Reach: Too many clients erode value; too few clients may attract regulatory/media scrutiny.

    3. Complexity and Product Variants

    Reduce the barrier to entry for prospects by simplifying data consumption:

    • Avoid Raw Complexity: Instead of providing raw coordinates (e.g., lat/lon), provide normalized metrics like 'visits per store per day/week/month'.
    • Offer Variants: Provide different tiers such as store chain reports or sector/sub-sector level offerings to reach different market segments (e.g., futures traders vs. equities traders).

    4. Content Consistency

    Ensure data integrity to prevent look-ahead bias:

    • Point-In-Time Representation: Data should reflect what was known at the time of publication. This may require rescoring historical data using current models.
    • Versioning & Documentation: Maintain a versioned data set, a robust data dictionary, and documentation covering indexing, metadata, assembly, and back-testing results.
  9. Retrieve economic FRED data series

    master

    To access data from the St. Louis Federal Reserve Bank, use the get() function with a fredcode. The fredcode can be provided as a string or assigned to a variable using specific naming conventions based on frequency (e.g., d4* for daily, m4* for monthly, q4* for quarterly).

    First, find the desired fredcode at https://fred.stlouisfed.org. For more details, refer to the lib/yi_fred.py module.

  10. Format stock slang strings

    master

    To avoid namespace collisions, this module uses a 'slang' convention for stock symbols. A valid slang string must:

    1. Be entirely in lowercase.
    2. Start with the prefix s4.

    For example, to access data for the symbol AAPL, you must use the slang 's4aapl'. The stock_decode() function handles the translation from this slang format back to the uppercase vendor symbol.

  11. How `softmax()` and `softmax_sort()` differ

    master

    While both functions compute softmax probabilities, they serve different use cases:

    1. softmax():

      • Use case: Tracking a specific class over time (e.g., softmax()[-1][i]) or performing fast temperature variation testing.
      • Performance: Faster.
      • Output: A raw list of probabilities.
    2. softmax_sort():

      • Use case: Extracting information about the top-k classes (e.g., softmax_sort()[:3]).
      • Performance: Slower due to sorting and filtering.
      • Output: A list of (probability, index, value) tuples, with optional filtering (drop) and renormalization (renorm).