Spaces:
Sleeping
Sleeping
Download factory.py from janggi3/agent_system: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/spaces/janggi3/agent_system/resolve/main/factory.py
- Command line
-
hf download hf://spaces/janggi3/agent_system/factory.py
-
curl -L -o factory.py https://huggingface.co/spaces/janggi3/agent_system/resolve/main/factory.py
2.55 kB
| # file: agent_system/factory.py | |
| """import numpy as np | |
| from core import Force, AssetAllocation | |
| def generate_synthetic_forces(num=10, days=365): | |
| forces = [] | |
| t = np.linspace(0, 20, days) # Timeline for signal generation | |
| for i in range(num): | |
| # Determine the "Personality" of the Force | |
| # Even indices are Momentum, Odd are Mean Reversion | |
| if i % 2 == 0: | |
| name = f"Trend_Follower_{i}" | |
| tags = {"momentum", "aggressive", "long"} | |
| # Signal: Follows a smoothed version of a sine wave (Trend) | |
| ret_signal = np.sin(t * 0.5) + np.random.normal(0, 0.2, days) | |
| # Allocation: Pure BTC Long | |
| alloc = AssetAllocation({"BTC": 1.0, "ETH": 0.0, "USDT": 0.0}) | |
| else: | |
| name = f"Contrarian_Hedge_{i}" | |
| tags = {"mean_reversion", "defensive", "short"} | |
| # Signal: Random noise that reverts to zero | |
| ret_signal = np.random.normal(0, 0.5, days) | |
| # Allocation: ETH Short vs USDT | |
| alloc = AssetAllocation({"BTC": 0.0, "ETH": -0.5, "USDT": 1.5}) | |
| forces.append(Force( | |
| id=f"f_{i}", | |
| name=name, | |
| tags=tags, | |
| allocation=alloc, | |
| returns_history=ret_signal | |
| )) | |
| return forces""" | |
| # file: agent_system/factory.py | |
| import numpy as np | |
| from core import Force, AssetAllocation | |
| def generate_synthetic_forces(n=10): | |
| """ | |
| Generates a set of diverse strategies (Forces). | |
| Including the new 'Short Seller' force for bear market survival. | |
| """ | |
| forces = [] | |
| # 1. THE SHORT SELLER (New: Profits from 2022-style crashes) | |
| forces.append(Force( | |
| id="f_short_btc", | |
| name="Inverse BTC", | |
| tags={"defensive", "short", "bear_trend"}, | |
| allocation=AssetAllocation({"BTC": -1.0}), # -100% exposure | |
| returns_history=np.zeros(10) | |
| )) | |
| # 2. THE MOMENTUM LONG (Profits from 2021/2024 bulls) | |
| forces.append(Force( | |
| id="f_long_btc", | |
| name="Aggressive Long BTC", | |
| tags={"momentum", "aggressive", "bull_trend"}, | |
| allocation=AssetAllocation({"BTC": 1.0}), | |
| returns_history=np.zeros(10) | |
| )) | |
| # 3. THE CASH RESERVE (Neutral) | |
| forces.append(Force( | |
| id="f_cash", | |
| name="USDT Reserve", | |
| tags={"safe", "stable"}, | |
| allocation=AssetAllocation({}), # 0% exposure to volatile assets | |
| returns_history=np.zeros(10) | |
| )) | |
| # ... Add more synthetic or specialized forces as needed ... | |
| return forces | |