Skip to content

Commit c8fafd6

Browse files
authored
Merge pull request #2 from bbcho/make_py
Make py
2 parents a497bc2 + 5c9715e commit c8fafd6

File tree

92 files changed

+5146
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5146
-1019
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.6, 3.7, 3.8]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install flake8 pytest
23+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
24+
- name: Lint with flake8
25+
run: |
26+
# stop the build if there are Python syntax errors or undefined names
27+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
28+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
29+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
30+
- name: Test with pytest
31+
env: # Or as an environment variable
32+
EIA: ${{ secrets.EIA }}
33+
QUANDL: ${{ secrets.QUANDL }}
34+
MS_USER: ${{ secrets.MS_USER }}
35+
MS_PASS: ${{ secrets.MS_PASS }}
36+
run: |
37+
pytest

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
.vscode/
55
.ipynb_checkpoints/
66

7-
/mytest/
7+
# saved data in pytest folder
8+
# pytest/*.json
89

910
# Byte-compiled / optimized / DLL files
1011
__pycache__/
@@ -55,4 +56,10 @@ coverage.xml
5556
*.pot
5657

5758
# Sphinx documentation
58-
docs/_build/
59+
docs/_build/
60+
61+
# conda env
62+
env/
63+
64+
# misc files
65+
*.ipynb

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: python
2+
python:
3+
- "3.6" # current default Python on Travis CI
4+
- "3.7"
5+
- "3.8"
6+
# command to install dependencies
7+
install:
8+
- pip install -r requirements.txt
9+
# command to run tests
10+
script:
11+
- pytest
12+
matrix:
13+
include:
14+
- name: "Python 3.8 on macOS 10.13"
15+
os: osx
16+
osx_image: xcode9.4 # Python 3.8 running on macOS 10.13
17+
language: shell # 'language: python' is an error on Travis CI macOS
18+
before_install:
19+
- python3 --version 3.8
20+
- pip3 install -U pip
21+
- pip3 install -U pytest
22+
- pip3 install codecov
23+
script: python3 -m pytest
24+
after_success: python 3 -m codecov
25+
# - name: "Python 3.8 on Windows"
26+
# os: windows # Windows 10.0.17134 N/A Build 17134
27+
# language: shell # 'language: python' is an error on Travis CI Windows
28+
# before_install:
29+
# - choco install python --version 3.8
30+
# - python --version
31+
# - python -m pip install --upgrade pip
32+
# - pip3 install --upgrade pytest
33+
# - pip3 install codecov
34+
# env: PATH=/c/Python38:/c/Python38/Scripts:$PATH

README.md

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,61 @@
11
# risktools
22

3-
Python wrapper for R library RTL found at https://github.com/risktoollib/RTL
3+
Python implementation of the R package RTL.
44

5-
NOTES:
6-
* Only works with rpy2 version >= 3.0. Verified working with version 3.2.6
7-
* All datetimes are given in UTC
8-
* Verified working for RTL version 0.1.1
5+
See CRAN for original R version
96

10-
Must have the following R libraries already installed on host machine:
7+
https://cran.r-project.org/web/packages/RTL/index.html
118

12-
* RTL
13-
* devtools
14-
* tidyverse
15-
* tidyquant
16-
* Quandl
9+
Purpose
1710

18-
And the following Python libaries:
11+
Purposely designed functions for trading, trading analytics and risk practitioners in Commodities and Finance.
12+
Build to support delivery of Finance classes from one of the co-authors of RTL at the Alberta School of Business.
1913

