Skip to main content

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

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

finlab-0.1.0.dev1-py3-none-any.whl (12.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page