Generate Sharpe, Sortino, Information, Treynor, Calmar, and Omega ratios for financial risk analysis from Alpaca historical market price data

Hi Alpaca community members,

Computing these financial ratios for stocks serves several purposes:

  • Performance Evaluation: These ratios help investors and analysts evaluate the historical performance of a stock or a portfolio. They can provide insights into how well a stock has performed compared to a benchmark or the market in general.

  • Risk Assessment: Ratios such as the Sharpe Ratio, Sortino Ratio, Information Ratio, and Treynor Ratio help investors understand the risk-adjusted performance of a stock or a portfolio. By considering both returns and risk, investors can make more informed decisions about their investments.

  • Portfolio Optimization: Financial ratios can be used to optimize a portfolio by selecting stocks with the desired risk-return characteristics. For example, investors might choose stocks with high Sharpe Ratios to maximize returns per unit of risk.

  • Investment Strategy: By analyzing these ratios, investors can develop and refine their investment strategies. For example, they might focus on stocks with high Omega Ratios to capture more upside potential than downside risk, or use Calmar Ratios to identify investments with favorable risk-return profiles in the context of drawdowns.

  • Comparison: Investors can use these financial ratios to compare different stocks or portfolios and identify the best opportunities based on their investment goals and risk tolerance.

These financial ratios help investors analyze stock performance, assess risk, optimize their portfolios, and develop effective investment strategies.

The GitHub repository can be accessed with the following link:

GitHub repository for StockFinancialRatios

You can clone the repository, with the following command:

git clone

The repository contains several python scripts:

  • - This script fetches a list of all active assets from the Alpaca API and stores it in a user-defined text file. It uses the Alpaca API’s REST client and Pandas library to extract symbols and names from the assets, save the DataFrame to a text file. The script can be run from the command line with optional file name argument.
  • - This Python script fetches historical price data for a given list of stock symbols using the Alpaca Trade API, saves the data to files and runs the program concurrently with the use of ThreadPoolExecutor. It uses the NYSE calendar to calculate the date range for fetching data, and fetches historical prices for stock symbols in the universe. The data is saved to a file if the number of rows is equal to ndays.
  • - This Python script calculates financial ratios of stock prices using reference prices. The script reads stock prices from a file, processes them to calculate financial ratios such as Sharpe Ratio, Sortino Ratio, Information Ratio, Treynor Ratio, Calmar Ratio, Omega Ratio, and Weighted Average, and outputs the results in a formatted table. The script can process a single stock or a list of stocks and can sort the output based on a specified column.

I’ve also included bash scripts to fetch/process the price data and compile the python programs into C code, for your reference.

Please let me know if you have any ideas on how to combine these financial ratios with other data types. Please share any lists of interesting symbols with other Alpaca community members.

Best regards,

Joe O.