mirror of
https://github.com/wassname/options_backtester.git
synced 2026-06-27 17:31:05 +08:00
Removed unnecessary asserts
This commit is contained in:
@@ -12,8 +12,6 @@ from .strategy import Strategy
|
||||
class Backtest:
|
||||
"""Backtest runner class."""
|
||||
def __init__(self, allocation, initial_capital=1_000_000, shares_per_contract=100):
|
||||
assert isinstance(allocation, dict)
|
||||
|
||||
assets = ('stocks', 'options', 'cash')
|
||||
total_allocation = sum(allocation.get(a, 0.0) for a in assets)
|
||||
|
||||
@@ -35,7 +33,6 @@ class Backtest:
|
||||
|
||||
@stocks.setter
|
||||
def stocks(self, stocks):
|
||||
assert all(isinstance(stock, Stock) for stock in stocks), 'Invalid stocks'
|
||||
assert np.isclose(sum(stock.percentage for stock in stocks), 1.0,
|
||||
atol=0.000001), 'Stock percentages must sum to 1.0'
|
||||
self._stocks = list(stocks)
|
||||
@@ -47,7 +44,6 @@ class Backtest:
|
||||
|
||||
@options_strategy.setter
|
||||
def options_strategy(self, strat):
|
||||
assert isinstance(strat, Strategy)
|
||||
self._options_strategy = strat
|
||||
|
||||
@property
|
||||
@@ -56,7 +52,6 @@ class Backtest:
|
||||
|
||||
@stocks_data.setter
|
||||
def stocks_data(self, data):
|
||||
assert isinstance(data, TiingoData)
|
||||
self._stocks_schema = data.schema
|
||||
self._stocks_data = data
|
||||
|
||||
@@ -66,7 +61,6 @@ class Backtest:
|
||||
|
||||
@options_data.setter
|
||||
def options_data(self, data):
|
||||
assert isinstance(data, HistoricalOptionsData)
|
||||
self._options_schema = data.schema
|
||||
self._options_data = data
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ from .schema import Schema
|
||||
class HistoricalOptionsData:
|
||||
"""Historical Options Data container class."""
|
||||
def __init__(self, file, schema=None, **params):
|
||||
if schema:
|
||||
assert isinstance(schema, Schema)
|
||||
else:
|
||||
if schema is None:
|
||||
self.schema = HistoricalOptionsData.default_schema()
|
||||
|
||||
file_extension = os.path.splitext(file)[1]
|
||||
|
||||
@@ -6,9 +6,7 @@ import pandas as pd
|
||||
class TiingoData:
|
||||
"""Tiingo (stocks & indeces) Data container class."""
|
||||
def __init__(self, file, schema=None, **params):
|
||||
if schema:
|
||||
assert isinstance(schema, Schema)
|
||||
else:
|
||||
if schema is None:
|
||||
self.schema = TiingoData.default_schema()
|
||||
|
||||
file_extension = os.path.splitext(file)[1]
|
||||
|
||||
@@ -2,9 +2,6 @@ import math
|
||||
|
||||
import numpy as np
|
||||
|
||||
from ..datahandler import Schema
|
||||
from .strategy_leg import StrategyLeg
|
||||
|
||||
|
||||
class Strategy:
|
||||
"""Options strategy class.
|
||||
@@ -12,7 +9,6 @@ class Strategy:
|
||||
entry and exit conditions.
|
||||
"""
|
||||
def __init__(self, schema):
|
||||
assert isinstance(schema, Schema)
|
||||
self.schema = schema
|
||||
self.legs = []
|
||||
self.conditions = []
|
||||
@@ -20,7 +16,6 @@ class Strategy:
|
||||
|
||||
def add_leg(self, leg):
|
||||
"""Adds leg to the strategy"""
|
||||
assert isinstance(leg, StrategyLeg)
|
||||
assert self.schema == leg.schema
|
||||
leg.name = "leg_{}".format(len(self.legs) + 1)
|
||||
self.legs.append(leg)
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
from backtester.enums import Type, Direction
|
||||
from backtester.datahandler import Schema
|
||||
|
||||
|
||||
class StrategyLeg:
|
||||
"""Strategy Leg data class"""
|
||||
def __init__(self, name, schema, option_type=Type.CALL, direction=Direction.BUY):
|
||||
assert isinstance(schema, Schema)
|
||||
assert isinstance(option_type, Type)
|
||||
assert isinstance(direction, Direction)
|
||||
|
||||
self.name = name
|
||||
self.schema = schema
|
||||
self.type = option_type
|
||||
|
||||
Reference in New Issue
Block a user