-
Notifications
You must be signed in to change notification settings - Fork 718
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
45 changed files
with
6,367 additions
and
0 deletions.
There are no files selected for viewing
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,77 @@ | ||
from typing import Dict, List, Optional | ||
|
||
from nautilus_trader.core.model import AccountType, LiquiditySide, OrderSide | ||
from nautilus_trader.model.events.account import AccountState | ||
from nautilus_trader.model.events.order import OrderFilled | ||
from nautilus_trader.model.identifiers import AccountId, InstrumentId | ||
from nautilus_trader.model.instruments.base import Instrument | ||
from nautilus_trader.model.objects import ( | ||
AccountBalance, | ||
Currency, | ||
Money, | ||
Price, | ||
Quantity, | ||
) | ||
from nautilus_trader.model.position import Position | ||
|
||
class Account: | ||
id: AccountId | ||
type: AccountType | ||
base_currency: Optional[Currency] | ||
is_cash_account: bool | ||
is_margin_account: bool | ||
calculate_account_state: bool | ||
|
||
def __init__(self, event: AccountState, calculate_account_state: bool) -> None: ... | ||
def __eq__(self, other: Account) -> bool: ... | ||
def __hash__(self) -> int: ... | ||
def __repr__(self) -> str: ... | ||
@property | ||
def last_event(self) -> AccountState: ... | ||
@property | ||
def events(self) -> List[AccountState]: ... | ||
@property | ||
def event_count(self) -> int: ... | ||
def currencies(self) -> List[Currency]: ... | ||
def starting_balances(self) -> Dict[Currency, Money]: ... | ||
def balances(self) -> Dict[Currency, AccountBalance]: ... | ||
def balances_total(self) -> Dict[Currency, Money]: ... | ||
def balances_free(self) -> Dict[Currency, Money]: ... | ||
def balances_locked(self) -> Dict[Currency, Money]: ... | ||
def commissions(self) -> Dict[Currency, Money]: ... | ||
def balance( | ||
self, currency: Optional[Currency] = None | ||
) -> Optional[AccountBalance]: ... | ||
def balance_total(self, currency: Optional[Currency] = None) -> Optional[Money]: ... | ||
def balance_free(self, currency: Optional[Currency] = None) -> Optional[Money]: ... | ||
def balance_locked( | ||
self, currency: Optional[Currency] = None | ||
) -> Optional[Money]: ... | ||
def commission(self, currency: Currency) -> Optional[Money]: ... | ||
def apply(self, event: AccountState) -> None: ... | ||
def update_balances( | ||
self, balances: List[AccountBalance], allow_zero: bool = True | ||
) -> None: ... | ||
def update_commissions(self, commission: Money) -> None: ... | ||
def is_unleveraged(self, instrument_id: InstrumentId) -> bool: ... | ||
def calculate_commission( | ||
self, | ||
instrument: Instrument, | ||
last_qty: Quantity, | ||
last_px: Price, | ||
liquidity_side: LiquiditySide, | ||
use_quote_for_inverse: bool = False, | ||
) -> Money: ... | ||
def calculate_pnls( | ||
self, | ||
instrument: Instrument, | ||
fill: OrderFilled, | ||
position: Optional[Position] = None, | ||
) -> List[Money]: ... | ||
def balance_impact( | ||
self, | ||
instrument: Instrument, | ||
quantity: Quantity, | ||
price: Price, | ||
order_side: OrderSide, | ||
) -> Money: ... |
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,112 @@ | ||
from datetime import datetime | ||
from decimal import Decimal | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
from nautilus_trader.backtest.results import BacktestResult | ||
from nautilus_trader.common.actor import Actor | ||
from nautilus_trader.common.component import Logger | ||
from nautilus_trader.config import BacktestEngineConfig | ||
from nautilus_trader.core.data import Data | ||
from nautilus_trader.core.uuid import UUID4 | ||
from nautilus_trader.execution.algorithm import ExecAlgorithm | ||
from nautilus_trader.model.enums import AccountType, OmsType | ||
from nautilus_trader.model.identifiers import ClientId, InstrumentId, Venue | ||
from nautilus_trader.model.instruments.base import Instrument | ||
from nautilus_trader.model.objects import Currency, Money | ||
from nautilus_trader.portfolio.base import PortfolioFacade | ||
from nautilus_trader.trading.strategy import Strategy | ||
from nautilus_trader.trading.trader import Trader | ||
|
||
class BacktestEngine: | ||
def __init__(self, config: Optional[BacktestEngineConfig] = None) -> None: ... | ||
@property | ||
def trader_id(self) -> str: ... | ||
@property | ||
def machine_id(self) -> str: ... | ||
@property | ||
def instance_id(self) -> UUID4: ... | ||
@property | ||
def kernel(self) -> Any: ... # NautilusKernel type | ||
@property | ||
def logger(self) -> Logger: ... | ||
@property | ||
def run_config_id(self) -> Optional[str]: ... | ||
@property | ||
def run_id(self) -> Optional[UUID4]: ... | ||
@property | ||
def iteration(self) -> int: ... | ||
@property | ||
def run_started(self) -> Optional[datetime]: ... | ||
@property | ||
def run_finished(self) -> Optional[datetime]: ... | ||
@property | ||
def backtest_start(self) -> Optional[datetime]: ... | ||
@property | ||
def backtest_end(self) -> Optional[datetime]: ... | ||
@property | ||
def trader(self) -> Trader: ... | ||
@property | ||
def cache(self) -> Any: ... # CacheFacade type | ||
@property | ||
def data(self) -> List[Data]: ... | ||
@property | ||
def portfolio(self) -> PortfolioFacade: ... | ||
def list_venues(self) -> List[Venue]: ... | ||
def add_venue( | ||
self, | ||
venue: Venue, | ||
oms_type: OmsType, | ||
account_type: AccountType, | ||
starting_balances: List[Money], | ||
base_currency: Optional[Currency] = None, | ||
default_leverage: Optional[Decimal] = None, | ||
leverages: Optional[Dict[InstrumentId, Decimal]] = None, | ||
modules: Optional[List[Any]] = None, # SimulationModule type | ||
fill_model: Optional[Any] = None, # FillModel type | ||
fee_model: Optional[Any] = None, # FeeModel type | ||
latency_model: Optional[Any] = None, # LatencyModel type | ||
book_type: str = "L1_MBP", | ||
routing: bool = False, | ||
frozen_account: bool = False, | ||
bar_execution: bool = True, | ||
reject_stop_orders: bool = True, | ||
support_gtd_orders: bool = True, | ||
support_contingent_orders: bool = True, | ||
use_position_ids: bool = True, | ||
use_random_ids: bool = False, | ||
use_reduce_only: bool = True, | ||
) -> None: ... | ||
def change_fill_model(self, venue: Venue, model: Any) -> None: ... # FillModel type | ||
def add_instrument(self, instrument: Instrument) -> None: ... | ||
def add_data( | ||
self, | ||
data: List[Data], | ||
client_id: Optional[ClientId] = None, | ||
validate: bool = True, | ||
sort: bool = True, | ||
) -> None: ... | ||
def dump_pickled_data(self) -> bytes: ... | ||
def load_pickled_data(self, data: bytes) -> None: ... | ||
def add_actor(self, actor: Actor) -> None: ... | ||
def add_actors(self, actors: List[Actor]) -> None: ... | ||
def add_strategy(self, strategy: Strategy) -> None: ... | ||
def add_strategies(self, strategies: List[Strategy]) -> None: ... | ||
def add_exec_algorithm(self, exec_algorithm: ExecAlgorithm) -> None: ... | ||
def add_exec_algorithms(self, exec_algorithms: List[ExecAlgorithm]) -> None: ... | ||
def reset(self) -> None: ... | ||
def clear_data(self) -> None: ... | ||
def clear_actors(self) -> None: ... | ||
def clear_strategies(self) -> None: ... | ||
def clear_exec_algorithms(self) -> None: ... | ||
def dispose(self) -> None: ... | ||
def run( | ||
self, | ||
start: Optional[Union[datetime, str, int]] = None, | ||
end: Optional[Union[datetime, str, int]] = None, | ||
run_config_id: Optional[str] = None, | ||
streaming: bool = False, | ||
) -> None: ... | ||
def end(self) -> None: ... | ||
def get_result(self) -> BacktestResult: ... | ||
|
||
__all__ = ["BacktestEngine", "BacktestEngineConfig"] |
Oops, something went wrong.