---
title: "Key Concepts"
description: "Risk free interest rate models provide the interest rate data to your algorithms to enable statistics like Sharpe and Sortino ratios."
canonical: https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/risk-free-interest-rate/key-concepts
markdown: https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/risk-free-interest-rate/key-concepts.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/03%20Writing%20Algorithms/24%20Reality%20Modeling/10%20Risk%20Free%20Interest%20Rate/01%20Key%20Concepts
modified: 2026-10-30
index: https://www.quantconnect.com/llms.txt
---

# Key Concepts

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Writing Algorithms](https://www.quantconnect.com/docs/v2/writing-algorithms.md) > Reality Modeling > Risk Free Interest Rate > Key Concepts

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

The risk free interest rate is the hurdle rate for investments. If investors can get a rate of return with virtually no risk, an investment needs to offer the potential for a greater return to attract capital from rational investors. The risk free interest rate also impacts some [performance statistics](https://www.quantconnect.com/docs/v2/writing-algorithms/statistics/algorithm-statistics.md), like Sharpe and Sortino ratios. Risk free interest rate models provide the interest rate data to your algorithms to enable these calculations.

## Set Models

To set the risk free interest rate model, in the [Initialize](https://www.quantconnect.com/docs/v2/writing-algorithms/initialization.md) method, call the `set_risk_free_interest_rate_model` method.

```python
def initialize(self) -> None:
    # Set the interest rate model for accurate option IV/greeks and result metrics like Sharpe Ratio
    # You should set it according to the main currency of your trading Securities
    self.set_risk_free_interest_rate_model(ConstantRiskFreeRateInterestRateModel(0.02))
```

To view all the pre-built risk free interest rate models, see [Supported Models](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/risk-free-interest-rate/supported-models.md).

## Default Behavior

The default risk free interest rate model is the [InterestRateProvider](https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/risk-free-interest-rate/supported-models.md#04-Interest-Rate-Provider-Model), which provides the primary credit rate from the Federal Open Market Committee (FOMC).

## Model Structure

Risk free interest rate models must extend the `IRiskFreeInterestRateModel` interface. Extensions of the `IRiskFreeInterestRateModel` interface must implement a `get_interest_rate` method. The `get_interest_rate` method returns the risk free interest rate for a given date.

```python
class CustomRiskFreeInterestRateModelExampleAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        # Set the interest rate model for accurate option IV/greeks and result metrics like Sharpe Ratio
        # You should set it according to the main currency of your trading Securities
        self.set_risk_free_interest_rate_model(MyRiskFreeInterestRateModel())

# Define the custom risk free interest rate model
class MyRiskFreeInterestRateModel(IRiskFreeInterestRateModel):
    def get_interest_rate(self, date: datetime | date) -> float:
        return 0.02
```

## Disable Interest Rates

To disable the risk free interest rate, set the model to the `ConstantRiskFreeRateInterestRateModel` and set the risk free rate to zero.

```python
self.set_risk_free_interest_rate_model(ConstantRiskFreeRateInterestRateModel(0))
```

## Get Interest Rate

To get the risk free interest rate for a specific time, call the `get_interest_rate` method with the time.

```python
def on_data(self, slice: Slice) -> None:
	risk_free_interest_rate = self.risk_free_interest_rate_model.get_interest_rate(slice.time)
```

To get the average risk free interest rate for a window of time, call the `RiskFreeInterestRateModelExtensions.get_risk_free_rate` method with the model, the start date, and end date.

```python
def on_data(self, slice: Slice) -> None:
	avg_risk_free_interest_rate = RiskFreeInterestRateModelExtensions.get_risk_free_rate(
		self.risk_free_interest_rate_model,
		self.time-timedelta(7), self.time
	)
```

To get the average risk free interest rate for a set of dates, call the `RiskFreeInterestRateModelExtensions.get_average_risk_free_rate` method with the model and list of dates.

```python
def on_data(self, slice: Slice) -> None:
	avg_risk_free_interest_rate = RiskFreeInterestRateModelExtensions.get_average_risk_free_rate(
		self.risk_free_interest_rate_model,
		[self.time, self.time-timedelta(180), self.time-timedelta(365)]
	)
```

## Examples

The following examples demonstrate common practices for implementing a custom risk free interest rate model.

### Example 1: Fixed Rate

The following algorithm implements a custom risk free interest rate model with a fixed rate of 2%.

```python
class CustomFillModelAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100000)
        self.set_risk_free_interest_rate_model(MyRiskFreeInterestRateModel())
        self.add_equity('SPY', Resolution.DAILY)

    def on_data(self, data: Slice) -> None:
        if not self.portfolio.invested:
            self.set_holdings('SPY', 1)

class MyRiskFreeInterestRateModel:

    def get_interest_rate(self, date: datetime | date) -> float:
        return 0.02
```
