Skip to content

Commit

Permalink
renaming repo
Browse files Browse the repository at this point in the history
  • Loading branch information
simongarisch committed Oct 19, 2020
1 parent 8a786ea commit eb70f64
Show file tree
Hide file tree
Showing 76 changed files with 219 additions and 219 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ install:
- pip install coveralls

script:
- python -m pytest --cov=pytrading/
- flake8 pytrading
- python -m pytest --cov=pxtrade/
- flake8 pxtrade

after_success:
- coveralls
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"python.pythonPath": "env\\Scripts\\python.exe",
"python.testing.pytestArgs": [
"pytrading"
"pxtrade"
],
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
## pytrading
[![Build Status](https://travis-ci.org/simongarisch/pytrading.svg?branch=master)](https://travis-ci.org/simongarisch/pytrading)
[![Coverage Status](https://coveralls.io/repos/github/simongarisch/pytrading/badge.svg)](https://coveralls.io/github/simongarisch/pytrading?branch=master)
## pxtrade
[![Build Status](https://travis-ci.org/simongarisch/pxtrade.svg?branch=master)](https://travis-ci.org/simongarisch/pxtrade)
[![Coverage Status](https://coveralls.io/repos/github/simongarisch/pxtrade/badge.svg)](https://coveralls.io/github/simongarisch/pxtrade?branch=master)

A multi currency, event driven backtester written in Python.


### Installation
```bash
pip install pytrading
pip install pxtrade
```

### Examples
[Notebooks](https://github.com/simongarisch/pytrading/tree/master/notes) are available to cover the main concepts and examples.
- [equities buy and hold](https://github.com/simongarisch/pytrading/blob/master/notes/06%20Example%20-%20Buy%20And%20Hold.ipynb)
- [fx trading](https://github.com/simongarisch/pytrading/blob/master/notes/08%20Example%20-%20FX.ipynb)
- [bitcoin](https://github.com/simongarisch/pytrading/blob/master/notes/09%20Example%20-%20Bitcoin.ipynb)
- [Intraday trading](https://github.com/simongarisch/pytrading/blob/master/notes/11%20Example%20-%20FX%20Intraday%20with%20Benchmark.ipynb)
[Notebooks](https://github.com/simongarisch/pxtrade/tree/master/notes) are available to cover the main concepts and examples.
- [equities buy and hold](https://github.com/simongarisch/pxtrade/blob/master/notes/06%20Example%20-%20Buy%20And%20Hold.ipynb)
- [fx trading](https://github.com/simongarisch/pxtrade/blob/master/notes/08%20Example%20-%20FX.ipynb)
- [bitcoin](https://github.com/simongarisch/pxtrade/blob/master/notes/09%20Example%20-%20Bitcoin.ipynb)
- [Intraday trading](https://github.com/simongarisch/pxtrade/blob/master/notes/11%20Example%20-%20FX%20Intraday%20with%20Benchmark.ipynb)

### Assets and Portfolios
Before we can run a backtest we need to define the assets and portfolios involved.
```python
from pytrading.assets import reset, Cash, Stock, FxRate, Portfolio
from pxtrade.assets import reset, Cash, Stock, FxRate, Portfolio


reset()
Expand Down Expand Up @@ -55,10 +55,10 @@ portfolio.value


### Imposing portfolio constraints through compliance
Ideally there will be risk limits in place when running a backtest. Some concrete compliance rules are provided, but you can also define your own by [inheriting from ComplianceRule](https://github.com/simongarisch/pytrading/blob/master/notes/02%20The%20Trade%20Lifecycle.ipynb).
Ideally there will be risk limits in place when running a backtest. Some concrete compliance rules are provided, but you can also define your own by [inheriting from ComplianceRule](https://github.com/simongarisch/pxtrade/blob/master/notes/02%20The%20Trade%20Lifecycle.ipynb).

```python
from pytrading.compliance import Compliance, UnitLimit
from pxtrade.compliance import Compliance, UnitLimit


for port in [portfolio, benchmark]:
Expand All @@ -68,11 +68,11 @@ for port in [portfolio, benchmark]:
```

### Defining a portfolio broker
Different portfolios / strategies are likely to vary materially in broker charges. All portfolios have a default broker that executes trades at the last price with no charge (or slippage). Brokers have separate execution and charges strategies. You can use the classes available or define custom strategies by inheriting from [AbstractExecution](https://github.com/simongarisch/pytrading/blob/master/pytrading/broker/execution.py#L6) or [AbstractCharges](https://github.com/simongarisch/pytrading/blob/master/pytrading/broker/charges.py#L8). Note that backtesting supports multiple currencies. The portfolio could be denominated in USD, for example, but broker charges defined in AUD terms.
Different portfolios / strategies are likely to vary materially in broker charges. All portfolios have a default broker that executes trades at the last price with no charge (or slippage). Brokers have separate execution and charges strategies. You can use the classes available or define custom strategies by inheriting from [AbstractExecution](https://github.com/simongarisch/pxtrade/blob/master/pxtrade/broker/execution.py#L6) or [AbstractCharges](https://github.com/simongarisch/pxtrade/blob/master/pxtrade/broker/charges.py#L8). Note that backtesting supports multiple currencies. The portfolio could be denominated in USD, for example, but broker charges defined in AUD terms.


```python
from pytrading.broker import (
from pxtrade.broker import (
Broker,
FillAtLastWithSlippage,
FixedRatePlusPercentage,
Expand All @@ -86,10 +86,10 @@ portfolio.broker = Broker(
```

### Defining a trading strategy
All strategy classes must inherit from pytrading.Strategy and implement a generate_trades method. Note that the trades returned can either be None, a trade instance or list or trades.
All strategy classes must inherit from pxtrade.Strategy and implement a generate_trades method. Note that the trades returned can either be None, a trade instance or list or trades.

```python
import pytrading as pt
import pxtrade as pt


class ExampleStrategy(pt.Strategy):
Expand Down Expand Up @@ -117,12 +117,12 @@ history = pt.History(
)
```

### [Loading event data](https://github.com/simongarisch/pytrading/blob/master/notes/05%20Bulk%20Event%20Loads.ipynb)
### [Loading event data](https://github.com/simongarisch/pxtrade/blob/master/notes/05%20Bulk%20Event%20Loads.ipynb)
Events can be loaded either from yahoo finance or from an existing data frame.

```python
from datetime import date
from pytrading.events.yahoo import load_yahoo_prices
from pxtrade.events.yahoo import load_yahoo_prices


start_date = date(2020, 6, 30)
Expand Down Expand Up @@ -161,7 +161,7 @@ df[columns].iplot(
title="Portfolio Holdings of SPY",
)
```
![holdings](https://github.com/simongarisch/pytrading/blob/master/notes/portfolio_holdings_of_spy.png?raw=true)
![holdings](https://github.com/simongarisch/pxtrade/blob/master/notes/portfolio_holdings_of_spy.png?raw=true)


```python
Expand All @@ -170,6 +170,6 @@ df[columns].iplot(
title="Portfolio Value",
)
```
![holdings](https://github.com/simongarisch/pytrading/blob/master/notes/portfolio_value.png?raw=true)
![holdings](https://github.com/simongarisch/pxtrade/blob/master/notes/portfolio_value.png?raw=true)

***
2 changes: 1 addition & 1 deletion create_environment.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pip install -r requirements-dev.txt

REM CREATE A UNIQUE JUPYTER KERNEL FOR THIS PROJECT
pip install ipykernel
ipython kernel install --user --name=pytrading
ipython kernel install --user --name=pxtrade
6 changes: 3 additions & 3 deletions notes/01 Assets and Portfolios.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.assets import (\n",
"from pxtrade.assets import (\n",
" reset,\n",
" Asset,\n",
" Cash,\n",
Expand Down Expand Up @@ -412,7 +412,7 @@
"metadata": {},
"source": [
"### Movements in FX rates\n",
"pytrading supports multiple currencies. For example, you could have an AUD denominated portfolio holding assets in USD, GBP, EUR... The only requirement is that FX rates must be avaliable for the portfolio to use in valuation. FxRateEvent is a supported event type which we'll cover later. For this example we'll just set the rates manually."
"pxtrade supports multiple currencies. For example, you could have an AUD denominated portfolio holding assets in USD, GBP, EUR... The only requirement is that FX rates must be avaliable for the portfolio to use in valuation. FxRateEvent is a supported event type which we'll cover later. For this example we'll just set the rates manually."
]
},
{
Expand Down Expand Up @@ -582,7 +582,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.assets import (\n",
"from pxtrade.assets import (\n",
" StaticPriceAsset,\n",
" VariablePriceAsset,\n",
")"
Expand Down
32 changes: 16 additions & 16 deletions notes/02 The Trade Lifecycle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.compliance import Compliance\n",
"from pytrading.broker import Broker\n",
"from pytrading.assets import (\n",
"from pxtrade.compliance import Compliance\n",
"from pxtrade.broker import Broker\n",
"from pxtrade.assets import (\n",
" reset,\n",
" Cash,\n",
" Stock,\n",
Expand Down Expand Up @@ -117,7 +117,7 @@
}
],
"source": [
"from pytrading import Trade\n",
"from pxtrade import Trade\n",
"\n",
"trade = Trade(portfolio, stock, 100)\n",
"print(trade)"
Expand All @@ -139,7 +139,7 @@
{
"data": {
"text/plain": [
"<pytrading.compliance.base.Compliance at 0x29444dd5c50>"
"<pxtrade.compliance.base.Compliance at 0x29444dd5c50>"
]
},
"execution_count": 10,
Expand All @@ -159,7 +159,7 @@
{
"data": {
"text/plain": [
"<pytrading.broker.broker.Broker at 0x29444dd5c88>"
"<pxtrade.broker.broker.Broker at 0x29444dd5c88>"
]
},
"execution_count": 11,
Expand Down Expand Up @@ -201,7 +201,7 @@
{
"data": {
"text/plain": [
"<pytrading.trade.trade_pipeline.ComplianceHandler at 0x29444dc1b38>"
"<pxtrade.trade.trade_pipeline.ComplianceHandler at 0x29444dc1b38>"
]
},
"execution_count": 22,
Expand All @@ -210,7 +210,7 @@
}
],
"source": [
"from pytrading.trade import trade_pipeline\n",
"from pxtrade.trade import trade_pipeline\n",
"\n",
"trade_pipeline"
]
Expand Down Expand Up @@ -238,7 +238,7 @@
{
"data": {
"text/plain": [
"<pytrading.compliance.base.Compliance at 0x29444e281d0>"
"<pxtrade.compliance.base.Compliance at 0x29444e281d0>"
]
},
"execution_count": 12,
Expand All @@ -247,7 +247,7 @@
}
],
"source": [
"from pytrading.compliance import Compliance\n",
"from pxtrade.compliance import Compliance\n",
"\n",
"compliance = Compliance()\n",
"compliance"
Expand Down Expand Up @@ -297,7 +297,7 @@
}
],
"source": [
"from pytrading.compliance import UnitLimit\n",
"from pxtrade.compliance import UnitLimit\n",
"\n",
"compliance.add_rule(\n",
" UnitLimit(stock, 100)\n",
Expand Down Expand Up @@ -364,7 +364,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.compliance import ComplianceRule\n",
"from pxtrade.compliance import ComplianceRule\n",
"\n",
"\n",
"class RestrictedSecurityCode(ComplianceRule):\n",
Expand Down Expand Up @@ -436,7 +436,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.compliance import UnitLimit, WeightLimit"
"from pxtrade.compliance import UnitLimit, WeightLimit"
]
},
{
Expand Down Expand Up @@ -475,7 +475,7 @@
{
"data": {
"text/plain": [
"<pytrading.broker.broker.Broker at 0x29444dd5c88>"
"<pxtrade.broker.broker.Broker at 0x29444dd5c88>"
]
},
"execution_count": 31,
Expand Down Expand Up @@ -520,12 +520,12 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.broker import ( # execution strategies\n",
"from pxtrade.broker import ( # execution strategies\n",
" FillAtLast, # default\n",
" FillAtLastWithSlippage,\n",
")\n",
"\n",
"from pytrading.broker import ( # charge strategies\n",
"from pxtrade.broker import ( # charge strategies\n",
" NoCharges, # default\n",
" FixedRatePlusPercentage,\n",
")"
Expand Down
12 changes: 6 additions & 6 deletions notes/03 Events.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.events import (\n",
"from pxtrade.events import (\n",
" AbstractEvent,\n",
" AssetPriceEvent,\n",
" FxRateEvent,\n",
Expand All @@ -38,7 +38,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"All events in pytrading inherit from AbstractEvent."
"All events in pxtrade inherit from AbstractEvent."
]
},
{
Expand Down Expand Up @@ -76,7 +76,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pytrading.assets import reset, Stock"
"from pxtrade.assets import reset, Stock"
]
},
{
Expand Down Expand Up @@ -260,8 +260,8 @@
"outputs": [],
"source": [
"from datetime import datetime\n",
"from pytrading import Trade\n",
"from pytrading.assets import reset, Cash, Stock, FxRate, Portfolio\n",
"from pxtrade import Trade\n",
"from pxtrade.assets import reset, Cash, Stock, FxRate, Portfolio\n",
"\n",
"reset()\n",
"aud = Cash(\"AUD\")\n",
Expand Down Expand Up @@ -447,7 +447,7 @@
}
],
"source": [
"from pytrading import EventsQueue\n",
"from pxtrade import EventsQueue\n",
"\n",
"reset()\n",
"queue = EventsQueue()\n",
Expand Down
Loading

0 comments on commit eb70f64

Please sign in to comment.