Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions alloc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
from datetime import datetime, timedelta
from pathlib import Path
from typing import Any, Callable
from typing import Any, Callable, cast

import numpy as np

Expand All @@ -31,7 +31,7 @@
# ---------------------------------------------------------------------------


def serialize_results(results: dict[str, Any]) -> dict[str, Any]:
def serialize_results(results: Any) -> Any:
"""Recursively convert numpy arrays to Python lists for JSON serialisation.

Parameters
Expand Down Expand Up @@ -123,7 +123,7 @@ def load_results(path: str, mode: str = "backtest") -> dict[str, Any]:
raise FileNotFoundError(f"Results file not found: {filepath}")

with open(filepath) as fh:
return json.load(fh)
return cast(dict[str, Any], json.load(fh))


# ---------------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions alloc/models/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging
import random
from collections import deque
from typing import Optional
from typing import Any, Optional

import numpy as np
import tensorflow as tf
Expand Down Expand Up @@ -194,14 +194,14 @@ class CashLayer(layers.Layer):
Passed to :class:`keras.layers.Layer`.
"""

def __init__(self, min_cash: float = 0.0, **kwargs):
def __init__(self, min_cash: float = 0.0, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.min_cash = float(min_cash)

def call(self, allocations: tf.Tensor) -> tf.Tensor:
return _calculate_cash(allocations, self.min_cash)

def get_config(self):
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update({"min_cash": self.min_cash})
return config
Expand All @@ -219,14 +219,14 @@ class CashLambda(layers.Lambda):
Passed to :class:`keras.layers.Lambda`.
"""

def __init__(self, min_cash: float = 0.0, **kwargs):
def __init__(self, min_cash: float = 0.0, **kwargs: Any) -> None:
self._min_cash = float(min_cash)
super().__init__(
function=lambda x: _calculate_cash(x, self._min_cash),
**kwargs,
)

def get_config(self):
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update({"min_cash": self._min_cash})
return config
Expand Down Expand Up @@ -525,7 +525,7 @@ def get_allocation(
)
allocation = allocation / allocation.sum()

return allocation
return allocation.astype(np.float64)

# ------------------------------------------------------------------
# Action sampling
Expand Down Expand Up @@ -556,7 +556,7 @@ def _sample_action(
action = self.get_allocation(state, add_noise=explore, noise_scale=noise_scale)
# Clamp to [0, 1]
action = np.clip(action, 0.0, 1.0)
return action
return action.astype(np.float64)

# ------------------------------------------------------------------
# Training step methods
Expand Down
16 changes: 16 additions & 0 deletions tickets/TICKET-036.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TICKET-036: Add type annotations to core modules

**Module:** `alloc/core.py`, `alloc/lib/*.py`
**Priority:** Medium — improve type safety

## What to Implement

Run mypy in strict mode and add missing type hints:
1. `alloc/core.py` — SimulationRunner methods
2. `alloc/lib/cache.py` — DiskCache methods
3. `alloc/lib/client.py` — PolygonClient methods

## Verification

- mypy alloc/ --ignore-missing-imports passes
- All tests pass
Loading