Skip to content

Commit 2325449

Browse files
author
todd
committed
Merge remote-tracking branch 'robcarver17/master' into missing-data-2
2 parents 69b6a0d + 30d512c commit 2325449

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

Diff for: sysbrokers/IB/client/ib_price_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from sysobjects.contracts import futuresContract
2525
from sysexecution.trade_qty import tradeQuantity
2626

27+
TIMEOUT_SECONDS_ON_HISTORICAL_DATA = 20
28+
2729

2830
class tickerWithBS(object):
2931
def __init__(self, ticker, BorS: str):
@@ -272,6 +274,7 @@ def _ib_get_historical_data_of_duration_and_barSize(
272274
whatToShow=whatToShow,
273275
useRTH=True,
274276
formatDate=2,
277+
timeout=TIMEOUT_SECONDS_ON_HISTORICAL_DATA,
275278
)
276279
df = util.df(bars)
277280

Diff for: sysproduction/data/capital.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from sysproduction.data.generic_production_data import productionDataLayerGeneric
1414

15+
from systems.accounts.from_returns import account_curve_from_returns
16+
1517

1618
class dataCapital(productionDataLayerGeneric):
1719
def _add_required_classes_to_data(self, data) -> dataBlob:
@@ -26,7 +28,7 @@ def db_capital_data(self) -> capitalData:
2628
## TOTAL CAPITAL...
2729

2830
def get_percentage_returns_as_account_curve(self) -> pd.DataFrame:
29-
return self.total_capital_calculator.get_percentage_returns_as_pd()
31+
return account_curve_from_returns(self.get_percentage_returns_as_pd())
3032

3133
def get_percentage_returns_as_pd(self) -> pd.DataFrame:
3234
return self.total_capital_calculator.get_percentage_returns_as_pd()

Diff for: systems/accounts/curves/account_curve_analysis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def _prepare_returns_data_for_t_test(
6868
return standardised_df_returns
6969

7070

71-
def get_system_level_results(system):
72-
acc = system.accounts.portfolio().percent
71+
def standard_statistics(account_curve: accountCurve):
72+
acc = account_curve.percent
7373
costs = acc.costs.ann_mean()
7474
print("Ann Mean %.1f" % acc.ann_mean())
7575
print("Gross ann mean %.1f" % acc.gross.ann_mean())

Diff for: systems/accounts/from_returns.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Functions to do calculations just from percentage returns
3+
"""
4+
from typing import Union
5+
import pandas as pd
6+
from systems.accounts.curves.account_curve import accountCurve
7+
8+
from syscore.constants import arg_not_supplied
9+
from systems.accounts.pandl_calculators.pandl_cash_costs import (
10+
pandlCalculationWithCashCostsAndFills,
11+
)
12+
13+
14+
def account_curve_from_returns(
15+
returns: pd.Series,
16+
costs: pd.Series = arg_not_supplied,
17+
capital: pd.Series = arg_not_supplied,
18+
):
19+
returns = returns.dropna()
20+
if costs is arg_not_supplied:
21+
costs = pd.Series(0.0, index=returns.index)
22+
23+
pandl_calculator = pandlCalculationWithCashCostsAndFillsFromReturns(
24+
price=returns.cumsum(),
25+
positions=pd.Series(1.0, index=returns.index),
26+
capital=capital,
27+
raw_costs=costs, # ignore warning, not used
28+
rolls_per_year=0,
29+
vol_normalise_currency_costs=False,
30+
)
31+
32+
account_curve = accountCurve(pandl_calculator)
33+
34+
return account_curve
35+
36+
37+
class pandlCalculationWithCashCostsAndFillsFromReturns(
38+
pandlCalculationWithCashCostsAndFills
39+
):
40+
def costs_pandl_in_points(self) -> pd.Series:
41+
return self._raw_costs # ignore warning

0 commit comments

Comments
 (0)