The indexing into performance results during the simulation loop fails
when emitting minutely since 'daily_perf' only exists on daily performance
results, not the minutely results.
Fix by making the key used to index into performance results depend
on the emission rate.
Intent is to both make the inputs to the treasury curve logic
more clear/explicit, as well as reducing the responsibilities
of the RiskMetrics classes.
Functions to move:
- search_day_distance
- get_treasury_rate
- choose_treasury
Also add new function:
- select_treasury_duration, split out of choose_treasury
So that calculations that leverage the range of the treasury_curves,
like `pd.Series.searchsorted` will not overshoot the 'end' of the
range we are calculating risk metrics.
The treasury_duration member in RiskMetrics is never used except
for in unit tests.
Remove the saving of treasury_duration in preparation for the
move of the choose_treasury method out of the RiskMetrics classes.
Down the line, if we do restore the sanving of treasury_duration,
choose_treasury can return a tuple that includes treasury_duration
instead of just returning the rate.
To make the risk metrics being calculated more clear, change the
naming convention that ratios have a '_risk' suffix.
Also, fixes typo in beta docstring.
Highlights:
- Benchmark updating now permits empty ranges.
(Fixes runtime crash when running immediately after Easter 2013.)
- Risk metrics
- Performance improvents from converting to numpy and pandas.
<@wesm, wesmckinn@gmail.com>
- Refactoring of risk metric calculation out of class structure.
On ranges with missing data from Yahoo, e.g.:
On 2013-04-2 the date range of April 2013-03-29 failed because
of the first day in the range being Good Friday, and the API not
yet updating for the Monday after.
Handle the 404 that is found by raising and warning that no
benchmark data was found, but continuing on.
In the test factory creation of returns, the date creation was using
a timedelta of one day instead of incrementing by trading days.
Working towards changing risk module behavior which would leverage
the trading day map, but tests fail because non-trading days are
created.
Remove `factory.create_returns`, moving uses of that function to us
`factory.create_returns_from_period`, since the number of days input
for `create_returns` was more difficult to use when specifying ranges
over arbirtray dates.
Move the risk metric definitions to functions at the module level
with defined parameters.
Both risk implementations call these functions, where the difference
between risk implementations is with which internal data they
send to the various risk metrics.
Metrics moved:
- Sharpe Ratio
- Sortino Ratio
- Information Ration
- Alpha
Following the lead of the RiskMetricsBatch conversion to use
more pandas and numpy.
Bringing the iterative and batch versions closer together as we
work towards folding them into one.
Handles the case when reword is called and the `commit --amend` invokes
the pre-commit hook, when there is no stash the `git stash pop -q`
in that case leaves the rebase in an odd state.
Fixes by only calling the stash pop if changes were saved.
So that the environments' exchange time is used without having to
specify it independently.
Also, moves uses of Delorean.shift for the exchange conversion inside
of environment to use the exchange_dt_to_utc method.
Wires up performance tracker so that when `emission_rate` is set
to `minute`, the performance packets are sent out every minute,
instead of once per day.
Please note, the performance packets that are generated are not
ready for prime time consumption, this patch is merely a step towards
hooking up the ability to inspect minute data.
Known issues:
- The packets do not currently include risk information.
Since we need to consider how this affects the denominators
of the risk calculations.
In preparation of changing how risk metrics are calculated,
this makes the checking of results more tolerant to floating point
rounding, since upcoming changes change the results by a neglible margin.
The pyandoc module throws an OSError of:
"No such file or directory",
when the underlying pandoc binary does not exist.
This error has caused confusion for numerous people during pip
installation.
pandoc is only needed on upload to PyPI to convert to ReST.
So, instead of doing a try/except on the `import pandoc` for all cases,
now checking whether or not 'upload' was invoked when calling setup.py,
so that only maintainers have to worry about installation of pandoc.
By only exercising the pandoc logic when
Converts the risk iterative and batch comparison tests to use
the trading environments next date, instead of just advancing by day,
so that the returns being passed into the RiskMetrics in the unit
test are using the same trading calendar as the internal checks for
trading days.
Fixes a case where empty return periods were being into
`calculate_period_returns`
Clearing the way for the pandas based optimization of the risk module.
So that a filter function can filter out sids on a 'static' source,
when the universe of sids changes.
e.g. when using fetch_csv with a changing universe of stocks.
So that Transaction object behavior is exercised, uses the Transaction
object in performance module tests instead of ndict.
Also, adds fields to the __init__ of Transaction, to make the
definition of the object more well defined.
This function is unused, and on the general path of moving testing
functions out of gens.utils
# Please enter the commit message for your changes. Lines starting
Slight refactoring of grouping the tracking variables in the
PerformanceTracker together.
So that it's easier to see which are config members and which are
members used to track internal state.
Highlights, with thanks to contributors inline:
- Runtime performance improvements
- Fixed the omission of peformance messages on days with no trades
- Changes to batch_transform implementation
-- supports sid filtering
-- performance improvements using pandas
-- added an option for only computating when there is a window length's
worth of data
- Added new risk metrics
-- Sortino
-- information ration
(Ryan Day, ryanday2@gmail.com @rday)
- Added stop and limit orders
(Tony Worm, verdverm@gmail.com @verdverm)
- Added variable recording
- Deprecated market_aware and delta kwargs to EventWindow
- Fixes to trading calendars for missing holidays
- Added TradingEnviorment context manager
- Added support for streaming through dividends
- Yahoo source now has OHLC
- Updates downloaded benchmark and treasury data when new data is available.
(Ryan Day, ryanday2@gmail.com @rday)
- Added optional adjustment of Yahoo data
(Jeremiah Lowin, jlowin@lowindata.com @jlowin)