A Financial backtesting framework for stock portfolio selection
Project description
FinLab
A Financial backtesting framework for stock portfolio selection
Installation
FinLab is a easy to install python package aims to help developing stock portfolio strategies.
pip install finlab
Getting Start
There are two main functionality of finlab in the alpha development. First, taiwan stock market historical data can be obtain by online.Data interface:
from finlab import online
data = online.Data()
close = data.get('close')
close.head()
date | 1101 | 1203 | ... | 1726 | 2330 |
---|---|---|---|---|---|
2015-1-6 | 43.0 | 23.7 | 82.0 | 139.5 | |
... | ... | ... | ... | ... | ... |
2015-1-8 | 42.25 | 23.8 | 82.0 | 133.5 |
Stock technical indicator calculation
With the integration of TA-Lib package, it is easily to calculate technical indicator using wrapper function online.Data.talib
:
rsi = data.talib('RSI', timeperiod=14)
With the simple code above, Data.talib
calculates RSI indicator for all stocks in the pool.
Perform dataFrame methods
It is easy to perform stock selection using methods provided by pandas dataframe
# plot stock price
close['1101'].plot()
# caculate monthly average price
sma20 = close.rolling(20).plot()
# select stocks with the price above sma20
signal = close > sma20
# print the stocks statisfy the condition above
last_signal = signal.iloc[-1]
last_signal[last_signal == True] # can be simplied to last_signal[last_signal]
Stock Backtesting
It is easy to write a condition using the similar calculation as above to create a backtest strategy: For example, let's select 10 stock that have the smallest price.
def strategy(data):
close = data.get('close')
buy = close.smallest(10)
sell = None
resample_frequency = '60d'
return buy, sell, resample_frequency
report = online.backtest(strategy)
report
FinLab will NEVER store your strategy or backtest history in the cloud.
We value your privacy! For every single backtest, an AWS private virtual machine is created (AWS Lambda). After backtesting, all local variables during simlation is destroyed.
Authors
- Cheng-Yu Han - Ph.D. FinLab
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for finlab-0.1.0.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7cada5ff66ace0a297dce5d7f8b859cdd9f742a1d82928675a929fd55fd762b |
|
MD5 | d5f85b57c983e77b263dd3901f0c5631 |
|
BLAKE2b-256 | 0d640c98580eb53e44b1feb1325ff72bd0ce6d3d73caf7d2ebf125ec6ebdfa20 |