1 changed files with 27 additions and 25 deletions
@ -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…
Reference in new issue