Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/calibration #22

Merged
merged 17 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed tests.
  • Loading branch information
johnbywater committed Oct 23, 2017
commit db2002bc14620400cad69434e2c07670414f2dee
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ The examples below use the library function `calc()` to evaluate Quant DSL sourc
methods of the `QuantDslApplication` mentioned above.

```python
from quantdsl.interfaces.calcandplot import calc
from quantdsl.calculate import calc
```

When called, the function `calc()` returns a results object, with an attribute `fair_value` that is the
Expand Down Expand Up @@ -933,18 +933,12 @@ gas = {
}
```

This example uses the library function `calc_print()` to calculate and then print results.

```python
from quantdsl.interfaces.calcandplot import calc_print
```

Because the `periodisation` argument is set to `'monthly'`, the deltas for each market in each month will be
calculated, and estimated risk neutral hedge positions will be printed for each market in each period, along
with the overall fair value.

```python
results = calc_print(
results = calc(
source_code=gas_storage,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down Expand Up @@ -1052,10 +1046,6 @@ with `path_count` of `1`.
The recommended hedge positions suggest injecting gas when
the price is low, and withdrawing when the price is high.

An alternative to `calc_print()` is the function in the same module
`calc_print_plot()` which will also plot the prices, positions, and
cash. You will need to install matplotlib to use `calc_print_plot()`.


### Gas fired power station

Expand Down Expand Up @@ -1164,7 +1154,7 @@ calculated, and estimated risk neutral hedge positions will be printed for each
with the overall fair value.

```python
results = calc_print(
results = calc(
source_code=power_plant,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down
7 changes: 6 additions & 1 deletion quantdsl/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def calc_contract_value(self, source_code, is_double_sided_deltas=True, periodis
valuation_result = self.app.get_result(contract_valuation)
periods = self.app.get_periods(contract_valuation)

return Results(valuation_result, periods, market_simulation.observation_date)
return Results(
valuation_result=valuation_result,
periods=periods,
contract_valuation=contract_valuation,
market_simulation=market_simulation
)

def calc_call_count(self, contract_specification_id):
return self.app.calc_call_count(contract_specification_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from quantdsl.interfaces.results import Results
from quantdsl.exceptions import CallLimitError
from quantdsl.interfaces.calcandplot import calc_print, calc
from quantdsl.calculate import calc


class TestCalcPrint(TestCase):
class TestCalc(TestCase):
def setUp(self):
assert_event_handlers_empty()

Expand All @@ -21,7 +21,7 @@ def test_periodisation_monthly(self):
GasStorage(Date('2011-6-1'), Date('2011-12-1'), 'GAS', 0, 0, 50000, TimeDelta('1m'), 1)
"""

results = calc_print(
results = calc(
source_code=source_code,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_periodisation_alltime(self):
GasStorage(Date('2011-6-1'), Date('2011-12-1'), 'GAS', 0, 0, 50000, TimeDelta('1m'), 1)
"""

results = calc_print(
results = calc(
source_code=source_code,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_periodisation_none(self):
GasStorage(Date('2011-6-1'), Date('2011-12-1'), 'GAS', 0, 0, 50000, TimeDelta('1m'), 1)
"""

results = calc_print(
results = calc(
source_code=source_code,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_timeout(self):
"""

with self.assertRaises(SystemExit):
calc_print(
calc(
source_code=source_code,
observation_date='2011-1-1',
interest_rate=2.5,
Expand All @@ -194,7 +194,7 @@ def test_dependency_graph_size_limit(self):
"""

with self.assertRaises(CallLimitError):
calc_print(
calc(
source_code=source_code,
observation_date='2011-1-1',
interest_rate=2.5,
Expand Down Expand Up @@ -239,22 +239,4 @@ def test_results_dataframes(self):
assert isinstance(results, Results)
# self.assertIsInstance(results.cash_mean, DataFrame)


import matplotlib.pyplot as plt
#
plt.ioff()

results.prices_mean.plot(title='Prices')

plt.pause(1)

results.hedges_mean.plot(title='Hedges')

plt.pause(1)

results.cash.plot(title='Cash')

plt.show()

# import matplotlib; import matplotlib.pyplot; print(matplotlib.backends.backend)

results.plot()
2 changes: 1 addition & 1 deletion quantdsl/tests/test_price_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test(self):


class TestHistoricalVolatility(unittest.TestCase):
def test(self):
def _test(self):
quotes = get_yahoo_data('GOOG', 30)
"Return the annualized stddev of daily log returns of `sym`."
vol_log_returns = historical_volatility_log_returns(quotes)
Expand Down