20-
* rpy2
21-
* pandas
22-
* numpy
23-
* tzlocal
14+
Features
15+
16+
Historical forward curves charting.
17+
18+
Calendars and expiry dates data objects for a wide range of commodity futures contracts.
19+
20+
roll_adjust to adjust continuous contracts returns for roll adjustments using expiries above.
21+
22+
Morningstar Marketplace API functions getPrice(), getPrices() and getCurve() using your own Morningstar credentials. Current feeds included:
23+
ICE_EuroFutures and ICE_EuroFutures_continuous.
24+
CME_NymexFutures_EOD and CME_NymexFutures_EOD_continuous.
25+
CME_NymexOptions_EOD.
26+
CME_CbotFuturesEOD and CME_CbotFuturesEOD_continuous.
27+
CME_Comex_FuturesSettlement_EOD and CME_Comex_FuturesSettlement_EOD_continuous.
28+
LME_AskBidPrices_Delayed.
29+
CME_CmeFutures_EOD and CME_CmeFutures_EOD_continuous.
30+
CME_STLCPC_Futures.
31+
ICE_NybotCoffeeSugarCocoaFutures and ICE_NybotCoffeeSugarCocoaFutures_continuous.
32+
Morningstar_FX_Forwards.
33+
… see ?getPrice for up to date selection and examples.
34+
35+
chart_zscore() supports seasonality adjusted analysis of residuals, particularly useful when dealing with commodity stocks and/or days demand time series with trends as well as non-constant variance across seasonal periods.
36+
37+
chart_eia_steo() and chart_eia_sd() return either a chart or dataframe of supply demand balances from the EIA.
38+
39+
chart_spreads() to generate specific contract spreads across years e.g. ULSD March/April. Requires Morningstar credentials.
40+
41+
swapInfo() returns all information required to price first line futures contract averaging swap or CMA physical trade, including a current month instrument with prior settlements.
42+
43+
Data Sets
44+
45+
Accessible via risktools.data.open_data(datsetname). Also use risktools.data.get_names() to get list of available data.
46+
47+
expiry_table: Historical and forward futures contract metadata.
48+
holidaysOil: Holiday calendars for ICE and NYMEX.
49+
tickers_eia: Mapping of EIA tickers to crude and refined products markets for building supply demand balances.
50+
usSwapIRDef: Data frame of definitions for instruments to build a curve for use with RQuantlib. Use getIRswapCurve() to extract the latest data from FRED and Morningstar.
51+
usSwapIR: Sample data set output of getIRswapCurve.
52+
usSwapCurves: Sample data set output of RQuantlib::DiscountCurve().
53+
cancrudeassays contains historical Canadian crude assays by batch from Crudemonitor. cancrudeassayssum is a summarised average assays version.
54+
crudeassaysXOM for all publicly available complete assays in Excel format from ExxonMobil
55+
crudeassaysBP for all publicly available complete assays in Excel format from BP
56+
eiaStocks: Sample data set of EIA.gov stocks for key commodiities.
57+
eiaStorageCap: EIA crude storage capacity by PADD.
58+
dflong and dfwide contain continuous futures prices sample data sets for Nymex (CL, HO, RB and NG contracts) and ICE Brent.
59+
crudepipelines and refineries contain GIS information in the North American crude space.
60+
61+
Usernames and password for API services are required.

TODO.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TODO
2+
3+
## Testing
4+
* finish testing module
5+
* figure out a way so that the prompt_beta results match RTL::promptBeta exactly.
6+
Issue is that both use a linear regression to determine the beta, but they're
7+
returning slightly different betas (on the order of 0.001). Need to determine if this is because of an error in my code or because of differences in implementation in linear regression models between R and Python.
8+
9+
## Enhancements
10+
* npv: remove need for live ir curve if using fixed yield. Just need to get maturities

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/build_instructions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sphinx-apidoc -f -o source ../src/risktools
2+
make html

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.function {
2+
border-bottom: 3px solid #d0d0d0;
3+
padding-bottom: 10px;
4+
padding-top: 10px;
5+
}

docs/source/_templates/layout.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% extends "!layout.html" %}
2+
{% set css_files = css_files + [ "_static/css/functions.css" ] %}

0 commit comments

Comments
 (0)