curl --request POST \
--url https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"expected_returns": [
0.08,
0.12,
0.1,
0.15
],
"covariance_matrix": [
[
0.04,
0.006,
0.008,
0.01
],
[
0.006,
0.09,
0.012,
0.015
],
[
0.008,
0.012,
0.0625,
0.018
],
[
0.01,
0.015,
0.018,
0.16
]
],
"rf_rate": 0.03,
"min_weights": [
0,
0,
0,
0
],
"max_weights": [
0.5,
0.5,
0.5,
0.5
]
}
'import requests
url = "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe"
payload = {
"expected_returns": [0.08, 0.12, 0.1, 0.15],
"covariance_matrix": [[0.04, 0.006, 0.008, 0.01], [0.006, 0.09, 0.012, 0.015], [0.008, 0.012, 0.0625, 0.018], [0.01, 0.015, 0.018, 0.16]],
"rf_rate": 0.03,
"min_weights": [0, 0, 0, 0],
"max_weights": [0.5, 0.5, 0.5, 0.5]
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
expected_returns: [0.08, 0.12, 0.1, 0.15],
covariance_matrix: [
[0.04, 0.006, 0.008, 0.01],
[0.006, 0.09, 0.012, 0.015],
[0.008, 0.012, 0.0625, 0.018],
[0.01, 0.015, 0.018, 0.16]
],
rf_rate: 0.03,
min_weights: [0, 0, 0, 0],
max_weights: [0.5, 0.5, 0.5, 0.5]
})
};
fetch('https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'expected_returns' => [
0.08,
0.12,
0.1,
0.15
],
'covariance_matrix' => [
[
0.04,
0.006,
0.008,
0.01
],
[
0.006,
0.09,
0.012,
0.015
],
[
0.008,
0.012,
0.0625,
0.018
],
[
0.01,
0.015,
0.018,
0.16
]
],
'rf_rate' => 0.03,
'min_weights' => [
0,
0,
0,
0
],
'max_weights' => [
0.5,
0.5,
0.5,
0.5
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe"
payload := strings.NewReader("{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"weights": [
0.25,
0.35,
0.3,
0.1
],
"expected_return": 0.1125,
"volatility": 0.2156,
"sharpe_ratio": 0.3826
}
}{
"detail": "Invalid API key"
}{
"detail": "Insufficient credits. This endpoint requires 5 credits."
}{
"detail": [
{
"loc": [
"body",
"expected_returns"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}Maximum Sharpe Ratio Portfolio
Constructs the maximum Sharpe ratio portfolio, also known as the tangency portfolio. This portfolio maximizes risk-adjusted returns and represents the optimal risky portfolio in mean-variance theory.
Use Cases:
- Constructing the optimal risky portfolio for two-fund separation
- Maximizing risk-adjusted returns in active management
- Identifying the market portfolio in CAPM framework
- Benchmark for performance evaluation
Mathematical Background: Maximizes: (R_p - R_f) / σ_p Subject to: Σw_i = 1, and optional constraints
Where R_p is portfolio return, R_f is risk-free rate, and σ_p is portfolio volatility.
Credits: 5 per request [Tier: PRO, Credits: 5]
curl --request POST \
--url https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"expected_returns": [
0.08,
0.12,
0.1,
0.15
],
"covariance_matrix": [
[
0.04,
0.006,
0.008,
0.01
],
[
0.006,
0.09,
0.012,
0.015
],
[
0.008,
0.012,
0.0625,
0.018
],
[
0.01,
0.015,
0.018,
0.16
]
],
"rf_rate": 0.03,
"min_weights": [
0,
0,
0,
0
],
"max_weights": [
0.5,
0.5,
0.5,
0.5
]
}
'import requests
url = "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe"
payload = {
"expected_returns": [0.08, 0.12, 0.1, 0.15],
"covariance_matrix": [[0.04, 0.006, 0.008, 0.01], [0.006, 0.09, 0.012, 0.015], [0.008, 0.012, 0.0625, 0.018], [0.01, 0.015, 0.018, 0.16]],
"rf_rate": 0.03,
"min_weights": [0, 0, 0, 0],
"max_weights": [0.5, 0.5, 0.5, 0.5]
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
expected_returns: [0.08, 0.12, 0.1, 0.15],
covariance_matrix: [
[0.04, 0.006, 0.008, 0.01],
[0.006, 0.09, 0.012, 0.015],
[0.008, 0.012, 0.0625, 0.018],
[0.01, 0.015, 0.018, 0.16]
],
rf_rate: 0.03,
min_weights: [0, 0, 0, 0],
max_weights: [0.5, 0.5, 0.5, 0.5]
})
};
fetch('https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'expected_returns' => [
0.08,
0.12,
0.1,
0.15
],
'covariance_matrix' => [
[
0.04,
0.006,
0.008,
0.01
],
[
0.006,
0.09,
0.012,
0.015
],
[
0.008,
0.012,
0.0625,
0.018
],
[
0.01,
0.015,
0.018,
0.16
]
],
'rf_rate' => 0.03,
'min_weights' => [
0,
0,
0,
0
],
'max_weights' => [
0.5,
0.5,
0.5,
0.5
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe"
payload := strings.NewReader("{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fincept.in/quantlib/portfolio/optimize/max-sharpe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expected_returns\": [\n 0.08,\n 0.12,\n 0.1,\n 0.15\n ],\n \"covariance_matrix\": [\n [\n 0.04,\n 0.006,\n 0.008,\n 0.01\n ],\n [\n 0.006,\n 0.09,\n 0.012,\n 0.015\n ],\n [\n 0.008,\n 0.012,\n 0.0625,\n 0.018\n ],\n [\n 0.01,\n 0.015,\n 0.018,\n 0.16\n ]\n ],\n \"rf_rate\": 0.03,\n \"min_weights\": [\n 0,\n 0,\n 0,\n 0\n ],\n \"max_weights\": [\n 0.5,\n 0.5,\n 0.5,\n 0.5\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"weights": [
0.25,
0.35,
0.3,
0.1
],
"expected_return": 0.1125,
"volatility": 0.2156,
"sharpe_ratio": 0.3826
}
}{
"detail": "Invalid API key"
}{
"detail": "Insufficient credits. This endpoint requires 5 credits."
}{
"detail": [
{
"loc": [
"body",
"expected_returns"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}Authorizations
API key for authentication. Get your key at https://api.fincept.in/auth/register
Body
Expected returns for each asset (annualized)
[0.08, 0.12, 0.1, 0.15]
Asset covariance matrix (annualized)
[
[0.04, 0.006, 0.008, 0.01],
[0.006, 0.09, 0.012, 0.015],
[0.008, 0.012, 0.0625, 0.018],
[0.01, 0.015, 0.018, 0.16]
]
Risk-free rate (annualized). Critical for Sharpe ratio calculation.
0.03
Minimum weight constraints for each asset
[0, 0, 0, 0]
Maximum weight constraints for each asset
[0.5, 0.5, 0.5, 0.5]
