SDKs overview

Portfolio Optimizer offers client libraries (SDKs) to facilitate programmatic interaction with its suite of RESTful APIs. These APIs are designed for tasks such as portfolio optimization, risk analysis, and backtesting financial strategies. The primary goal of providing SDKs is to reduce the complexity of direct HTTP request management and JSON parsing, allowing developers to focus on financial modeling and application logic. The platform supports widely used programming languages in quantitative finance, with official SDKs available for Python and R, which are detailed in the Portfolio Optimizer documentation. These SDKs abstract the underlying API calls, managing authentication, request formatting, and response handling.

The SDKs are built to align with typical development workflows in financial engineering and data science. For instance, the Python SDK integrates with common data science libraries, simplifying data preparation and post-processing. Similarly, the R SDK is structured to fit within R's ecosystem for statistical computing and visualization. Adherence to OpenAPI Specification principles in the API design contributes to the maintainability and consistent behavior of these client libraries, ensuring reliable interaction with the Portfolio Optimizer backend services. This approach aids developers in implementing complex financial models and deploying algorithmic trading strategies with reduced integration overhead.

Official SDKs by language

Portfolio Optimizer provides official SDKs for Python and R, reflecting the prevalence of these languages in quantitative finance and data analysis. These SDKs are maintained by Portfolio Optimizer to ensure compatibility with API updates and to offer a consistent developer experience across versions. Each SDK is designed to encapsulate the API's functionality, providing language-idiomatic interfaces for various endpoints, including those for mean-variance optimization, risk parity, and stress testing scenarios.

The following table summarizes the key characteristics of the official SDKs:

Language Package Name Installation Command Maturity
Python portfolio-optimizer-sdk pip install portfolio-optimizer-sdk Stable
R portfolio.optimizer.R install.packages("portfolio.optimizer.R") Stable

These packages are hosted on their respective official package repositories (PyPI for Python and CRAN for R), facilitating standard installation procedures. The SDKs are regularly updated to introduce new features, improve performance, and address any reported issues, with versioning following semantic versioning principles to manage compatibility. Developers are advised to consult the Portfolio Optimizer SDK documentation for the most current installation instructions and usage guides.

Installation

Installing the Portfolio Optimizer SDKs typically involves using the standard package managers for Python and R. These tools ensure that all necessary dependencies are resolved and installed correctly, preparing the environment for API interaction.

Python SDK Installation

To install the Python SDK, use pip, the Python package installer. It is recommended to use a virtual environment to manage project dependencies, preventing conflicts with other Python projects. Detailed instructions for setting up Python environments are available in the Python venv documentation.

# Create a virtual environment
python3 -m venv my_optimizer_env

# Activate the virtual environment
source my_optimizer_env/bin/activate # On Windows, use `my_optimizer_env\Scripts\activate`

# Install the Portfolio Optimizer Python SDK
pip install portfolio-optimizer-sdk

After installation, the SDK can be imported into Python scripts or Jupyter notebooks. The SDK relies on standard Python libraries for HTTP requests and JSON processing, which are automatically handled by pip during installation.

R SDK Installation

For the R SDK, installation is performed using R's built-in package management functions. R packages are distributed through CRAN (Comprehensive R Archive Network).

# Install the Portfolio Optimizer R SDK
install.packages("portfolio.optimizer.R")

# Load the package into your R session
library(portfolio.optimizer.R)

The R SDK ensures compatibility with common data structures used in R, such as data frames, facilitating seamless integration into existing R-based analytical workflows. Dependencies specific to the R SDK are also managed automatically by the install.packages function.

Quickstart example

This quickstart demonstrates how to use the Portfolio Optimizer Python SDK to request a basic mean-variance optimized portfolio. The example assumes you have an API key, which is required for authentication with the Portfolio Optimizer API. You can obtain an API key by signing up for an account on the Portfolio Optimizer website.

Python Quickstart

First, ensure you have installed the Python SDK as described in the Installation section. This example calculates an efficient portfolio based on provided expected returns, volatilities, and a correlation matrix for a set of assets.

import os
from portfolio_optimizer_sdk import PortfolioOptimizerClient
from portfolio_optimizer_sdk.models import Asset, Constraints, PortfolioRequest

# Replace with your actual API Key or set as environment variable
API_KEY = os.environ.get("PORTFOLIO_OPTIMIZER_API_KEY", "YOUR_API_KEY_HERE")

# Initialize the client
client = PortfolioOptimizerClient(api_key=API_KEY)

# Define assets with their expected returns and volatilities
assets = [
    Asset(name="Asset A", expected_return=0.10, volatility=0.15),
    Asset(name="Asset B", expected_return=0.12, volatility=0.20),
    Asset(name="Asset C", expected_return=0.08, volatility=0.10),
]

