Risk Free Interest Rate

Key Concepts

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, 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 method, call the SetRiskFreeInterestRateModel method.

// In Initialize
SetRiskFreeInterestRateModel(new ConstantRiskFreeRateInterestRateModel(0.02m));
# In Initialize
self.SetRiskFreeInterestRateModel(ConstantRiskFreeRateInterestRateModel(0.02))

To view all the pre-built risk free interest rate models, see Supported Models.

Default Behavior

The default risk free interest rate model is the InterestRateProvider, 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 GetInterestRate method. The GetInterestRate method returns the risk free interest rate for a given date.

// In the Initialize method, set the risk free interest rate model
SetRiskFreeInterestRateModel(new MyRiskFreeInterestRateModel());

// Define the custom risk free interest rate model
public class MyRiskFreeInterestRateModel : IRiskFreeInterestRateModel 
{
    public decimal GetInterestRate(DateTime date) 
    {
        return 0.02m;
    }
}
# In the Initialize method, set the risk free interest rate model
self.SetRiskFreeInterestRateModel(MyRiskFreeInterestRateModel())
    
# Define the custom risk free interest rate model
class MyRiskFreeInterestRateModel:
    def GetInterestRate(self, date: datetime) -> float:
        return 0.02

For a full example algorithm, see this backtestthis backtest.

Disable Interest Rates

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

SetRiskFreeInterestRateModel(new ConstantRiskFreeRateInterestRateModel(0));
self.SetRiskFreeInterestRateModel(ConstantRiskFreeRateInterestRateModel(0))

Get Interest Rate

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

var riskFreeInterestRate = RiskFreeInterestRateModel.GetInterestRate(Time);
risk_free_interest_rate = self.RiskFreeInterestRateModel.GetInterestRate(self.Time)

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

var avgRiskFreeInterestRate = RiskFreeInterestRateModel.GetRiskFreeRate(Time.AddDays(-30), Time);
avg_risk_free_interest_rate = RiskFreeInterestRateModelExtensions.GetRiskFreeRate(
    self.RiskFreeInterestRateModel, 
    self.Time-timedelta(7), self.Time
)

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

var avgRiskFreeInterestRate = RiskFreeInterestRateModel.GetAverageRiskFreeRate(
    new [] {Time, Time.AddDays(-180), Time.AddDays(-365)}
);
avg_risk_free_interest_rate = RiskFreeInterestRateModelExtensions.GetAverageRiskFreeRate(
    self.RiskFreeInterestRateModel, 
    [self.Time, self.Time-timedelta(180), self.Time-timedelta(365)]
)

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: