Files
quantconnect--lean/Algorithm.Python/FuncRiskFreeRateInterestRateModelWithPythonLambda.py
T
Ricardo Andrés Marino Rojas bc313a999b
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Add PyObject Constructor Overload for FuncRiskFreeRateInterestRateModel (#7625)
* Add overload and regression tests

* Nit changes

* Nit change

* Nit change
2023-12-14 11:04:42 -03:00

32 lines
1.6 KiB
Python

# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from AlgorithmImports import *
### <summary>
### Asserts we can use a Python lambda function as a FuncRiskFreeRateInterestRateModel
### </summary>
class FuncRiskFreeRateInterestRateModelWithPythonLambda(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 5, 28)
self.SetEndDate(2020, 6, 28)
self.AddEquity("SPY", Resolution.Daily)
self.model = FuncRiskFreeRateInterestRateModel(lambda dt: 1 if dt.date != datetime(2020, 5, 28) else 0)
def OnData(self, slice):
if self.Time.date == datetime(2020, 5, 28) and self.model.GetInterestRate(self.Time) != 0:
raise Exception(f"Risk free interest rate should be 0, but was {self.model.GetInterestRate(self.Time)}")
elif self.Time.date != datetime(2020, 5, 28) and self.model.GetInterestRate(self.Time) != 1:
raise Exception(f"Risk free interest rate should be 1, but was {self.model.GetInterestRate(self.Time)}")