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:

import finlab

close = finlab.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 finlab.data.talib:

rsi = finlab.data.talib('RSI', timeperiod=14)
rsi.head()

With the simple code above, finlab.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).mean()

# 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] # simplied: 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 = finlab.backtest(strategy)
report

FinLab will NEVER record your strategy in the cloud without your permission.

We value your privacy! For every single backtest, an private container is created (using AWS Lambda). After each 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

If you're not sure about the file name format, learn more about wheel file names.

finlab-0.1.2.dev1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file finlab-0.1.2.dev1-py3-none-any.whl.

File metadata

  • Download URL: finlab-0.1.2.dev1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.8

File hashes

Hashes for finlab-0.1.2.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 b31f9b82a53e2cf2d84edecd80dfe5d4ee6c511e5bf2f9c6cf24893e5607665e
MD5 b2ad64fa5f17b7a7ef6bf17ea5d466f5
BLAKE2b-256 278cc7c825ff13fecaeebdf6b8c707bcbcff06c29c860b50395510131566800e

See more details on using hashes here.

Supported by

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