-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
features/autonomous_financial_planning/financial_planning_ai.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# File name: financial_planning_ai.py | ||
import gym | ||
import numpy as np | ||
from stable_baselines3 import PPO | ||
|
||
class FinancialPlanningAI: | ||
def __init__(self, env): | ||
self.env = env | ||
self.model = PPO('MlpPolicy', env, verbose=1) | ||
|
||
def train(self): | ||
self.model.learn(total_timesteps=10000) | ||
self.model.save("financial_planning_ai") | ||
|
||
def plan(self, state): | ||
action, _ = self.model.predict(state) | ||
return action | ||
|
||
env = gym.make('FinancialPlanningEnv-v0') | ||
financial_planning_ai = FinancialPlanningAI(env) | ||
financial_planning_ai.train() |