Skip to main content

Tools to backtest and create your own portfolio insurance strategy

Project description

Create your own insured portfolio using several Tools.

First ,To install, just use pip :

pip install pyinsurance

Required Dependencies are listed below , such :

Dependency

Version

arch

5.0.1

numpy

1.20.1

scipy

1.6.2

statsmodels

0.12.2

numba

0.52.1

setuptools

60.5.0

pandas

1.2.4

pyvar

0.0.1

There is no dependency verification , so please, make sure to have installed every required one before using the package.

Example

To begin, let’s extract some included default data :

import pyinsurance
from pyinsurance.pymolder import tipp_model
from pyinsurance.data.IRX import load as d1
from pyinsurance.data.sp500 import load as d2
import matplotlib.pyplot as plt

risky_Asset = d2()
safe_Asset = d1()/52  #we divided by 52 as we use weekly rates

Let’s initalise our first insured portfolio now!

For instance,we set our lock-in rate , minimum capital risk allocation , threshold for capital injection , allocate funds ,strategy’s percentage floor ,multipler,benchmark returns and rebalancement cycle being respectively equal to :

lock_in_rate = 0.05
mcr = 0.40
tfci = 0.80
fund = 100
floor = 0.80
multiplier = 10
Benchmark_return = risk_Asset
Rebalancement_frequency = 52 # once a week -> 52 weeks a year

Running the tipp_model class :

res = tipp_model(risk_Asset,safe_Asset,lock_in_rate,mcr,tfci,fund,\
                floor,multiplier,risk_Asset,Rebalancement_frequency)

Our strategy-insured backtest is ready !

import matplotlib.pyplot as plt
from pyinsurance.Metric_Generator.returns_metrics import Cumulative_ret


fig = plt.figure(figsize=(15,5))
ax0 = fig.add_subplot(111)
plt.plot(risk_Asset.index,Cumulative_ret(risk_Asset)*100,label = 'Non-Insured Performance')
plt.plot(risk_Asset.index,res.Fund,label = 'Fund Performance')
plt.plot(risk_Asset.index,res.Reference_capital,label = 'Reference Capital',linestyle="--")
plt.plot(risk_Asset.index,res.floor,label = 'Floor',linestyle="-.")
plt.legend()
plt.show()
https://raw.githubusercontent.com/EM51641/pyinsurance-/main/pictures/output.png

And our capital injections through the period are presented as:

fig = plt.figure(figsize=(15,5))
ax1 = fig.add_subplot(111)
plt.plot(risk_Asset.index,res.capital_reinjection,label = 'Injected Capital')
plt.legend()
plt.show()
https://raw.githubusercontent.com/EM51641/pyinsurance-/main/pictures/output2.png

If you want to backtest the VaR, you can use the varpy library:

import pyvar
from varpy.Backtester.bktst import Backtest
from varpy.Backtester.time_Significance import Testing
VaR , CVaR = Backtest(data, 500, 2, 0.05, model = 'EVT')
fig = plt.figure(figsize=(15,5))
plt.plot(data[500:])
plt.plot(VaR, label = 'VaR')
plt.plot(CVaR, label = 'CVaR')
plt.legend()
plt.show()
https://raw.githubusercontent.com/EM51641/pyinsurance-/main/pictures/output3.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Pyinsurance-1.1.9.tar.gz (794.7 kB view details)

Uploaded Source

Built Distribution

Pyinsurance-1.1.9-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file Pyinsurance-1.1.9.tar.gz.

File metadata

  • Download URL: Pyinsurance-1.1.9.tar.gz
  • Upload date:
  • Size: 794.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for Pyinsurance-1.1.9.tar.gz
Algorithm Hash digest
SHA256 9991e956bb7435d2d49757ec0a679e638757e91bfe3ccf05dbd31f324c7efa21
MD5 1efaf6a627fa0678548dd227def431a9
BLAKE2b-256 3070e27c59c86de92e7564975cd3c1b28a94ec4a53e4a63e68972d7d0d986d15

See more details on using hashes here.

File details

Details for the file Pyinsurance-1.1.9-py3-none-any.whl.

File metadata

  • Download URL: Pyinsurance-1.1.9-py3-none-any.whl
  • Upload date:
  • Size: 42.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for Pyinsurance-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0edd8e1c5dde7f81326399092f00a6527913347e5dc28b242f9a09d2e07ab1d4
MD5 3cd6c7a4166ac7d3324aea9fcbdd260f
BLAKE2b-256 b93b38626a303beddf012a8a6edb0840dc0dd44cde5847d5f04d188c2df54f52

See more details on using hashes here.

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