-
Notifications
You must be signed in to change notification settings - Fork 834
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
Rob Carver
committed
Mar 19, 2024
1 parent
eaa9542
commit 69b90ae
Showing
6 changed files
with
146 additions
and
32 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
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
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
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,33 @@ | ||
from sysdata.data_blob import dataBlob | ||
|
||
from syscore.constants import arg_not_supplied | ||
from sysproduction.reporting.reporting_functions import body_text | ||
from sysproduction.reporting.api import reportingApi | ||
|
||
REPORT_TEXT = body_text( | ||
"Commissions report, columns are commissions from configuration, broker, and ratio:\n" | ||
) | ||
|
||
|
||
def commissions_report( | ||
data: dataBlob = arg_not_supplied, | ||
): | ||
if data is arg_not_supplied: | ||
data = dataBlob() | ||
|
||
reporting_api = reportingApi( | ||
data, | ||
) | ||
|
||
formatted_output = [] | ||
|
||
formatted_output.append(reporting_api.std_header("Commission report")) | ||
formatted_output.append(REPORT_TEXT) | ||
formatted_output.append(reporting_api.table_of_commissions()) | ||
formatted_output.append(reporting_api.footer()) | ||
|
||
return formatted_output | ||
|
||
|
||
if __name__ == "__main__": | ||
commissions_report() |
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 |
---|---|---|
@@ -1,31 +1,63 @@ | ||
from typing import List | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
from sysproduction.data.instruments import diagInstruments | ||
from sysproduction.data.broker import dataBroker | ||
from sysproduction.data.contracts import dataContracts | ||
from sysobjects.contracts import futuresContract | ||
from sysdata.data_blob import dataBlob | ||
|
||
def df_of_configure_and_broker_block_cost(data) -> pd.DataFrame: | ||
configured = get_current_configured_block_costs(data) | ||
list_of_instruments = configured.index | ||
def df_of_configure_and_broker_block_cost_with_ratio_sorted(data: dataBlob) -> pd.DataFrame: | ||
df = df_of_configure_and_broker_block_cost(data) | ||
ratio = df[BROKER_COLUMN] / df[CONFIGURED_COLUMN] | ||
df[RATIO_COLUMN] = ratio | ||
|
||
list_of_broker = get_broker_block_costs(list_of_instruments) | ||
df.sort_values(by=RATIO_COLUMN) | ||
|
||
return pd.concat([configured, list_of_broker], axis=1) | ||
return df | ||
|
||
def get_current_configured_block_costs(data) -> pd.Series: | ||
diag_instruments = diagInstruments(data) | ||
def df_of_configure_and_broker_block_cost(data: dataBlob) -> pd.DataFrame: | ||
configured = get_current_configured_block_costs(data) | ||
list_of_instrument_codes = configured.index | ||
list_of_broker = get_broker_block_costs(data=data, list_of_instrument_codes=list_of_instrument_codes) | ||
both = pd.concat([configured, list_of_broker], axis=1) | ||
both.columns = [CONFIGURED_COLUMN, BROKER_COLUMN] | ||
return both | ||
|
||
return diag_instruments.get_block_commissions_as_series() | ||
CONFIGURED_COLUMN = 'configured' | ||
BROKER_COLUMN = 'broker' | ||
RATIO_COLUMN = 'ratio' | ||
|
||
def get_broker_block_costs(list_of_instruments_codes: List[str]) ->pd.Series: | ||
db = dataBroker() | ||
dc = dataContracts() | ||
def get_current_configured_block_costs(data: dataBlob) -> pd.Series: | ||
diag_instruments = diagInstruments(data) | ||
|
||
list_of_priced_contracts = [futuresContract(instrument_code, dc.get_priced_contract_id(instrument_code)) for instrument_code in list_of_instruments_codes] | ||
return diag_instruments.get_block_commissions_as_series() | ||
|
||
return pd.Series( | ||
[db.get_commission_for_contract(contract) for contract in list_of_priced_contracts], | ||
index = list_of_instruments_codes | ||
) | ||
def get_broker_block_costs(data: dataBlob, list_of_instrument_codes: List[str]) ->pd.Series: | ||
priced_contracts = get_series_of_priced_contracts(data=data, list_of_instrument_codes=list_of_instrument_codes) | ||
block_costs = get_costs_given_priced_contracts(data=data, priced_contracts=priced_contracts) | ||
return pd.Series(block_costs) | ||
|
||
def get_series_of_priced_contracts(data: dataBlob, list_of_instrument_codes: List[str]) -> pd.Series: | ||
dc = dataContracts(data) | ||
list_of_priced_contracts = {} | ||
for instrument_code in list_of_instrument_codes: | ||
try: | ||
contract = futuresContract(instrument_code, dc.get_priced_contract_id(instrument_code)) | ||
except: | ||
continue | ||
list_of_priced_contracts[instrument_code] = contract | ||
return pd.Series(list_of_priced_contracts) | ||
|
||
def get_costs_given_priced_contracts(data: dataBlob, priced_contracts: pd.Series)-> pd.Series: | ||
db = dataBroker(data) | ||
block_costs = {} | ||
for instrument_code, contract in priced_contracts.items(): | ||
try: | ||
costs = db.get_commission_for_contract(contract) | ||
except: | ||
costs = np.nan | ||
block_costs[instrument_code] = costs | ||
return pd.Series(block_costs) |
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