Browse Source

feat: started in mem ptf

pull/14/head
QuentinN42 1 year ago
parent
commit
a1582065c9
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 52
      auto_trading/ptf/in_memory.py

52
auto_trading/ptf/in_memory.py

@ -1,28 +1,30 @@
from ..interfaces import Portfolio
from typing import Dict
from pandas import DataFrame # type: ignore
class InMemoryPortfolio(Portfolio):
from ..interfaces import PTF, PTFState
from ..orders import Long, Short
class InMemoryPortfolio(PTF):
"""Just store the value in memory."""
def __init__(self, currency: dict) -> None:
"""Define the ptf with some starting currency"""
self.currency = currency
def content(self) -> dict:
"""return the content in each currency"""
return self.currency
def withdraw(self, amount: int, currency: str) -> None:
"""Withdraw money from the portfolio"""
if self.currency[currency] < amount:
raise ValueError("Not enough money")
self.currency[currency] -= amount
def deposit(self, amount: int, currency: str) -> None:
"""Deposit money into the portfolio"""
self.currency[currency] += amount
def convert(self, amount: int, to_amount: int, currency: str, to_currency: str) -> None:
"""Convert money from one currency to another"""
self.withdraw(amount, currency)
self.deposit(to_amount, to_currency)
_blanance: float
_stocks: Dict[str, float]
@property
def state(self):
return PTFState(
0,
self._stocks.copy(),
)
def execute_short(self, order: Short) -> None:
"""Sell actions."""
...
def execute_long(self, order: Long) -> None:
"""Buy actions."""
...
executors = {Short: execute_short, Long: execute_long}

Loading…
Cancel
Save