An event-driven backtesting system
Project description
AlphaGens
An agent-environment based backtesting framework.
Event-Driven backtesting
class BuyAndHold(BaseStrategy):
def __init__(self, engine, broker, account):
super().__init__(engine, broker, account)
def before_trading_end(self):
if self.current_date == self.trade_dates[0]:
self.account.order_target_pct_to(pd.Series(1, index=["000001"]))
quick start
class BuyAndHold(BaseAgent):
def __init__(self, data):
super().__init__(data)
self.i = -1
def take_action(self, state, date):
self.buffer.append(state)
self.i += 1
if self.i == 0:
target_positions = np.array([0.2 for i in range(5)])
return target_positions
else:
return NO_ACTION
while True:
try:
print(f"current date is {env.current_date}")
action = agent.take_action(state, env.current_date)
next_state, reward, truncated, terminated, info = env.step(action)
state = next_state
returns.append(reward)
except IndexError:
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
alphagens-0.5.5.tar.gz
(36.2 kB
view details)
Built Distribution
alphagens-0.5.5-py3-none-any.whl
(60.4 kB
view details)
File details
Details for the file alphagens-0.5.5.tar.gz
.
File metadata
- Download URL: alphagens-0.5.5.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5042211139f9f5313b7a7e84f55e7f485eb7e34f742922c481d62a121812c1f2 |
|
MD5 | 026f90713b1e0be76474bb28d992482a |
|
BLAKE2b-256 | 11d31eb82fd7500bcfb2902d1cb687b035b3baa5f2129caeac1462bcaad1c8b4 |
File details
Details for the file alphagens-0.5.5-py3-none-any.whl
.
File metadata
- Download URL: alphagens-0.5.5-py3-none-any.whl
- Upload date:
- Size: 60.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e822ed053f45f3adaf9ee52e5c360fc1ef25b0ce726f24dc21ab9700d387d06c |
|
MD5 | eca236bd1efdb9d78078e2135807c8ba |
|
BLAKE2b-256 | 16411811d7da4bcc69d9ca71a578a711b5124573abead8116547cb7bf137cfb7 |