Browse Source

feat: backtest

pull/14/head
QuentinN42 1 year ago
parent
commit
81c0df277c
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 0
      auto_trading/broker/__init__.py
  2. 22
      auto_trading/broker/backtest.py
  3. 6
      auto_trading/interfaces.py

0
auto_trading/broker/__init__.py

22
auto_trading/broker/backtest.py

@ -0,0 +1,22 @@
import pandas as pd
from ..interfaces import Broker
class Backtest(Broker):
"""
Backtest Broker
"""
def __init__(self, f_name: str) -> None:
"""Read the csv file and store it into a dataframe"""
self.data = pd.read_csv(f_name)
self.curcor = -1
def __bool__(self):
return self.curcor < len(self.data)
def next(self):
"""Return the next row of the dataframe"""
self.curcor += 1
return self.data.iloc[:self.curcor]

6
auto_trading/interfaces.py

@ -3,6 +3,8 @@
"""
from abc import ABC, abstractmethod
import pandas as pd
class Portfolio(ABC):
"""How may of each money do I have ?"""
@ -40,7 +42,7 @@ class Broker(ABC):
"""Return True if the broker has data to retrive"""
@abstractmethod
def next(self) -> dict:
def next(self) -> pd.DataFrame:
"""Return the next data to process"""
@ -48,5 +50,5 @@ class Predictor(ABC):
"""What is the future ?"""
@abstractmethod
def predict(self, data: dict) -> dict:
def predict(self, data: pd.DataFrame) -> dict:
"""Return the prediction"""

Loading…
Cancel
Save