Skip to content

Commit

Permalink
Fixed delivery date. Renamed a few things in the results data.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbywater committed Oct 9, 2017
1 parent 3957f0b commit 3ebdbc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions quantdsl/application/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,17 @@ def read_results(self, evaluation):
simulated_price = self.simulated_price_repo[simulated_price_id]
simulated_price_value = simulated_price.value
else:
delivery_date = datetime.date(year, month, 1)
sum_simulated_prices = 0
count_simulated_prices = 0
for i in range(1, 32):
try:
delivery_date = datetime.date(year, month, i)
_delivery_date = datetime.date(year, month, i)
except ValueError:
continue
else:
simulated_price_id = make_simulated_price_id(
market_simulation.id, market_name, delivery_date, delivery_date
market_simulation.id, market_name, _delivery_date, _delivery_date
)
try:
simulated_price = self.simulated_price_repo[simulated_price_id]
Expand Down Expand Up @@ -378,7 +379,6 @@ def __init__(self, fair_value, periods):

self.deltas = {p['perturbation_name']: p['delta'] for p in self.periods}


@property
def fair_value_mean(self):
if isinstance(self.fair_value, scipy.ndarray):
Expand Down
13 changes: 7 additions & 6 deletions quantdsl/interfaces/calcandplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ def print_results(results, path_count):
net_cash_in = 0
net_hedge_units = defaultdict(int)
for period in results.periods:
perturbation_name = period['perturbation_name']
market_name = period['market']
delivery_date = period['delivery_date']
print(market_name, delivery_date)
# delivery_date = period['delivery_date']
print(perturbation_name)
print("Price: {:.2f}".format(period['price'].mean()))
hedge_units = period['hedge_units']
hedge_units_mean = hedge_units.mean()
Expand Down Expand Up @@ -453,7 +454,7 @@ def print_results(results, path_count):
def plot_periods(periods, title, periodisation, interest_rate, path_count, perturbation_factor):
from matplotlib import dates as mdates, pylab as plt

names = set([p['commodity'].split('-')[0] for p in periods])
names = set([p['market'] for p in periods])

f, subplots = plt.subplots(1 + 2 * len(names), sharex=True)
f.canvas.set_window_title(title)
Expand All @@ -476,9 +477,9 @@ def plot_periods(periods, title, periodisation, interest_rate, path_count, pertu
MEAN_COLOUR = '0.1'
for i, name in enumerate(names):

_periods = [p for p in periods if p['commodity'].startswith(name)]
_periods = [p for p in periods if p['market'] == name]

dates = [p['date'] for p in _periods]
dates = [p['delivery_date'] for p in _periods]
price_plot = subplots[i]

prices_mean = [p['price'].mean() for p in _periods]
Expand Down Expand Up @@ -556,7 +557,7 @@ def plot_periods(periods, title, periodisation, interest_rate, path_count, pertu

dates = []
for period in periods:
date = period['date']
date = period['delivery_date']
if date not in dates:
dates.append(date)
cash_in_by_date[date].append(period['cash_in'])
Expand Down

0 comments on commit 3ebdbc9

Please sign in to comment.