# Define the correlation matrix (must be symmetric and positive semi-definite)
# Order corresponds to the 'assets' list: A, B, C
correlation_matrix = [
    [1.0, 0.6, 0.3],
    [0.6, 1.0, 0.4],
    [0.3, 0.4, 1.0],
]

# Define portfolio constraints (e.g., weights must sum to 1)
constraints = Constraints(minimum_weight=0.0, maximum_weight=1.0, total_weight=1.0)

# Create a portfolio request for mean-variance optimization
portfolio_request = PortfolioRequest(
    assets=assets,
    correlation_matrix=correlation_matrix,
    constraints=constraints,
    # Example: target a specific expected return for the efficient frontier
    target_expected_return=0.09
)

try:
    # Call the API to optimize the portfolio
    optimized_portfolio = client.optimize_portfolio(portfolio_request)

    print("Optimized Portfolio Weights:")
    for asset_name, weight in optimized_portfolio.weights.items():
        print(f"  {asset_name}: {weight:.4f}")
    print(f"Expected Portfolio Return: {optimized_portfolio.expected_return:.4f}")
    print(f"Portfolio Volatility: {optimized_portfolio.volatility:.4f}")

except Exception as e:
    print(f"An error occurred: {e}")

This example demonstrates a foundational optimization task. The optimize_portfolio method can accept various parameters to fine-tune the optimization process, such as different optimization objectives (e.g., minimum variance, maximum Sharpe ratio), transaction costs, and asset-specific constraints. For more advanced features and different optimization models, refer to the official API documentation.

R Quickstart

Similarly, the R SDK provides functions for interacting with the API. Here's an example demonstrating a portfolio optimization request in R:

# Load the Portfolio Optimizer R SDK
library(portfolio.optimizer.R)

# Replace with your actual API Key or set as environment variable
api_key <- Sys.getenv("PORTFOLIO_OPTIMIZER_API_KEY")
if (api_key == "") {
  stop("Please set the PORTFOLIO_OPTIMIZER_API_KEY environment variable.")
}

# Define assets as a data frame or list of lists
assets <- list(
  list(name = "Asset A", expected_return = 0.10, volatility = 0.15),
  list(name = "Asset B", expected_return = 0.12, volatility = 0.20),
  list(name = "Asset C", expected_return = 0.08, volatility = 0.10)
)

# Define the correlation matrix
correlation_matrix <- matrix(
  c(1.0, 0.6, 0.3,
    0.6, 1.0, 0.4,
    0.3, 0.4, 1.0),
  nrow = 3, byrow = TRUE
)

# Define constraints
constraints <- list(
  minimum_weight = 0.0,
  maximum_weight = 1.0,
  total_weight = 1.0
)

# Create the portfolio request payload
portfolio_request <- list(
  assets = assets,
  correlation_matrix = correlation_matrix,
  constraints = constraints,
  target_expected_return = 0.09
)

# Initialize the client and make the API call
response <- tryCatch({
  PortfolioOptimizerClient$new(api_key = api_key)$optimize_portfolio(portfolio_request)
}, error = function(e) {
  message("An error occurred: ", e$message)
  NULL
})

# Process the response
if (!is.null(response)) {
  cat("Optimized Portfolio Weights:\n")
  for (i in seq_along(response$weights)) {
    cat(sprintf("  %s: %.4f\n", names(response$weights)[i], response$weights[[i]]))
  }
  cat(sprintf("Expected Portfolio Return: %.4f\n", response$expected_return))
  cat(sprintf("Portfolio Volatility: %.4f\n", response$volatility))
} else {
  cat("Failed to retrieve optimized portfolio.\n")
}

This R example mirrors the Python functionality, demonstrating how to structure requests and handle responses within an R environment. The SDK handles the serialization and deserialization of data, allowing R users to work with native R data structures.

Community libraries

While Portfolio Optimizer maintains official SDKs for Python and R, the platform's adherence to standard REST API principles allows for the development of community-contributed libraries in other languages. These community efforts often arise from specific developer needs or preferences for languages not officially supported. As of 2026, the primary focus for SDK development remains on Python and R due to their strong adoption in quantitative finance. However, developers can always interact directly with the Portfolio Optimizer REST API using any HTTP client library in their preferred language. For example, JavaScript developers might use fetch or axios, while Go developers might use the standard library's net/http package. Community contributions, if they emerge, are typically hosted on platforms like GitHub and may not carry the same level of support or guarantee of compatibility as official SDKs.

Developers interested in contributing to or discovering community-driven projects related to Portfolio Optimizer are encouraged to monitor public code repositories and developer forums. Building a custom client involves managing API requests, handling authentication (typically with an API key), and parsing JSON responses, as outlined in general HTTP API client development best practices. While direct community libraries are less prevalent for Portfolio Optimizer compared to platforms with broader developer ecosystems, the robust API documentation ensures that developers have the necessary resources to build their own client integrations if needed.