Skip to content

turtle_quant_1.backtesting.models

turtle_quant_1.backtesting.models

Pydantic models for backtesting results.

PortfolioSummary

Bases: BaseModel

Pydantic model for portfolio summary.

PortfolioTransaction

Bases: BaseModel

Pydantic model for a single transaction.

TestCaseResponse

Bases: BaseModel

Pydantic model for backtesting test case response.

is_failed property

is_failed: bool

Check if the test case failed.

is_successful property

is_successful: bool

Check if the test case was successful.

summary_str property

summary_str: str

Get a formatted summary of the test case result.

from_failure classmethod

from_failure(
    test_case_name: str,
    test_case_description: str,
    error: Exception,
    execution_time: Optional[float] = None,
) -> TestCaseResponse

Create a failed test case response.

Source code in src/turtle_quant_1/backtesting/models.py
@classmethod
def from_failure(
    cls,
    test_case_name: str,
    test_case_description: str,
    error: Exception,
    execution_time: Optional[float] = None,
) -> "TestCaseResponse":
    """Create a failed test case response."""
    return cls(  # pyrefly: ignore[missing-argument]
        test_case_name=test_case_name,
        test_case_description=test_case_description,
        status=TestCaseStatus.FAILED,
        error_message=str(error),
        error_type=type(error).__name__,
        execution_time_seconds=execution_time,
    )

from_success classmethod

from_success(
    test_case_name: str,
    test_case_description: str,
    results: TestCaseResults,
    execution_time: Optional[float] = None,
) -> TestCaseResponse

Create a successful test case response.

Source code in src/turtle_quant_1/backtesting/models.py
@classmethod
def from_success(
    cls,
    test_case_name: str,
    test_case_description: str,
    results: TestCaseResults,
    execution_time: Optional[float] = None,
) -> "TestCaseResponse":
    """Create a successful test case response."""
    return cls(  # pyrefly: ignore[missing-argument]
        test_case_name=test_case_name,
        test_case_description=test_case_description,
        status=TestCaseStatus.PASSED,
        results=results,
        execution_time_seconds=execution_time,
    )

TestCaseResults

Bases: BaseModel

Pydantic model for backtesting results.

portfolio_summary_str property

portfolio_summary_str: str

Get a formatted summary of the portfolio.

return_summary_str property

return_summary_str: str

Get a formatted summary of returns.

transaction_summary_str property

transaction_summary_str: str

Get a formatted summary of transaction activity.

TestCaseStatus

Bases: str, Enum

Enumeration for test case execution status.