Skip to content

Commit

Permalink
[Del] remove trailing white space
Browse files Browse the repository at this point in the history
[Del] remove spaces in blank lines
  • Loading branch information
nanoric committed Aug 15, 2019
1 parent 85603bb commit 2505f78
Show file tree
Hide file tree
Showing 26 changed files with 3,117 additions and 3,119 deletions.
2 changes: 0 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ exclude = venv,build,__pycache__,__init__.py,ib,talib,uic
ignore =
E501 line too long, fixed by black
W503 line break before binary operator
W293 blank line contains whitespace
W291 trailing whitespace
2 changes: 1 addition & 1 deletion examples/simple_rpc/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestClient(RpcClient):
"""
Test RpcClient
Test RpcClient
"""

def __init__(self):
Expand Down
4,770 changes: 2,385 additions & 2,385 deletions vnpy/api/apex/fiddef.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions vnpy/api/rest/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def add_request(
"""
Add a new request.
:param method: GET, POST, PUT, DELETE, QUERY
:param path:
:param path:
:param callback: callback function if 2xx status, type: (dict, Request)
:param params: dict for query string
:param data: Http body. If it is a dict, it will be converted to form-data. Otherwise, it will be converted to bytes.
Expand Down Expand Up @@ -296,7 +296,7 @@ def request(
"""
Add a new request.
:param method: GET, POST, PUT, DELETE, QUERY
:param path:
:param path:
:param params: dict for query string
:param data: dict for body
:param headers: dict for headers
Expand Down
6 changes: 3 additions & 3 deletions vnpy/app/algo_trading/algos/dma_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DmaAlgo(AlgoTemplate):
"vt_symbol": "",
"direction": [Direction.LONG.value, Direction.SHORT.value],
"order_type": [
OrderType.MARKET.value,
OrderType.MARKET.value,
OrderType.LIMIT.value,
OrderType.STOP.value,
OrderType.FAK.value,
Expand Down Expand Up @@ -74,7 +74,7 @@ def on_tick(self, tick: TickData):
self.order_type,
self.offset
)

else:
self.vt_orderid = self.sell(
self.vt_symbol,
Expand All @@ -96,4 +96,4 @@ def on_order(self, order: OrderData):

def on_trade(self, trade: TradeData):
""""""
pass
pass
12 changes: 6 additions & 6 deletions vnpy/app/cta_backtester/ui/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,13 @@ def update_history(self, history: list):
def update_trades(self, trades: list):
""""""
trade_data = []

for trade in trades:
ix = self.dt_ix_map[trade.datetime]

scatter = {
"pos": (ix, trade.price),
"data": 1,
"pos": (ix, trade.price),
"data": 1,
"size": 14,
"pen": pg.mkPen((255, 255, 255))
}
Expand All @@ -1030,19 +1030,19 @@ def update_trades(self, trades: list):
else:
scatter["symbol"] = "t"
scatter["brush"] = pg.mkBrush((0, 0, 255))

trade_data.append(scatter)

self.trade_scatter.setData(trade_data)

def clear_data(self):
""""""
self.updated = False
self.chart.clear_all()

self.dt_ix_map.clear()
self.trade_scatter.clear()

def is_updated(self):
""""""
return self.updated
108 changes: 54 additions & 54 deletions vnpy/app/cta_strategy/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pandas import DataFrame
from deap import creator, base, tools, algorithms

from vnpy.trader.constant import (Direction, Offset, Exchange,
from vnpy.trader.constant import (Direction, Offset, Exchange,
Interval, Status)
from vnpy.trader.database import database_manager
from vnpy.trader.object import OrderData, TradeData, BarData, TickData
Expand Down Expand Up @@ -84,12 +84,12 @@ def generate_setting(self):
settings.append(setting)

return settings

def generate_setting_ga(self):
""""""
""""""
settings_ga = []
settings = self.generate_setting()
for d in settings:
settings = self.generate_setting()
for d in settings:
param = [tuple(i) for i in d.items()]
settings_ga.append(param)
return settings_ga
Expand Down Expand Up @@ -215,8 +215,8 @@ def load_data(self):
self.end = datetime.now()

if self.start >= self.end:
self.output("起始日期必须小于结束日期")
return
self.output("起始日期必须小于结束日期")
return

self.history_data.clear() # Clear previously loaded history data

Expand All @@ -230,7 +230,7 @@ def load_data(self):

while start < self.end:
end = min(end, self.end) # Make sure end time stays within set range

if self.mode == BacktestingMode.BAR:
data = load_bar_data(
self.symbol,
Expand All @@ -248,15 +248,15 @@ def load_data(self):
)

self.history_data.extend(data)

progress += progress_delta / total_delta
progress = min(progress, 1)
progress_bar = "#" * int(progress * 10)
self.output(f"加载进度:{progress_bar} [{progress:.0%}]")

start = end
end += progress_delta

self.output(f"历史数据加载完成,数据量:{len(self.history_data)}")

def run_backtesting(self):
Expand All @@ -271,7 +271,7 @@ def run_backtesting(self):
# Use the first [days] of history data for initializing strategy
day_count = 0
ix = 0

for ix, data in enumerate(self.history_data):
if self.datetime and data.datetime.day != self.datetime.day:
day_count += 1
Expand Down Expand Up @@ -339,8 +339,8 @@ def calculate_statistics(self, df: DataFrame = None, output=True):
# Check DataFrame input exterior
if df is None:
df = self.daily_df
# Check for init DataFrame

# Check for init DataFrame
if df is None:
# Set all statistics to 0 if no trade.
start_date = ""
Expand Down Expand Up @@ -484,11 +484,11 @@ def calculate_statistics(self, df: DataFrame = None, output=True):

def show_chart(self, df: DataFrame = None):
""""""
# Check DataFrame input exterior
# Check DataFrame input exterior
if df is None:
df = self.daily_df

# Check for init DataFrame
# Check for init DataFrame
if df is None:
return

Expand Down Expand Up @@ -580,7 +580,7 @@ def run_ga_optimization(self, optimization_setting: OptimizationSetting, populat
def generate_parameter():
""""""
return random.choice(settings)

def mutate_individual(individual, indpb):
""""""
size = len(individual)
Expand Down Expand Up @@ -620,24 +620,24 @@ def mutate_individual(individual, indpb):
ga_mode = self.mode

# Set up genetic algorithem
toolbox = base.Toolbox()
toolbox.register("individual", tools.initIterate, creator.Individual, generate_parameter)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", mutate_individual, indpb=1)
toolbox.register("evaluate", ga_optimize)
toolbox.register("select", tools.selNSGA2)
toolbox = base.Toolbox()
toolbox.register("individual", tools.initIterate, creator.Individual, generate_parameter)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", mutate_individual, indpb=1)
toolbox.register("evaluate", ga_optimize)
toolbox.register("select", tools.selNSGA2)

total_size = len(settings)
pop_size = population_size # number of individuals in each generation
lambda_ = pop_size # number of children to produce at each generation
mu = int(pop_size * 0.8) # number of individuals to select for the next generation

cxpb = 0.95 # probability that an offspring is produced by crossover
cxpb = 0.95 # probability that an offspring is produced by crossover
mutpb = 1 - cxpb # probability that an offspring is produced by mutation
ngen = ngen_size # number of generation
pop = toolbox.population(pop_size)

pop = toolbox.population(pop_size)
hof = tools.ParetoFront() # end result of pareto front

stats = tools.Statistics(lambda ind: ind.fitness.values)
Expand All @@ -662,30 +662,30 @@ def mutate_individual(individual, indpb):
start = time()

algorithms.eaMuPlusLambda(
pop,
toolbox,
mu,
lambda_,
cxpb,
mutpb,
ngen,
pop,
toolbox,
mu,
lambda_,
cxpb,
mutpb,
ngen,
stats,
halloffame=hof
)
)

end = time()
cost = int((end - start))

self.output(f"遗传算法优化完成,耗时{cost}秒")

# Return result list
results = []

for parameter_values in hof:
setting = dict(parameter_values)
target_value = ga_optimize(parameter_values)[0]
results.append((setting, target_value, {}))

return results

def update_daily_close(self, price: float):
Expand Down Expand Up @@ -743,14 +743,14 @@ def cross_limit_order(self):

# Check whether limit orders can be filled.
long_cross = (
order.direction == Direction.LONG
and order.price >= long_cross_price
order.direction == Direction.LONG
and order.price >= long_cross_price
and long_cross_price > 0
)

short_cross = (
order.direction == Direction.SHORT
and order.price <= short_cross_price
order.direction == Direction.SHORT
and order.price <= short_cross_price
and short_cross_price > 0
)

Expand Down Expand Up @@ -811,12 +811,12 @@ def cross_stop_order(self):
for stop_order in list(self.active_stop_orders.values()):
# Check whether stop order can be triggered.
long_cross = (
stop_order.direction == Direction.LONG
stop_order.direction == Direction.LONG
and stop_order.price <= long_cross_price
)

short_cross = (
stop_order.direction == Direction.SHORT
stop_order.direction == Direction.SHORT
and stop_order.price >= short_cross_price
)

Expand Down Expand Up @@ -911,10 +911,10 @@ def send_order(
return [vt_orderid]

def send_stop_order(
self,
direction: Direction,
offset: Offset,
price: float,
self,
direction: Direction,
offset: Offset,
price: float,
volume: float
):
""""""
Expand All @@ -936,15 +936,15 @@ def send_stop_order(
return stop_order.stop_orderid

def send_limit_order(
self,
self,
direction: Direction,
offset: Offset,
price: float,
price: float,
volume: float
):
""""""
self.limit_order_count += 1

order = OrderData(
symbol=self.symbol,
exchange=self.exchange,
Expand Down Expand Up @@ -1008,13 +1008,13 @@ def write_log(self, msg: str, strategy: CtaTemplate = None):
"""
msg = f"{self.datetime}\t{msg}"
self.logs.append(msg)

def send_email(self, msg: str, strategy: CtaTemplate = None):
"""
Send email to default receiver.
"""
pass

def sync_strategy_data(self, strategy: CtaTemplate):
"""
Sync strategy data into json file.
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def optimize(
Function for running in multiprocessing.pool
"""
engine = BacktestingEngine()

engine.set_parameters(
vt_symbol=vt_symbol,
interval=interval,
Expand Down
Loading

0 comments on commit 2505f78

Please sign in to comment.