# Features
(*features*)

## Overview

### Available Operations

* [getTree](#gettree) - Provide the tree structure of the features faceting panel
* [list](#list) - List available features
* [getHistoricalValues](#gethistoricalvalues) - Get historical values for a feature
* [getTransformedValues](#gettransformedvalues) - Get the historical values for a feature transformed via the specified transformation
* [getWeightedIndex](#getweightedindex) - Returns the values of a user-definable index by creating a linear combination of features

## getTree

Provide the organization of a search tree over the features organization

### Example Usage

<!-- UsageSnippet language="typescript" operationID="get_features_tree" method="get" path="/v1/features_tree" -->
```typescript
import { Hedgewise } from "hedgewise";

const hedgewise = new Hedgewise({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const result = await hedgewise.features.getTree();

  console.log(result);
}

run();
```

### Standalone function

The standalone function version of this method:

```typescript
import { HedgewiseCore } from "hedgewise/core.js";
import { featuresGetTree } from "hedgewise/funcs/featuresGetTree.js";

// Use `HedgewiseCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const hedgewise = new HedgewiseCore({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await featuresGetTree(hedgewise);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("featuresGetTree failed:", res.error);
  }
}

run();
```

### Parameters

| Parameter                                                                                                                                                                      | Type                                                                                                                                                                           | Required                                                                                                                                                                       | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `options`                                                                                                                                                                      | RequestOptions                                                                                                                                                                 | :heavy_minus_sign:                                                                                                                                                             | Used to set various options for making HTTP requests.                                                                                                                          |
| `options.fetchOptions`                                                                                                                                                         | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)                                                                                        | :heavy_minus_sign:                                                                                                                                                             | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries`                                                                                                                                                              | [RetryConfig](../../lib/utils/retryconfig.md)                                                                                                                                  | :heavy_minus_sign:                                                                                                                                                             | Enables retrying HTTP requests under certain failure conditions.                                                                                                               |

### Response

**Promise\<[components.FeatureTreeModel](../../models/components/featuretreemodel.md)\>**

### Errors

| Error Type      | Status Code     | Content Type    |
| --------------- | --------------- | --------------- |
| errors.APIError | 4XX, 5XX        | \*/\*           |

## list

Returns the list of all available features that Hedgewise
        tracks or produces. Some of these are used to produce our price and
        commodity production forecasts. The returned features can be filtered by futures contract symbol they can relate or by the dataset they belong to.

### Example Usage

<!-- UsageSnippet language="typescript" operationID="get_available_features" method="get" path="/v1/features" -->
```typescript
import { Hedgewise } from "hedgewise";

const hedgewise = new Hedgewise({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const result = await hedgewise.features.list({
    symbols: [
      "ZC",
    ],
    datasetKeys: [
      "technical_macro_v1_2025",
    ],
    statisticTypes: [
      "raw_value",
    ],
    variableTypes: [
      "price",
    ],
    sources: [
      "CFTC",
    ],
    countries: [
      "usa",
    ],
    frequencies: [
      "daily",
    ],
    phenologyStages: [
      "harvest",
    ],
    limit: 761472,
    offset: 958645,
    search: "coffee",
  });

  console.log(result);
}

run();
```

### Standalone function

The standalone function version of this method:

```typescript
import { HedgewiseCore } from "hedgewise/core.js";
import { featuresList } from "hedgewise/funcs/featuresList.js";

// Use `HedgewiseCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const hedgewise = new HedgewiseCore({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await featuresList(hedgewise, {
    symbols: [
      "ZC",
    ],
    datasetKeys: [
      "technical_macro_v1_2025",
    ],
    statisticTypes: [
      "raw_value",
    ],
    variableTypes: [
      "price",
    ],
    sources: [
      "CFTC",
    ],
    countries: [
      "usa",
    ],
    frequencies: [
      "daily",
    ],
    phenologyStages: [
      "harvest",
    ],
    limit: 761472,
    offset: 958645,
    search: "coffee",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("featuresList failed:", res.error);
  }
}

run();
```

### Parameters

| Parameter                                                                                                                                                                      | Type                                                                                                                                                                           | Required                                                                                                                                                                       | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request`                                                                                                                                                                      | [operations.GetAvailableFeaturesRequest](../../models/operations/getavailablefeaturesrequest.md)                                                                               | :heavy_check_mark:                                                                                                                                                             | The request object to use for the request.                                                                                                                                     |
| `options`                                                                                                                                                                      | RequestOptions                                                                                                                                                                 | :heavy_minus_sign:                                                                                                                                                             | Used to set various options for making HTTP requests.                                                                                                                          |
| `options.fetchOptions`                                                                                                                                                         | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)                                                                                        | :heavy_minus_sign:                                                                                                                                                             | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries`                                                                                                                                                              | [RetryConfig](../../lib/utils/retryconfig.md)                                                                                                                                  | :heavy_minus_sign:                                                                                                                                                             | Enables retrying HTTP requests under certain failure conditions.                                                                                                               |

### Response

**Promise\<[components.GetAvailableFeaturesResponse](../../models/components/getavailablefeaturesresponse.md)\>**

### Errors

| Error Type                 | Status Code                | Content Type               |
| -------------------------- | -------------------------- | -------------------------- |
| errors.HTTPValidationError | 422                        | application/json           |
| errors.APIError            | 4XX, 5XX                   | \*/\*                      |

## getHistoricalValues

Returns historical values for a given feature code. The
        feature code is a unique identifier for a specific feature, such as
        weather or crop health data. Feature codes can be obtained with the
        `/v1/features` endpoint.

### Example Usage

<!-- UsageSnippet language="typescript" operationID="get_features_historical_values" method="get" path="/v1/features/historical/{feature_code}" -->
```typescript
import { Hedgewise } from "hedgewise";

const hedgewise = new Hedgewise({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const result = await hedgewise.features.getHistoricalValues({
    featureCode: "vietnam_t2mean",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
    addStrengthForCommodity: "KC",
    freq: "weekly",
    agg: "mean",
  });

  console.log(result);
}

run();
```

### Standalone function

The standalone function version of this method:

```typescript
import { HedgewiseCore } from "hedgewise/core.js";
import { featuresGetHistoricalValues } from "hedgewise/funcs/featuresGetHistoricalValues.js";

// Use `HedgewiseCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const hedgewise = new HedgewiseCore({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await featuresGetHistoricalValues(hedgewise, {
    featureCode: "vietnam_t2mean",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
    addStrengthForCommodity: "KC",
    freq: "weekly",
    agg: "mean",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("featuresGetHistoricalValues failed:", res.error);
  }
}

run();
```

### Parameters

| Parameter                                                                                                                                                                      | Type                                                                                                                                                                           | Required                                                                                                                                                                       | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request`                                                                                                                                                                      | [operations.GetFeaturesHistoricalValuesRequest](../../models/operations/getfeatureshistoricalvaluesrequest.md)                                                                 | :heavy_check_mark:                                                                                                                                                             | The request object to use for the request.                                                                                                                                     |
| `options`                                                                                                                                                                      | RequestOptions                                                                                                                                                                 | :heavy_minus_sign:                                                                                                                                                             | Used to set various options for making HTTP requests.                                                                                                                          |
| `options.fetchOptions`                                                                                                                                                         | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)                                                                                        | :heavy_minus_sign:                                                                                                                                                             | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries`                                                                                                                                                              | [RetryConfig](../../lib/utils/retryconfig.md)                                                                                                                                  | :heavy_minus_sign:                                                                                                                                                             | Enables retrying HTTP requests under certain failure conditions.                                                                                                               |

### Response

**Promise\<[components.GetFeatureHistoricalResponse](../../models/components/getfeaturehistoricalresponse.md)\>**

### Errors

| Error Type                 | Status Code                | Content Type               |
| -------------------------- | -------------------------- | -------------------------- |
| errors.HTTPValidationError | 422                        | application/json           |
| errors.APIError            | 4XX, 5XX                   | \*/\*                      |

## getTransformedValues

Provides a facility to apply transformation like computing the average of 5 years or 
        transpose the features time-series to create a year-on-year representation of the time-series
        of the features Feature codes can be obtained with the `/v1/features` endpoint.

### Example Usage

<!-- UsageSnippet language="typescript" operationID="get_transformed_feature_values" method="get" path="/v1/features/transform/{feature_code}" -->
```typescript
import { Hedgewise } from "hedgewise";

const hedgewise = new Hedgewise({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const result = await hedgewise.features.getTransformedValues({
    featureCode: "vietnam_t2mean",
    transform: "xyavg",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
    freq: "weekly",
    agg: "mean",
  });

  console.log(result);
}

run();
```

### Standalone function

The standalone function version of this method:

```typescript
import { HedgewiseCore } from "hedgewise/core.js";
import { featuresGetTransformedValues } from "hedgewise/funcs/featuresGetTransformedValues.js";

// Use `HedgewiseCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const hedgewise = new HedgewiseCore({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await featuresGetTransformedValues(hedgewise, {
    featureCode: "vietnam_t2mean",
    transform: "xyavg",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
    freq: "weekly",
    agg: "mean",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("featuresGetTransformedValues failed:", res.error);
  }
}

run();
```

### Parameters

| Parameter                                                                                                                                                                      | Type                                                                                                                                                                           | Required                                                                                                                                                                       | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request`                                                                                                                                                                      | [operations.GetTransformedFeatureValuesRequest](../../models/operations/gettransformedfeaturevaluesrequest.md)                                                                 | :heavy_check_mark:                                                                                                                                                             | The request object to use for the request.                                                                                                                                     |
| `options`                                                                                                                                                                      | RequestOptions                                                                                                                                                                 | :heavy_minus_sign:                                                                                                                                                             | Used to set various options for making HTTP requests.                                                                                                                          |
| `options.fetchOptions`                                                                                                                                                         | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)                                                                                        | :heavy_minus_sign:                                                                                                                                                             | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries`                                                                                                                                                              | [RetryConfig](../../lib/utils/retryconfig.md)                                                                                                                                  | :heavy_minus_sign:                                                                                                                                                             | Enables retrying HTTP requests under certain failure conditions.                                                                                                               |

### Response

**Promise\<[components.GetTransformedFeatureResponse](../../models/components/gettransformedfeatureresponse.md)\>**

### Errors

| Error Type                 | Status Code                | Content Type               |
| -------------------------- | -------------------------- | -------------------------- |
| errors.HTTPValidationError | 422                        | application/json           |
| errors.APIError            | 4XX, 5XX                   | \*/\*                      |

## getWeightedIndex

Provides a facility to create an index formed as a weighted basket of the list of features provided.
    The features provided must exist and listed as available at the `/v1/features` endpoint.

### Example Usage

<!-- UsageSnippet language="typescript" operationID="get_weighted_index" method="get" path="/v1/features/weighted_index/" -->
```typescript
import { Hedgewise } from "hedgewise";

const hedgewise = new Hedgewise({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const result = await hedgewise.features.getWeightedIndex({
    weights: [
      0.5,
    ],
    featureCodes: [
      "vietnam_t2mean",
    ],
    indexLabel: "user_defined_index",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
  });

  console.log(result);
}

run();
```

### Standalone function

The standalone function version of this method:

```typescript
import { HedgewiseCore } from "hedgewise/core.js";
import { featuresGetWeightedIndex } from "hedgewise/funcs/featuresGetWeightedIndex.js";

// Use `HedgewiseCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const hedgewise = new HedgewiseCore({
  serverURL: "https://api.example.com",
  bearerAuth: process.env["HEDGEWISE_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await featuresGetWeightedIndex(hedgewise, {
    weights: [
      0.5,
    ],
    featureCodes: [
      "vietnam_t2mean",
    ],
    indexLabel: "user_defined_index",
    startDate: "2025-03-24",
    endDate: "2025-04-25",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("featuresGetWeightedIndex failed:", res.error);
  }
}

run();
```

### Parameters

| Parameter                                                                                                                                                                      | Type                                                                                                                                                                           | Required                                                                                                                                                                       | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request`                                                                                                                                                                      | [operations.GetWeightedIndexRequest](../../models/operations/getweightedindexrequest.md)                                                                                       | :heavy_check_mark:                                                                                                                                                             | The request object to use for the request.                                                                                                                                     |
| `options`                                                                                                                                                                      | RequestOptions                                                                                                                                                                 | :heavy_minus_sign:                                                                                                                                                             | Used to set various options for making HTTP requests.                                                                                                                          |
| `options.fetchOptions`                                                                                                                                                         | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options)                                                                                        | :heavy_minus_sign:                                                                                                                                                             | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
| `options.retries`                                                                                                                                                              | [RetryConfig](../../lib/utils/retryconfig.md)                                                                                                                                  | :heavy_minus_sign:                                                                                                                                                             | Enables retrying HTTP requests under certain failure conditions.                                                                                                               |

### Response

**Promise\<[components.GetTransformedFeatureResponse](../../models/components/gettransformedfeatureresponse.md)\>**

### Errors

| Error Type                 | Status Code                | Content Type               |
| -------------------------- | -------------------------- | -------------------------- |
| errors.HTTPValidationError | 422                        | application/json           |
| errors.APIError            | 4XX, 5XX                   | \*/\*                      |