This project is to simulate an exchange in order to bakc test quant strategies.
Dependencies
python 3.5
pandas 0.23.0
spyder 3.2.8
plotly 2.7.0
Installation
pip install mini_exchange
Usage
# price: dataframe dt*ticker
# signal01: dataframe dt*ticker
# signal02: dataframe dt*ticker
dates=price.loc[start:end].index
tickers=price.columns
from mini_exchange import Mini_Exchange,Account,Log
MM=Mini_Exchange(price)
# create user01
acc01=Account(start_amount=1000)
log01=Log()
MM.register(user_name='user01',account=acc01,log=log01)
# create user02
acc02=Account(start_amount=1000)
log02=Log()
MM.register(user_name='user02',account=acc02,log=log02)
# trade
for dt in dates:
print('\rrun %d'%dt,end='\r')
MM.hold(dt)
for ticker in tickers:
#user01
if signal01.loc[dt,ticker]==1:
#open long
MM.long(ticker,amount=10,dt=dt,user='user01')
elif signal01.loc[dt,ticker]==-1:
#open short
MM.short(ticker,amount=10,dt=dt,user='user01')
elif signal01.loc[dt,ticker].isin((-2,2)):
#close
MM.close(dt,ticker, by='ticker',user='user01')
#user02
if signal02.loc[dt,ticker]==1:
#open long
MM.long(ticker,amount=10,dt=dt,user='user02')
elif signal02.loc[dt,ticker]==-1:
#open short
MM.short(ticker,amount=10,dt=dt,user='user02')
elif signal01.loc[dt,ticker].isin((-2,2)):
#close
MM.close(dt,ticker, by='ticker',user='user01')
MM.settle(dt)
# summary
# user01
print(acc01.annual_return(),acc01.sharpe_ratio(rf=0.03))
print(pos01.win_rate())
acc01.plot_history(by_pct=True)
pos01.plot_history_position()
history_position=pos01.pos
history_value=acc01.history_value
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Mini Exchange-0.0.8.tar.gz
(8.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Mini Exchange-0.0.8.tar.gz.
File metadata
- Download URL: Mini Exchange-0.0.8.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
545e1b96ba607ec5858840696c905057b521c4948d511974bef259559cb044d0
|
|
| MD5 |
57d1eac4005e46151497a7a5a704f7fd
|
|
| BLAKE2b-256 |
b02d932b745f7a31d2f797fe141a796bb5db7d790936c8ca0b0348adbe5f1b41
|
File details
Details for the file Mini_Exchange-0.0.8-py3-none-any.whl.
File metadata
- Download URL: Mini_Exchange-0.0.8-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.11.0 pkginfo/1.4.2 requests/2.14.2 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a2008041d19af9e2b2f9c50148d2edfb03e903f7c21ad18dc291bf59e5e7713
|
|
| MD5 |
f1ac8d53ce192d461d7ebdc1eb6490ae
|
|
| BLAKE2b-256 |
a91a888973d820052a33b0bde6de5f86fe3f795d774ba972787a4f9acbcff173
|