Skip to content

Commit

Permalink
adding ranges tracking to markets, and reporting to sim_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Feb 5, 2024
1 parent 744f9f2 commit b9eeabb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sharkfin/markets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class MockMarket(AbstractMarket):

prices = None
dividends = None
ranges = None

dividend_growth_rate = None
dividend_shock_std = None
Expand All @@ -191,6 +192,7 @@ def __init__(

self.prices = [self.default_sim_price]
self.dividends = [self.default_sim_price / self.price_to_dividend_ratio]
self.ranges = []

self.rng = rng if rng is not None else np.random.default_rng()

Expand All @@ -213,6 +215,7 @@ def run_market(self, seed=0, buy_sell=(0,0), run_args = None):
print('dividend: ' + str(new_dividend))

self.dividends.append(new_dividend)
self.ranges.append(new_price / 10) # entirely arbitrary value for now.

return new_price, new_dividend

Expand Down
11 changes: 10 additions & 1 deletion sharkfin/markets/ammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ClientRPCMarket(AbstractMarket):
rng = None

macro_price_field = None
range_field = None

def __init__(self,
seed=None,
Expand All @@ -34,7 +35,8 @@ def __init__(self,
dividend_std = 0.011988,
price_to_dividend_ratio = 60 / 0.05,
rng = None,
macro_price_field = None
macro_price_field = None,
range_field = None
):

# discounted future value, divided by days per quarter
Expand All @@ -51,6 +53,7 @@ def __init__(self,
self.latest_price = None
self.prices = [self.default_sim_price]
self.dividends = [self.default_sim_price / self.price_to_dividend_ratio]
self.ranges = []

self.rpc_queue_name = queue_name
self.rpc_host_name = host
Expand All @@ -59,6 +62,10 @@ def __init__(self,
if macro_price_field is not None \
else "ClosingPrice"

self.range_field = range_field \
if range_field is not None \
else "DailyRange"

self.init_rpc()

def _get_rpc_market_host(self):
Expand Down Expand Up @@ -142,13 +149,15 @@ def run_market(self, buy_sell=(0, 0), run_args = None):

self.latest_price = np.nan
self.prices.append(np.nan)
self.ranges.append(np.nan)

raise MarketFailureError(f"AMMPS Market Failure: {self.response['MarketState']}")

else:

self.latest_price = self.response[ self.macro_price_field ]
self.prices.append(float(self.response[ self.macro_price_field ]))
self.ranges.append(float(self.response[self.range_field]))

return self.latest_price, new_dividend

Expand Down
10 changes: 10 additions & 0 deletions sharkfin/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ def class_stat_column_to_dict(clabel):
}).dropna()
sim_stats["price_dividend_pearsonr"] = pd_df.corr()['p']['d']


sim_stats["ranges_mean"] = mean(self.market.ranges)
sim_stats["ranges_stdev"] = stdev(self.market.ranges)
sim_stats["ranges_min"] = min(self.market.ranges)
sim_stats["ranges_max"] = max(self.market.ranges)

ranges_zscore = stats.zscore(np.array(self.market.ranges))

sim_stats["ranges_zs_max"] = ranges_zscore.max()

return sim_stats


Expand Down

0 comments on commit b9eeabb

Please sign in to comment.