File size: 699 Bytes
d96a847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# file: agent_system/core.py
from dataclasses import dataclass
from typing import Dict, Set
import numpy as np

@dataclass
class AssetAllocation:
    weights: Dict[str, float]

@dataclass
class Force:
    id: str
    name: str
    tags: Set[str]
    allocation: AssetAllocation
    returns_history: np.ndarray
    
@dataclass
class Portfolio:
    def __init__(self, cash: float):
        self.cash = cash  # This is the USDT balance
        self.positions = {} # {Symbol: Quantity}
        self.total_value = cash

    def update(self, prices: Dict[str, float]):
        pos_val = sum(qty * prices.get(sym, 0) for sym, qty in self.positions.items())
        self.total_value = self.cash + pos_val